Create a message
Messages-style text endpoint.
POST /api/v1/messages
Useful when organizing multi-turn context as a messages array and returning a message object.
Back to Text endpoint listRequest parameters
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | GlobalRouter text model ID. |
models | string[] | No | OpenRouter-style model candidates; the first entry is used when model is omitted. |
messages | array | Yes | Multi-turn messages containing role and content. |
provider | string | No | Specify provider preferences. |
stream | boolean | No | Whether to use streaming output. |
temperature | number | No | Sampling temperature. |
top_p | number | No | Nucleus sampling probability. |
max_tokens | integer | No | Maximum output token count. |
max_completion_tokens | integer | No | Compatibility alias for max_tokens. |
tools | object[] | No | Tool call definitions. |
tool_choice | string | object | No | Tool selection strategy. |
response_format | object | No | Structured output configuration. |
stop | string | string[] | No | Stop sequences. |
user | string | No | Application-side user identifier. |
_router | object | No | Routing metadata, merged into router metadata. |
metadata | object | No | Application or routing metadata. |
Request examples
curl "https://api.globalrouter.com/api/v1/messages" \
-H "Authorization: Bearer $GR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3-32b",
"messages": [
{ "role": "user", "content": "列出三个接入前检查项。" }
],
"provider": "qwen",
"temperature": 0.7,
"top_p": 0.9,
"max_completion_tokens": 256,
"tools": [
{
"type": "function",
"function": {
"name": "lookup_model",
"description": "查询模型信息",
"parameters": { "type": "object", "properties": { "model": { "type": "string" } } }
}
}
],
"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 | message ID。 |
type | string | Yes | message。 |
role | string | Yes | assistant。 |
model | string | Yes | Actual model ID used. |
content | object[] | Yes | Text content part. |
stop_reason | string | No | Stop reason. |
usage | object | No | Token usage. |
openrouter_metadata | object | No | Metadata such as provider and generation_id. |
Response example
{
"id": "msg_123",
"type": "message",
"role": "assistant",
"model": "qwen3-32b",
"content": [
{ "type": "text", "text": "确认模型、Key scope 和额度。" }
],
"usage": {
"prompt_tokens": 16,
"completion_tokens": 20,
"total_tokens": 36
}
}