Chat completions
Creates a model response for the given chat conversation.
Endpoint
POST https://gateway.mytokengate.com/v1/chat/completionsRequest Example
curl --request POST \
--url https://gateway.mytokengate.com/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-4o",
"messages": [
{
"role": "user",
"content": "What opportunities and challenges will the Chinese large model industry face in 2025?"
}
]
}'Authentication
All requests require a Bearer token in the Authorization header:
Authorization: Bearer YOUR_API_KEYRequest Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | Model name. See Models for available options. |
| messages | array | Yes | A list of messages comprising the conversation so far. |
| max_tokens | integer | No | Maximum tokens to generate. Ensure input + output tokens don’t exceed model’s context window. |
| stream | boolean | No | If true, returns tokens as Server-Sent Events. Stream terminates with data: [DONE]. |
| temperature | float | No | Controls randomness. Range: 0-2. Default varies by model. |
| top_p | float | No | Nucleus sampling parameter. Default: 0.7 |
| top_k | float | No | Top-k sampling parameter. |
| frequency_penalty | float | No | Penalizes repeated tokens. Range: -2.0 to 2.0. |
| stop | string or array | No | Up to 4 sequences where generation will stop. |
| n | integer | No | Number of completions to generate. Default: 1 |
| response_format | object | No | Specifies output format (e.g., { "type": "json_object" }). |
| tools | array | No | List of tools the model may call. Max 128 functions. |
Response
{
"id": "chatcmpl-xxx",
"choices": [
{
"message": {
"role": "assistant",
"content": "The response text...",
"tool_calls": [
{
"id": "call_xxx",
"type": "function",
"function": {
"name": "function_name",
"arguments": "{\"arg\": \"value\"}"
}
}
]
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 456,
"total_tokens": 579
},
"created": 1234567890,
"model": "gpt-4o",
"object": "chat.completion"
}Error Codes
| Code | Description |
|---|---|
| 400 | Invalid request parameters |
| 401 | Invalid or missing API key |
| 404 | Model not found |
| 429 | Rate limit exceeded |
| 503/504 | Service temporarily unavailable |
Last updated on