GRGlobalRouter Docs
Console

Chat / POST

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 list

Request parameters

FieldTypeRequiredDescription
modelstringYesGlobalRouter model ID.
messagesarrayYesMessage array, with each item containing role and content.
providerstringNoGlobalRouter provider preference; this is a GR provider string, not the official OpenRouter provider object.
streambooleanNoWhether to use SSE streaming output.
stream_optionsobjectNoStreaming options, such as include_usage.
temperaturenumberNoSampling temperature, from 0 to 2.
top_pnumberNoNucleus sampling probability, from 0 to 1.
max_completion_tokensintegerNoMaximum output token count.
max_tokensintegerNoMaximum output tokens for legacy requests; prefer max_completion_tokens for new requests.
reasoningobjectNoReasoning configuration, such as effort, summary, or reasoning options supported by the provider.
reasoning_effortstringNoShorthand for reasoning.effort; the two fields must not have different values.
toolsobject[]NoTool definitions.
tool_choicestring | objectNoTool selection strategy, such as auto or a specific tool.
response_formatobjectNoStructured output configuration.
stopstring | string[]NoStop sequences.
userstringNoApplication-side user identifier.
modalitiesstring[]NoTriggers image output when image is included.
image_configobjectNoImage output configuration.
_routerobjectNoRouting 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
}
JSON

Response fields

FieldTypeRequiredDescription
idstringYesChat completion ID。
choicesobject[]YesGenerated result list.
choices[].messageobjectNoAssistant message returned for non-streaming responses.
choices[].deltaobjectNoIncremental content in streaming chunks.
usageobjectNoUsage summary for tokens or image tasks.
openrouter_metadataobjectYesMetadata such as provider and generation_id.

Response example

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.