/chat/completionsCreate Chat Completion
Creates a model response from conversation history with streaming, tools, and usage accounting.
Use your API-Key with Authorization: Bearer sk-xxxx.
Request Example
{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": "Hello"
}
],
"stream": false
}Response Example
{
"id": "chatcmpl_xxx",
"object": "chat.completion",
"created": 0,
"model": "gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello!"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 8,
"completion_tokens": 3,
"total_tokens": 11
}
}curl Example
curl -X POST 'https://costrouter.ai/v1/chat/completions' \
-H 'Authorization: Bearer sk-xxxx'
-H 'Content-Type: application/json'
-d '{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": "Hello"
}
],
"stream": false
}'Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | Model ID. The CostRouter selects an available channel by model name and forwards the request. |
| messages | array<object> | Yes | Conversation message array, usually with system, user, assistant, or tool roles. |
| temperature | number | No | Sampling temperature. Higher values make output more random. |
| top_p | number | No | Nucleus sampling parameter, usually adjusted instead of temperature. |
| stream | boolean | No | Whether to return a streaming response. |
| max_tokens | integer | No | Maximum number of output tokens. |
| tools | array<object> | No | Tool or function definitions. Support depends on the upstream model. |
| response_format | object | No | Structured response format. Support depends on the upstream model. |
Response Example
| Name | Type | Required | Description |
|---|---|---|---|
| id | string | No | Response, task, or resource ID. |
| object | string | No | Response object type. |
| created | integer | No | Creation timestamp. |
| model | string | No | - |
| choices | array<object> | No | Candidate model outputs. |
| usage | object | No | Token usage statistics. |