Create a chat completion
OpenAI-compatible chat completions: messages, tools, images and streaming are passed to the model as sent.
Request#
/v1/chat/completionsSend 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
}'// Run on your server. Keep this ID for retries of this request.
const requestId = crypto.randomUUID();
const response = await fetch(
"https://api.runlode.xyz/v1/chat/completions",
{
method: "POST",
headers: {
Authorization: `Bearer ${process.env.RUNLODE_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": requestId
},
body: JSON.stringify({
model: "MODEL_ID",
messages: [{ role: "user", content: "Hello, Runlode." }],
max_tokens: 256
})
}
);
const result = await response.json();
if (!response.ok) {
throw new Error(result.error?.message ?? "Request failed");
}
console.log(result.choices[0].message.content);Keep the same request ID, API key and input when retrying this logical request.
Body parameters#
| Field | How Runlode handles it |
|---|---|
model | Required. A Runlode model ID from GET /v1/models; Runlode sends it to the provider route. |
messages | Passed as sent: system, user, assistant and tool roles, text and image content parts, tool_calls. |
stream | true returns server-sent events (SSE) ending with data: [DONE]. Usage is included when stream_options.include_usage is true. |
tools, tool_choice, parallel_tool_calls | Passed as sent. Tool calls come back in the OpenAI format, also while streaming. |
max_tokens / max_completion_tokens | Optional. Values above the model’s output limit are lowered to it; when both are missing, the model’s output limit is sent. |
n | Passed as sent; the balance hold covers every choice. |
| Any other field | Passed 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.
| Field | Meaning |
|---|---|
id | Response ID from the model provider. The Runlode request ID is in the X-Request-Id header. |
choices[].message | Assistant message as returned by the model: content, tool_calls, refusal or reasoning fields. |
choices[].finish_reason | stop, length, tool_calls or content_filter. |
usage | Input, output and total token counts reported for the request. |
billing.chargedMicros | Settled wallet charge in integer micro-dollars (JSON responses only). |
billing.balanceMicros | Wallet AI balance after settlement, in integer micro-dollars. |
billing.basis | reported 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.