/chat/completionsCreate Chat Completion
Creates a model response from conversation history with streaming, tools, and usage accounting.
Dùng khóa API của bạn với Authorization: Bearer sk-xxxx.
Ví dụ request
{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": "Hello"
}
],
"stream": false
}Ví dụ response
{
"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
}'Tham số
| Tên | Loại | Bắt buộc | Mô tả |
|---|---|---|---|
| model | string | Có | Model ID. The CostRouter selects an available channel by model name and forwards the request. |
| messages | array<object> | Có | Conversation message array, usually with system, user, assistant, or tool roles. |
| temperature | number | Không | Sampling temperature. Higher values make output more random. |
| top_p | number | Không | Nucleus sampling parameter, usually adjusted instead of temperature. |
| stream | boolean | Không | Whether to return a streaming response. |
| max_tokens | integer | Không | Số token đầu ra tối đa. |
| tools | array<object> | Không | Tool or function definitions. Support depends on the upstream model. |
| response_format | object | Không | Structured response format. Support depends on the upstream model. |
Ví dụ response
| Tên | Loại | Bắt buộc | Mô tả |
|---|---|---|---|
| id | string | Không | Response, task, or resource ID. |
| object | string | Không | Response object type. |
| created | integer | Không | Creation timestamp. |
| model | string | Không | - |
| choices | array<object> | Không | Candidate model outputs. |
| usage | object | Không | Token usage statistics. |