Chat Completions
Create a chat completion using any supported model. This endpoint is fully compatible with the OpenAI Chat Completions API.
POST/v1/chat/completions
Request Body
| Parameter | Type | Required | Description |
|---|
model | string | Yes | Model ID to use |
messages | array | Yes | List of message objects |
temperature | number | No | Sampling temperature (0-2) |
max_tokens | integer | No | Maximum tokens to generate |
stream | boolean | No | Enable streaming response |
top_p | number | No | Nucleus sampling parameter |
Example Request
curl https://api.zora.io.vn/v1/chat/completions \
-H "Authorization: Bearer zr_live_sk_your_key" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-3-opus-20240229",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is machine learning?"}
],
"temperature": 0.7,
"max_tokens": 1000,
"stream": false
}'
Response
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1710000000,
"model": "claude-3-opus-20240229",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Machine learning is a subset of AI..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 150,
"total_tokens": 175
}
}
Streaming
Set stream: true to receive responses as Server-Sent Events (SSE). Each chunk contains a delta object with the incremental content:
data: {"id":"chatcmpl-abc123","choices":[{"delta":{"content":"Machine"}}]}
data: {"id":"chatcmpl-abc123","choices":[{"delta":{"content":" learning"}}]}
data: {"id":"chatcmpl-abc123","choices":[{"delta":{"content":" is"}}]}
...
data: [DONE]