Chat Completions
OpenAI-compatible chat completions endpoint. Every model that supports the chat format (GPT, Claude, Gemini, etc.) goes through this route.
Request
POST /v1/chat/completions
Body
| Field | Type | Required | Description |
|---|---|---|---|
model | string | ✓ | Model ID, e.g. gpt-5.5, claude-sonnet-4-6 |
messages | array | ✓ | Conversation history. Each item has role and content |
stream | boolean | ✗ | Stream the response. Default false |
temperature | number | ✗ | 0-2. Higher = more creative |
max_tokens | integer | ✗ | Maximum output tokens |
tools | array | ✗ | Function calling tool definitions |
Example
curl https://api.tokensmart.ai/v1/chat/completions \
-H "Authorization: Bearer pk_live_xxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.5",
"messages": [
{ "role": "system", "content": "You are a friendly assistant" },
{ "role": "user", "content": "What is the weather in Beijing today?" }
],
"temperature": 0.7
}'
Response
{
"id": "chatcmpl-xxx",
"object": "chat.completion",
"model": "gpt-5.5",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "I cannot fetch real-time weather..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 42,
"total_tokens": 67
}
}
Streaming
Pass "stream": true and the response turns into SSE format. Each chunk is a JSON delta.
See the OpenAI Chat Completions reference for full details.