Chat Completions¶
POST https://revidapi.com/v1/chat/completions
OpenAI-compatible. Any library that speaks to OpenAI works here — point
base_url at https://revidapi.com/v1.
Auth¶
Send either header:
Authorization: Bearer sk_YOUR_KEY
X-API-Key: sk_YOUR_KEY
Parameters¶
| Field | Type | Required | Description |
|---|---|---|---|
model |
string | Yes | Model ID, e.g. claude-sonnet-5. See models |
messages |
array | Yes | {role, content} items. role is system, user or assistant |
stream |
bool | No | true to receive SSE chunks |
max_tokens |
int | No | Caps the answer length — the surest way to avoid paying for an unexpectedly long reply |
temperature |
number | No | 0–2 |
top_p |
number | No | 0–1 |
tools |
array | No | OpenAI-style function definitions |
tool_choice |
string/object | No | auto, none, or a named function |
parallel_tool_calls |
bool | No | Allow several tool calls per turn |
Basic example¶
curl https://revidapi.com/v1/chat/completions \
-H "Authorization: Bearer sk_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5",
"max_tokens": 1024,
"messages": [
{"role": "system", "content": "Answer briefly."},
{"role": "user", "content": "Explain HTTP 429 in two sentences."}
]
}'
Response:
{
"id": "chatcmpl-...",
"object": "chat.completion",
"model": "claude-sonnet-5",
"choices": [
{
"index": 0,
"finish_reason": "stop",
"message": {"role": "assistant", "content": "429 means..."}
}
],
"usage": {"prompt_tokens": 42, "completion_tokens": 58, "total_tokens": 100}
}
Streaming¶
Set "stream": true. The server returns Server-Sent Events, each line prefixed
with data:, terminated by data: [DONE].
from openai import OpenAI
client = OpenAI(api_key="sk_YOUR_KEY",
base_url="https://revidapi.com/v1")
for chunk in client.chat.completions.create(
model="claude-sonnet-5",
messages=[{"role": "user", "content": "Tell me a short story."}],
max_tokens=800,
stream=True,
):
piece = chunk.choices[0].delta.content
if piece:
print(piece, end="", flush=True)
Function calling¶
curl https://revidapi.com/v1/chat/completions \
-H "Authorization: Bearer sk_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5",
"max_tokens": 1024,
"messages": [{"role": "user", "content": "What is the weather in Hanoi?"}],
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Current weather for a city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"]
}
}
}]
}'
The model returns tool_calls. Run the function on your side, then send the
result back as a role: "tool" message, exactly as with OpenAI.
Not every model supports this. The Tools column in models says which do.
Images¶
For models with ✅ in the Vision column:
{
"model": "claude-sonnet-5",
"max_tokens": 1024,
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": "What is in this image?"},
{"type": "image_url",
"image_url": {"url": "data:image/jpeg;base64,/9j/4AAQ..."}}
]
}]
}
Error codes¶
| Code | Meaning | What to do |
|---|---|---|
400 |
Bad body — missing model, empty messages, malformed JSON |
Fix the request |
401 |
Missing or invalid key | Check the header |
402 |
Not enough credits | Top up |
404 |
Model not on sale | Call GET /v1/models for valid names |
429 |
Too many concurrent calls | Back off and retry |
503 |
Upstream model failing | Retry later, or pick another model |
Errors cost nothing. Any call that does not return an answer is refunded
automatically. You can verify this in GET /v1/credits — the ledger records
every charge and every refund.
We never substitute models on your behalf. If you ask for claude-opus-5
and its upstream is failing, we return an error and refund — we do not quietly
answer with a cheaper model.