GRGlobalRouter Docs
Console

Chat / POST

Create chat completion

Creates an OpenAI-style chat completion.

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 list

Request parameters

FieldTypeRequiredDescription
modelstringYesGlobalRouter model ID.
messagesarrayYesOpenAI-style message array containing role and content.
messages[]objectYesSingle OpenAI-style message.
messages[].rolestringYesMessage role, such as system, user, assistant, or tool.
messages[].contentstring | arrayNoMessage text or multimodal content parts.
messages[].namestringNoParticipant name.
messages[].tool_callsarrayNoTool calls in an assistant message.
messages[].tool_call_idstringNoTool call ID associated with a tool message.
providerstringNoGlobalRouter provider preference; this is a GR provider string, not the official OpenRouter provider object.
streambooleanNoWhen true, returns text/event-stream.
stream_optionsobjectNoStreaming options, such as include_usage.
temperaturenumberNoSampling temperature.
top_pnumberNoNucleus sampling probability.
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.
toolsarrayNoTool call definitions.
tool_choicestring | objectNoTool selection strategy, such as auto or a specific tool.
response_formatobjectNoStructured output constraints.
stopstring | string[]NoStop sequences.
userstringNoApplication-side user identifier.
_routerobjectNoGlobalRouter 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

FieldTypeRequiredDescription
idstringYesGeneration record ID.
choicesarrayYesModel output; streaming responses include delta.
usageobjectNoToken and billing statistics.
modelstringYesActual model ID used.

Response example

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

HTTPCodeDescription
401UNAUTHORIZEDMissing or invalid Authorization Bearer token.
403FORBIDDENThe current API key is not allowed to call this scope or model.
429RATE_LIMITEDRequests 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.