Create a chat completion
Creates a chat completion.
POST /api/v1/chat/completions
Returns full JSON by default. When `stream=true`, returns an SSE stream. If `modalities: ["image"]` is included, image results are in `choices[].message.images`.
Back to Chat endpoint listRequest parameters
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | GlobalRouter model ID. |
messages | array | Yes | Message array, with each item containing role and content. |
provider | string | No | GlobalRouter provider preference; this is a GR provider string, not the official OpenRouter provider object. |
stream | boolean | No | Whether to use SSE streaming output. |
stream_options | object | No | Streaming options, such as include_usage. |
temperature | number | No | Sampling temperature, from 0 to 2. |
top_p | number | No | Nucleus sampling probability, from 0 to 1. |
max_completion_tokens | integer | No | Maximum output token count. |
max_tokens | integer | No | Maximum output tokens for legacy requests; prefer max_completion_tokens for new requests. |
reasoning | object | No | Reasoning configuration, such as effort, summary, or reasoning options supported by the provider. |
reasoning_effort | string | No | Shorthand for reasoning.effort; the two fields must not have different values. |
tools | object[] | No | Tool definitions. |
tool_choice | string | object | No | Tool selection strategy, such as auto or a specific tool. |
response_format | object | No | Structured output configuration. |
stop | string | string[] | No | Stop sequences. |
user | string | No | Application-side user identifier. |
modalities | string[] | No | Triggers image output when image is included. |
image_config | object | No | Image output configuration. |
_router | object | No | Routing metadata, such as provider or routing. |
Request examples
curl "https://api.globalrouter.com/api/v1/chat/completions" \
-H "Authorization: Bearer $GR_API_KEY" \
-H "Content-Type: application/json" \
--data-binary @- <<JSON
{
"model": "${GR_CHAT_MODEL:?Set GR_CHAT_MODEL before running this example}",
"messages": [
{
"role": "user",
"content": "请用一句话说明你能做什么。"
}
],
"temperature": 0.2,
"max_tokens": 128,
"stream": false
}
JSONResponse fields
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Chat completion ID。 |
choices | object[] | Yes | Generated result list. |
choices[].message | object | No | Assistant message returned for non-streaming responses. |
choices[].delta | object | No | Incremental content in streaming chunks. |
usage | object | No | Usage summary for tokens or image tasks. |
openrouter_metadata | object | Yes | Metadata such as provider and generation_id. |
Response example
{
"id": "chatcmpl_123",
"object": "chat.completion",
"model": "deepseek-v4-pro",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "GlobalRouter 用一个接口聚合主流模型,并让成本和可靠性交付更可见。"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 18,
"completion_tokens": 26,
"total_tokens": 44
},
"openrouter_metadata": {
"provider": "deepseek",
"generation_id": "req_123"
}
}Notes
- The Chat API requires an API key with the chat scope; image output also uses task capability and the corresponding model permissions.
- `provider` is a GlobalRouter provider string; the field with the same name in the official OpenRouter Chat Completion documentation is an object.