Create a chat completion

OpenAI-compatible chat completions: messages, tools, images and streaming are passed to the model as sent.

Request#

POST/v1/chat/completions

Send an active Bearer key and a JSON body in the OpenAI chat completions format. Use a current public model ID from GET /v1/models. Any OpenAI SDK or agent works with the Runlode base URL and key.

curl -fsS https://api.runlode.xyz/v1/chat/completions \
  -H "Authorization: Bearer $RUNLODE_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: YOUR_UNIQUE_REQUEST_ID" \
  --data '{
    "model": "deepseek-v4.1-flash",
    "messages": [{"role": "user", "content": "Hello, Runlode."}],
    "max_tokens": 256
  }'

Keep the same request ID, API key and input when retrying this logical request.

Body parameters#

FieldHow Runlode handles it
modelRequired. A Runlode model ID from GET /v1/models; Runlode sends it to the provider route.
messagesPassed as sent: system, user, assistant and tool roles, text and image content parts, tool_calls.
streamtrue returns server-sent events (SSE) ending with data: [DONE]. Usage is included when stream_options.include_usage is true.
tools, tool_choice, parallel_tool_callsPassed as sent. Tool calls come back in the OpenAI format, also while streaming.
max_tokens / max_completion_tokensOptional. Values above the model’s output limit are lowered to it; when both are missing, the model’s output limit is sent.
nPassed as sent; the balance hold covers every choice.
Any other fieldPassed as sent (temperature, top_p, stop, seed, response_format, reasoning settings and provider-specific fields).

Whether a model supports tools, images or a parameter is decided by the model. If it refuses, its own error is returned with the same HTTP status. See Request limits.

Successful response#

{
  "id": "<string: response ID>",
  "object": "chat.completion",
  "created": "<integer: Unix seconds>",
  "model": "deepseek-v4.1-flash",
  "choices": [
    {
      "index": 0,
      "finish_reason": "<string: stop | length | tool_calls>",
      "message": {
        "role": "assistant",
        "content": "<string: model reply>"
      }
    }
  ],
  "usage": {
    "prompt_tokens": "<integer>",
    "completion_tokens": "<integer>",
    "total_tokens": "<integer>"
  },
  "billing": {
    "chargedMicros": "<integer: micro-dollars charged>",
    "balanceMicros": "<integer: AI balance after>"
  }
}

Response format. Values in angle brackets describe the type of each field.

FieldMeaning
idResponse ID from the model provider. The Runlode request ID is in the X-Request-Id header.
choices[].messageAssistant message as returned by the model: content, tool_calls, refusal or reasoning fields.
choices[].finish_reasonstop, length, tool_calls or content_filter.
usageInput, output and total token counts reported for the request.
billing.chargedMicrosSettled wallet charge in integer micro-dollars (JSON responses only).
billing.balanceMicrosWallet AI balance after settlement, in integer micro-dollars.
billing.basisreported when the provider sent token usage, estimated otherwise.

Streaming responses carry the same request ID in the X-Request-Id header; the charge appears in Usage when the stream ends.

Reservation and completion#

Before sending, Runlode holds an estimate of the maximum charge: input size plus the output limit. When the request ends, the charge uses the model’s rates and the token usage the provider reports, and the rest of the hold is released. If a stream ends without usage, the charge is estimated from the input and the streamed output.

Use the returned request ID to find the record in Usage. If the request is interrupted, follow Retries and request status before sending a new ID.

Search documentation

Start typing to search the documentation.