API reference
Chat completions
POST /v1/chat/completions speaks the OpenAI Chat Completions format. Use it with the OpenAI SDKs, or with any library that lets you set a base URL.
curl https://api.libremodel.ai/v1/chat/completions \
-H "Authorization: Bearer $LIBREMODEL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4.1-flash-1017",
"messages": [{"role": "user", "content": "Hello, Libremodel"}]
}'# pip install openai
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.libremodel.ai/v1",
api_key=os.environ["LIBREMODEL_API_KEY"],
)
response = client.chat.completions.create(
model="deepseek-v4.1-flash-1017",
messages=[{"role": "user", "content": "Hello, Libremodel"}],
)
print(response.choices[0].message.content)// npm install openai
import OpenAI from 'openai'
const client = new OpenAI({
baseURL: 'https://api.libremodel.ai/v1',
apiKey: process.env.LIBREMODEL_API_KEY,
})
const response = await client.chat.completions.create({
model: 'deepseek-v4.1-flash-1017',
messages: [{ role: 'user', content: 'Hello, Libremodel' }],
})
console.log(response.choices[0].message.content)Request body
| Parameter | Type | Description |
|---|---|---|
model | string, required | A Libremodel model ID, from Models or GET /v1/models. |
messages | array, required | The conversation, in the Chat Completions format. |
max_completion_tokens / max_tokens | integer | Cap on output tokens, reasoning included. Optional: see Output limit. If you send both, max_completion_tokens wins. |
stream | boolean | Send the response as Server-Sent Events. See Streaming. |
stream_options.include_usage | boolean | With stream, adds a final chunk with the token count. |
reasoning_effort | string | How much the model thinks before answering: low, high, max, off. Each model has its own levels and default. |
Any other Chat Completions parameter is passed to the model unchanged. Whether it has an effect depends on the model.
{
"model": "deepseek-v4.1-flash-1017",
"messages": [
{ "role": "system", "content": "You are a concise assistant." },
{ "role": "user", "content": "Explain SSE in one sentence." }
],
"max_tokens": 512,
"reasoning_effort": "low"
}Response
A Chat Completions object. model is always the Libremodel ID you asked for, and id is always a Libremodel ID (chatcmpl-…). Only the standard Chat Completions fields come back: extras such as system_fingerprint are left out. Every response carries an x-request-id header: keep it if you need to report a problem.
{
"id": "chatcmpl-...",
"object": "chat.completion",
"model": "deepseek-v4.1-flash-1017",
"choices": [
{
"index": 0,
"message": { "role": "assistant", "content": "Server-Sent Events is ..." },
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 27,
"completion_tokens": 41,
"total_tokens": 68,
"prompt_tokens_details": { "cached_tokens": 0 },
"completion_tokens_details": { "reasoning_tokens": 18 }
}
}| Field | What it counts |
|---|---|
usage.prompt_tokens | Input tokens, cached ones included. |
usage.prompt_tokens_details.cached_tokens | Input tokens read from cache. They are billed at the lower cached price. |
usage.completion_tokens | Output tokens, reasoning included. Billed at the output price. |
usage.completion_tokens_details.reasoning_tokens | The part of the output the model spent thinking. |
Output limit (max_tokens)
Every request runs with an output cap, and your balance has to cover it before the request starts (how the hold works).
- If you send `max_tokens` and your balance covers it, that is the cap. If it does not, you get
402 insufficient_balance(or403 key_limit_exceeded, when what falls short is the key's spending limit) and, when possible, the message tells you the largestmax_tokensthat fits. We never lower a limit you set. - If you leave it out, the cap is the model's output limit, lowered to what your balance (and the key's spending limit, if it has one) covers. If that does not cover even 256 output tokens, you get
402(or403). - Either way, a response that reaches the cap ends with
finish_reason: "length". - If your
max_tokensis above the model's output limit, or the input plusmax_tokensdoes not fit in its context, the request can return503 upstream_unavailable(Limits and errors). - Reasoning tokens count toward the cap. A low cap on a model that thinks a lot can end the response before the answer starts.
Reasoning
Models that reason accept reasoning_effort (low, high, max, off). Without it, each model uses its default level; both are listed on Models. When streaming, the reasoning arrives in delta.reasoning_content before the answer.
Errors
Errors come in the OpenAI format: {"error": {"message", "type", "code", "param"}}. The full list is in Limits and errors.