API Reference
POST/v1/chat/completions
Chat Completions
Creates a model response for the given conversation. Fully compatible with the OpenAI Chat Completions API — existing SDKs work without modification.
Request body
| Parameter | Type | Description |
|---|
modelrequired | string | The virtual model ID to use. Call GET /v1/models to list the model IDs available on your account. |
messagesrequired | array | Array of message objects. Each has role ("system", "user", or "assistant") and content (string). |
stream | boolean | If true, tokens are sent as server-sent events as they are generated. Defaults to false. |
temperature | number | Sampling temperature between 0 and 2. Higher values produce more random output. Defaults to 1. |
max_tokens | integer | Maximum tokens to generate. Defaults to model maximum if not set. |
top_p | number | Nucleus sampling — only the top-p probability mass is considered. Defaults to 1. |
stop | string | array | Up to 4 sequences where the API will stop generating. Can be a string or array of strings. |
n | integer | Number of chat completion choices to generate. Defaults to 1. |
Example request
{
"model": "default",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the capital of France?"}
],
"temperature": 0.7,
"max_tokens": 256,
"stream": false
}
Response
Returns a chat.completion object when stream=false, or a stream of chat.completion.chunk events when stream=true.
Non-streaming response
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1748000000,
"model": "default",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The capital of France is Paris."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 28,
"completion_tokens": 9,
"total_tokens": 37
}
}
Streaming response (SSE)
Each line is a data: event. Read choices[0].delta.content and concatenate chunks until you receive data: [DONE].
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"delta":{"role":"assistant"},"index":0}]}
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"delta":{"content":"The"},"index":0}]}
data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"delta":{"content":" capital"},"index":0}]}
data: [DONE]
Error codes
Errors return {"error": {"message", "type", "code", "param"?, "request_id"?}} — see the Error Handling guide for the full envelope and which codes to retry.
400invalid_message_role / missing_input / context_length_exceeded
Bad request body — unsupported role, missing messages, or input too long for the model.
401invalid_api_key
Missing, invalid, or expired API key. Check the Authorization header.
402insufficient_credit
Wallet balance is too low. Top up at Dashboard → Add credits.
403kyc_required / insufficient_scope
KYC verification is required before this call, or the API key lacks the required scope.
404model_not_found
The model ID in the request does not exist or is not available to your account.
429rate_limit_exceeded
Too many requests, or a per-key RPM/TPD limit was hit. Slow down and retry with exponential backoff.
503model_unavailable
Every configured route for this model failed or timed out. Retry after a short wait — this is not something to fix in your request.