Create chat completion
Creates an OpenAI-style chat completion.
Compatibility
Keep the OpenAI request shape and point base_url at the GlobalRouter compatible entry, so existing OpenAI SDKs and client code keep working.
Choose the Base URL for the site you are using, then append the full endpoint path:
https://api.globalrouter.com/v1(China site)https://api.globalrouter.ai/v1(Overseas site)
Data is not shared between the two sites. Use the Base URL that matches your site. Examples below default to https://api.globalrouter.com/v1.
| Parameter | Type / Location | Required | Description |
|---|---|---|---|
Authorization | Header | Yes | Bearer <GlobalRouter API Key>. |
Content-Type | Header | Required for JSON requests | application/json。 |
provider | string | No | GlobalRouter provider preference string; not the OpenRouter official provider object. |
The /v1 paths are OpenAI-compatible. For the Seedance / Doubao native protocol, see the Seedance docs.
POST /v1/chat/completions
Useful for migrating projects that already use an OpenAI SDK. Requests use OpenAI-style messages, while model IDs come from the GlobalRouter catalog.
Back to Chat endpoint listRequest parameters
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | GlobalRouter model ID. |
messages | array | Yes | OpenAI-style message array containing role and content. |
messages[] | object | Yes | Single OpenAI-style message. |
messages[].role | string | Yes | Message role, such as system, user, assistant, or tool. |
messages[].content | string | array | No | Message text or multimodal content parts. |
messages[].name | string | No | Participant name. |
messages[].tool_calls | array | No | Tool calls in an assistant message. |
messages[].tool_call_id | string | No | Tool call ID associated with a tool message. |
provider | string | No | GlobalRouter provider preference; this is a GR provider string, not the official OpenRouter provider object. |
stream | boolean | No | When true, returns text/event-stream. |
stream_options | object | No | Streaming options, such as include_usage. |
temperature | number | No | Sampling temperature. |
top_p | number | No | Nucleus sampling probability. |
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 | array | No | Tool call definitions. |
tool_choice | string | object | No | Tool selection strategy, such as auto or a specific tool. |
response_format | object | No | Structured output constraints. |
stop | string | string[] | No | Stop sequences. |
user | string | No | Application-side user identifier. |
_router | object | No | GlobalRouter routing metadata, such as provider, route, or metadata. |
Request examples
curl "https://api.globalrouter.com/v1/chat/completions" \
-H "Authorization: Bearer $GR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "kimi-k3",
"messages": [
{ "role": "user", "content": "用三句话介绍 GlobalRouter。" }
],
"provider": "moonshot",
"stream": false,
"stream_options": { "include_usage": true },
"temperature": 0.7,
"top_p": 0.9,
"max_completion_tokens": 512,
"reasoning_effort": "high",
"tools": [
{
"type": "function",
"function": {
"name": "lookup_model",
"description": "查询模型信息",
"parameters": {
"type": "object",
"properties": { "model": { "type": "string" } },
"required": ["model"]
}
}
}
],
"tool_choice": "auto",
"response_format": { "type": "json_object" },
"stop": ["###"],
"user": "user_123",
"_router": {
"route": "balanced",
"metadata": { "project": "docs-demo" }
}
}'Response fields
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Generation record ID. |
choices | array | Yes | Model output; streaming responses include delta. |
usage | object | No | Token and billing statistics. |
model | string | Yes | Actual model ID used. |
Response example
{
"id": "chatcmpl_01HV...",
"object": "chat.completion",
"created": 1716283200,
"model": "kimi-k3",
"choices": [
{
"index": 0,
"message": { "role": "assistant", "content": "GlobalRouter 提供统一模型 API..." },
"finish_reason": "stop"
}
],
"usage": { "prompt_tokens": 18, "completion_tokens": 42, "total_tokens": 60 }
}Errors
| HTTP | Code | Description |
|---|---|---|
| 401 | UNAUTHORIZED | Missing or invalid Authorization Bearer token. |
| 403 | FORBIDDEN | The current API key is not allowed to call this scope or model. |
| 429 | RATE_LIMITED | Requests are too frequent or the asynchronous task queue is full; reduce concurrency or retry later. |
Notes
- `provider` is a GlobalRouter provider string; the field with the same name in the official OpenRouter Chat Completion documentation is an object.