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

ParameterTypeRequiredDescription
modelstringYesModel ID to use
messagesarrayYesList of message objects
temperaturenumberNoSampling temperature (0-2)
max_tokensintegerNoMaximum tokens to generate
streambooleanNoEnable streaming response
top_pnumberNoNucleus sampling parameter

Example Request

curl
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

JSON
{ "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:

SSE Stream
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]