Chat Completions
Send chat completion requests to any AI model via the OpenAI-compatible /v1/chat/completions endpoint. Supports streaming, tool calls, vision, and JSON mode.
The chat completions endpoint is OpenAI-compatible. Send a list of messages and receive a model-generated response.
Endpoint
POST https://api.ruvicode.com/v1/chat/completionsRequest body
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model ID (e.g., glm-5.2) |
messages | array | Yes | List of message objects |
stream | boolean | No | Enable streaming (default false) |
max_tokens | number | No | Max output tokens |
temperature | number | No | 0 to 2, default 1 |
top_p | number | No | Nucleus sampling, 0 to 1 |
stop | array | No | Sequences where generation stops |
seed | number | No | Deterministic sampling (model dependent) |
frequency_penalty | number | No | -2 to 2, penalizes repeated tokens |
presence_penalty | number | No | -2 to 2, penalizes new topic tokens |
response_format | object | No | {"type":"json_object"} or {"type":"json_schema",...} |
tools | array | No | Tool definitions (see Tool calling) |
tool_choice | string | object | No |
parallel_tool_calls | boolean | No | Allow multiple tool calls per turn |
reasoning_effort | string | No | low / medium / high on reasoning models |
Parameter pass-through
This is the important part: any parameter not listed above is forwarded to the model provider verbatim. We do not whitelist. If your tool sends top_k, provider-specific extras, or a parameter invented next month, it rides along untouched. If a sampling parameter is absent from your request, we omit it upstream rather than substituting a default, so the model applies its own.
Example
curl https://api.ruvicode.com/v1/chat/completions \
-H "Authorization: Bearer rvcd_..." \
-H "Content-Type: application/json" \
-d '{
"model": "glm-5.2",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is 2+2?"}
],
"max_tokens": 100
}'Response
{
"id": "chatcmpl-...",
"object": "chat.completion",
"model": "glm-5.2",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "2 + 2 = 4"
},
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 7,
"total_tokens": 32,
"prompt_cache_hit_tokens": 0,
"prompt_tokens_details": {
"cached_tokens": 0
}
}
}Cached tokens in usage
When a request reuses a prompt prefix that was already processed, the cached portion is billed at a lower cache read rate instead of the full input rate. Caching is automatic, there is no parameter to set. The usage object reports the split, and clients can read it from these fields:
| Field | Description |
|---|---|
prompt_cache_hit_tokens | Prompt tokens served from cache |
cached_tokens | Same count, nested in prompt_tokens_details |
prompt_tokens is always the full prompt token count, including cached tokens. See Pricing for cache rates and billing rules.
Cost header
Every non-streaming response includes an X-Cost header showing the exact charge in USD:
X-Cost: 0.00000698
This is the amount deducted from your wallet for this request. The same figure is in the body as usage.cost:
"usage": { "prompt_tokens": 12, "completion_tokens": 7, "total_tokens": 19, "cost": 0.00000698 }Streaming responses cannot carry headers added after generation starts, so they report the cost only in usage.cost on the final usage chunk.
Tool calling
Tool definitions follow the OpenAI shape and are passed through as-is. When the model decides to call a tool, the response contains tool_calls on the assistant message:
{
"choices": [{
"message": {
"role": "assistant",
"content": null,
"tool_calls": [{
"id": "call_1",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"city\": \"Jakarta\"}"
}
}]
},
"finish_reason": "tool_calls"
}]
}Send the tool result back as a tool role message and continue the conversation:
{
"model": "glm-5.2",
"messages": [
{"role": "user", "content": "What's the weather in Jakarta?"},
{"role": "assistant", "content": null, "tool_calls": [{"id": "call_1", "type": "function", "function": {"name": "get_weather", "arguments": "{\"city\": \"Jakarta\"}"}}]},
{"role": "tool", "tool_call_id": "call_1", "content": "30°C, sunny"},
{"role": "user", "content": "Great, thanks!"}
],
"tools": [{"type": "function", "function": {"name": "get_weather", "parameters": {"type": "object", "properties": {"city": {"type": "string"}}}}}]
}Tool-call history is forwarded verbatim, so agentic frameworks (OpenCode, LangChain agents, Claude-SDK-style loops) work out of the box.
Vision (image input)
Models marked with the vision tag in the catalog accept image input using the OpenAI content-block format. Pass an image by URL or base64 data URL:
{
"model": "kimi-k3",
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": "What's in this image?"},
{"type": "image_url", "image_url": {"url": "https://example.com/photo.png"}}
]
}],
"max_tokens": 200
}For base64, use a data URL: "url": "data:image/png;base64,iVBOR...".
Tool-specific vision config
Some coding tools (OpenCode, OpenClaw) refuse image attachments at the client side when a custom provider model lacks a modalities declaration, even though the API serves vision fine. In those tools' config, add:
"modalities": { "input": ["text", "image"], "output": ["text"] }to each vision model entry. Models without the vision tag don't need it. See the integrations page for per-tool examples.
Using with SDKs
Python
from openai import OpenAI
client = OpenAI(api_key="rvcd_...", base_url="https://api.ruvicode.com/v1")
response = client.chat.completions.create(
model="glm-5.2",
messages=[{"role": "user", "content": "Hello!"}]
)Node.js
import OpenAI from "openai";
const client = new OpenAI({ apiKey: "rvcd_...", baseURL: "https://api.ruvicode.com/v1" });
const response = await client.chat.completions.create({
model: "glm-5.2",
messages: [{ role: "user", content: "Hello!" }],
});Why the model may misname itself
Ask a model which version it is and it may answer from outdated training data, for example a V4 release calling itself V3. This happens on every provider and is not a sign that the wrong model served your request. The model field in the API response and the model catalog are the source of truth for what actually served the request.