Skip to content
Ruvicode logo
Ruvicode
USD

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/completions

Request body

ParameterTypeRequiredDescription
modelstringYesModel ID (e.g., glm-5.2)
messagesarrayYesList of message objects
streambooleanNoEnable streaming (default false)
max_tokensnumberNoMax output tokens
temperaturenumberNo0 to 2, default 1
top_pnumberNoNucleus sampling, 0 to 1
stoparrayNoSequences where generation stops
seednumberNoDeterministic sampling (model dependent)
frequency_penaltynumberNo-2 to 2, penalizes repeated tokens
presence_penaltynumberNo-2 to 2, penalizes new topic tokens
response_formatobjectNo{"type":"json_object"} or {"type":"json_schema",...}
toolsarrayNoTool definitions (see Tool calling)
tool_choicestringobjectNo
parallel_tool_callsbooleanNoAllow multiple tool calls per turn
reasoning_effortstringNolow / 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:

FieldDescription
prompt_cache_hit_tokensPrompt tokens served from cache
cached_tokensSame 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.