Chat Completions API
Path: POST /v1/chat/completions
📥 Request Body Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model identifier (e.g. gpt-4o, claude-3-5-sonnet, deepseek-chat) |
messages | array | Yes | Array of conversation context containing roles and content |
stream | boolean | No | Whether to enable SSE streaming typewriter effect, default false |
temperature | float | No | Sampling temperature ($0.0 \sim 2.0$), higher values are more creative |
max_tokens | integer | No | Maximum number of tokens to generate |
📤 Response Example (Non-streaming JSON)
{
"id": "chatcmpl-9xX8Yz123456",
"object": "chat.completion",
"created": 1728000000,
"model": "gpt-4o-2024-08-06",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! I am an AI assistant, happy to serve you."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 15,
"completion_tokens": 12,
"total_tokens": 27
}
}