Chat completions
POSThttps://api.aerless.si/v1/chat/completions
The OpenAI chat-completions format. Send messages, get the reply, whole or streamed.
Build a request#
curl https://api.aerless.si/v1/chat/completions \
curl -N https://api.aerless.si/v1/chat/completions \
-H "Authorization: Bearer $AERLESS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4.1-flash-abliterated",
"stream": true,
"stream_options": {"include_usage": true},
"reasoning_effort": "off",
"reasoning_effort": "low",
"reasoning_effort": "high",
"reasoning_effort": "max",
"tools": [{"type": "function", "function": {
"name": "get_weather",
"parameters": {"type": "object", "properties": {"city": {"type": "string"}}}
}}],
"messages": [{"role": "user", "content": "Write a two-line poem about the sea."}]
"messages": [{"role": "user", "content": "What is the weather in Lisbon?"}]
"messages": [{"role": "user", "content": [
{"type": "text", "text": "What is in this picture?"},
{"type": "image_url", "image_url": {"url": "‹image URL›"}}
]}]
}'
{
"id": "‹id›",
"object": "chat.completion",
"created": ‹unix time›,
"model": "deepseek-v4.1-flash-abliterated",
"choices": [{"index": 0, "message": {"role": "assistant", "content": "‹the reply›"}, "finish_reason": "stop"}],
"usage": {"prompt_tokens": ‹input tokens›, "completion_tokens": ‹output tokens›}
}
{
"id": "‹id›",
"object": "chat.completion",
"created": ‹unix time›,
"model": "deepseek-v4.1-flash-abliterated",
"choices": [{"index": 0, "message": {"role": "assistant", "reasoning_content": "‹the reasoning›", "content": "‹the reply›"}, "finish_reason": "stop"}],
"usage": {"prompt_tokens": ‹input tokens›, "completion_tokens": ‹output tokens›}
}
{
"id": "‹id›",
"object": "chat.completion",
"created": ‹unix time›,
"model": "deepseek-v4.1-flash-abliterated",
"choices": [{"index": 0, "message": {"role": "assistant", "content":null, "tool_calls": [{"id": "‹call id›", "type": "function", "function": {"name": "get_weather", "arguments": "‹the arguments as a JSON string›"}}]}, "finish_reason": "tool_calls"}],
"usage": {"prompt_tokens": ‹input tokens›, "completion_tokens": ‹output tokens›}
}
{
"id": "‹id›",
"object": "chat.completion",
"created": ‹unix time›,
"model": "deepseek-v4.1-flash-abliterated",
"choices": [{"index": 0, "message": {"role": "assistant", "reasoning_content": "‹the reasoning›", "content":null, "tool_calls": [{"id": "‹call id›", "type": "function", "function": {"name": "get_weather", "arguments": "‹the arguments as a JSON string›"}}]}, "finish_reason": "tool_calls"}],
"usage": {"prompt_tokens": ‹input tokens›, "completion_tokens": ‹output tokens›}
}
data: {"id":"‹id›","object":"chat.completion.chunk","created":‹unix time›,"model":"deepseek-v4.1-flash-abliterated","choices":[{"index":0,"delta":{"content":"‹part of the reply›"}}]}
‹more chunks›
data: {"id":"‹id›","object":"chat.completion.chunk","created":‹unix time›,"model":"deepseek-v4.1-flash-abliterated","choices":[],"usage":{"prompt_tokens":‹input tokens›,"completion_tokens":‹output tokens›}}
data: [DONE]
data: {"id":"‹id›","object":"chat.completion.chunk","created":‹unix time›,"model":"deepseek-v4.1-flash-abliterated","choices":[{"index":0,"delta":{"reasoning_content":"‹part of the reasoning›"}}]}
data: {"id":"‹id›","object":"chat.completion.chunk","created":‹unix time›,"model":"deepseek-v4.1-flash-abliterated","choices":[{"index":0,"delta":{"content":"‹part of the reply›"}}]}
‹more chunks›
data: {"id":"‹id›","object":"chat.completion.chunk","created":‹unix time›,"model":"deepseek-v4.1-flash-abliterated","choices":[],"usage":{"prompt_tokens":‹input tokens›,"completion_tokens":‹output tokens›}}
data: [DONE]
data: {"id":"‹id›","object":"chat.completion.chunk","created":‹unix time›,"model":"deepseek-v4.1-flash-abliterated","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"id":"‹call id›","type":"function","function":{"name":"get_weather","arguments":"‹part of the arguments›"}}]}}]}
‹more chunks›
data: {"id":"‹id›","object":"chat.completion.chunk","created":‹unix time›,"model":"deepseek-v4.1-flash-abliterated","choices":[{"index":0,"delta":{},"finish_reason":"tool_calls"}]}
data: {"id":"‹id›","object":"chat.completion.chunk","created":‹unix time›,"model":"deepseek-v4.1-flash-abliterated","choices":[],"usage":{"prompt_tokens":‹input tokens›,"completion_tokens":‹output tokens›}}
data: [DONE]
data: {"id":"‹id›","object":"chat.completion.chunk","created":‹unix time›,"model":"deepseek-v4.1-flash-abliterated","choices":[{"index":0,"delta":{"reasoning_content":"‹part of the reasoning›"}}]}
data: {"id":"‹id›","object":"chat.completion.chunk","created":‹unix time›,"model":"deepseek-v4.1-flash-abliterated","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"id":"‹call id›","type":"function","function":{"name":"get_weather","arguments":"‹part of the arguments›"}}]}}]}
‹more chunks›
data: {"id":"‹id›","object":"chat.completion.chunk","created":‹unix time›,"model":"deepseek-v4.1-flash-abliterated","choices":[{"index":0,"delta":{},"finish_reason":"tool_calls"}]}
data: {"id":"‹id›","object":"chat.completion.chunk","created":‹unix time›,"model":"deepseek-v4.1-flash-abliterated","choices":[],"usage":{"prompt_tokens":‹input tokens›,"completion_tokens":‹output tokens›}}
data: [DONE]
# 400: the model reads text only on this API.
{
"error": {
"message": "‹what is wrong›",
"type": "invalid_request_error",
"param": "‹the field›",
"code": "invalid_request"
}
}
The reply is in choices[0].message.content, tool calls in choices[0].message.tool_calls, token counts in usage. Every response, errors included, carries an x-request-id header; quote it to support.
Request parameters#
| Field | Type | What it does |
|---|---|---|
model | string, required | The model ID, for example deepseek-v4.1-flash-abliterated. See models. |
messages | array, required | At least one message. role is one of system, developer, user, assistant, tool, function; developer is treated as system. content is a string or an array of {"type": "text", "text": "..."} parts. Other message fields are under the table. |
stream | boolean | Stream the reply as server-sent events. See streaming. |
stream_options | object | {"include_usage": true} adds a final chunk with token usage. |
max_tokens | integer ≥ 1 | Most tokens to generate, reasoning included. Default 8,192. Values above 128,000 are lowered to 128,000. max_completion_tokens is accepted as the same thing. |
reasoning_effort | string | off, low, high, max. The standard OpenAI values are translated. See reasoning. |
tools | array | Functions the model may call. See tool calling. |
n | integer | Must be 1 if sent: one completion per request. |
temperature | number, 0 to 2 | Sampling temperature. |
top_p | number, 0 to 1 | Nucleus sampling. |
presence_penalty | number, −2 to 2 | Presence penalty. |
frequency_penalty | number, −2 to 2 | Frequency penalty. |
stop | string or array of strings | Stop sequences. |
Other fields: passed on, removed or refused
Message fields. A message may also have name, tool_calls, tool_call_id, function_call, reasoning_content, reasoning, refusal, prefix. On a message sent back from an earlier reply, annotations, audio, reasoning_details, cache_control are accepted and removed.
Also accepted. These OpenAI fields are passed to the model; whether they take effect depends on the model: top_k, min_p, repetition_penalty, seed, tool_choice, parallel_tool_calls, functions, function_call, response_format, user, logprobs, top_logprobs, logit_bias.
Client hints. Common SDKs and clients send hints that mean nothing for this model. These are accepted and removed early: store, metadata, service_tier, prompt_cache_key, prompt_cache_retention, prompt_cache_options, safety_identifier, verbosity, prediction, transforms, provider, route, models, usage, include_reasoning, modalities. modalities is removed only when it asks for text. Each must have the type the hint has, or the request is refused. OpenRouter’s reasoning object is folded into reasoning_effort.
Refused. audio, web_search_options, plugins, moderation are refused with 400 and a message saying so.
Image parts. The model reads text only on this API: image content parts (image_url and similar) are refused with 400.
Anything else. Any other field is refused with 400 invalid_request, at the top level, in a message or in a content part. So is a value of the wrong type or out of range; param names the field.
Request limits#
- 8 MiB
- 2,097,152 chars
- 1,000,000 tokens
- 20 min
- 64 levels
How each limit applies
- Body: 32 MiB for a key whose tokens-per-minute limit has been raised. Beyond the limit the request is refused with 413, before the body is read when its
Content-Lengthsays so. - A body sent with
Content-Encodinggzip,deflateorbris decompressed and held to the same limit. Any other encoding gets 415. - Text counts across all fields of the request (413 beyond that).
- Context: the prompt and the output together must fit.
- Time: the body must arrive within 60 seconds, and a request may run for at most 20 minutes.
Streaming#
With "stream": true the reply arrives as server-sent events (text/event-stream) of chat.completion.chunk objects, ended by data: [DONE].
Full streaming example in curl, Python and Node
Add "stream_options": {"include_usage": true} for a last chunk with an empty choices array and the usage block; the charge is the same either way.
curl -N https://api.aerless.si/v1/chat/completions \
-H "Authorization: Bearer $AERLESS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4.1-flash-abliterated",
"stream": true,
"stream_options": {"include_usage": true},
"messages": [{"role": "user", "content": "Write a two-line poem about the sea."}]
}'import os
from openai import OpenAI
client = OpenAI(base_url="https://api.aerless.si/v1", api_key=os.environ["AERLESS_API_KEY"])
stream = client.chat.completions.create(
model="deepseek-v4.1-flash-abliterated",
messages=[{"role": "user", "content": "Write a two-line poem about the sea."}],
stream=True,
stream_options={"include_usage": True},
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
if chunk.usage:
print("\n", chunk.usage)import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.aerless.si/v1", apiKey: process.env.AERLESS_API_KEY });
const stream = await client.chat.completions.create({
model: "deepseek-v4.1-flash-abliterated",
messages: [{ role: "user", content: "Write a two-line poem about the sea." }],
stream: true,
stream_options: { include_usage: true },
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
if (chunk.usage) console.log("\n", chunk.usage);
}data: {"id":"‹id›","object":"chat.completion.chunk","created":‹unix time›,"model":"deepseek-v4.1-flash-abliterated","choices":[{"index":0,"delta":{"content":"‹part of the reply›"}}]}
‹more chunks›
data: {"id":"‹id›","object":"chat.completion.chunk","created":‹unix time›,"model":"deepseek-v4.1-flash-abliterated","choices":[],"usage":{"prompt_tokens":‹input tokens›,"completion_tokens":‹output tokens›}}
data: [DONE]Errors during a stream#
After the stream starts the status is already 200. An error arrives as one more event in the usual error format, then data: [DONE].
The error event, and what is charged
data: {"error":{"message":"The model backend returned an error. Retry the request.","type":"api_error","param":null,"code":"upstream_error"}}
data: [DONE]Check each event for an error field. The tokens delivered before the error are charged; the request is not retried for you after output has started.
If your client disconnects mid-stream, reads nothing for 120 seconds, or the request reaches the 20-minute limit, the stream is ended. Everything the model generated up to then is charged, including what had not yet reached you.
Output check#
Answers are checked for the same prohibited content as requests. A stopped answer gets 403 content_blocked without streaming, or the same error as the last event of a stream; nothing more of it is delivered.
What is charged, and the hourly suspension
The prompt and everything the model generated are charged. After 3 such answers in an hour the account is suspended for an hour (403 account_suspended).
Tool calling#
The model supports OpenAI-style function calling.
- List your functions in
tools. - The reply has
finish_reason: "tool_calls"and atool_callsarray. - Run it. Append the reply and a
toolmessage with itstool_call_id, then call again.
Full tool-calling example in Python
import json, os
from openai import OpenAI
client = OpenAI(base_url="https://api.aerless.si/v1", api_key=os.environ["AERLESS_API_KEY"])
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Current weather for a city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
},
}]
messages = [{"role": "user", "content": "What is the weather in Lisbon?"}]
first = client.chat.completions.create(model="deepseek-v4.1-flash-abliterated", messages=messages, tools=tools)
call = first.choices[0].message.tool_calls[0]
args = json.loads(call.function.arguments)
messages.append(first.choices[0].message)
messages.append({
"role": "tool",
"tool_call_id": call.id,
"content": json.dumps({"city": args["city"], "temp_c": 19, "sky": "clear"}),
})
final = client.chat.completions.create(model="deepseek-v4.1-flash-abliterated", messages=messages, tools=tools)
print(final.choices[0].message.content){
"id": "‹id›",
"object": "chat.completion",
"created": ‹unix time›,
"model": "deepseek-v4.1-flash-abliterated",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "‹call id›",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "‹the arguments as a JSON string›"
}
}
]
},
"finish_reason": "tool_calls"
}
],
"usage": {
"prompt_tokens": ‹input tokens›,
"completion_tokens": ‹output tokens›
}
}Reasoning#
The model can think before it answers. reasoning_effort sets how much: off for none (lowest latency and cost), low for brief reasoning, high for harder problems, max for the most the model will do.
OpenAI values, reasoning text and tokens
The standard OpenAI values are translated, so coding tools work unchanged: none to off, disabled to off, minimal to off, medium to low, default to low, xhigh to max. Any other value is refused with 400.
The reasoning text, when there is any, is returned in message.reasoning_content (or delta.reasoning_content when streaming), separate from content.
Reasoning tokens count as output tokens: they are included in completion_tokens, charged at the output price, and count towards max_tokens. Leave enough room in max_tokens at high settings, or the answer may be cut short.
Full reasoning example in curl, Python and Node
curl https://api.aerless.si/v1/chat/completions \
-H "Authorization: Bearer $AERLESS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4.1-flash-abliterated",
"reasoning_effort": "high",
"messages": [{"role": "user", "content": "How many weekdays are there in March 2027?"}]
}'import os
from openai import OpenAI
client = OpenAI(base_url="https://api.aerless.si/v1", api_key=os.environ["AERLESS_API_KEY"])
response = client.chat.completions.create(
model="deepseek-v4.1-flash-abliterated",
messages=[{"role": "user", "content": "How many weekdays are there in March 2027?"}],
# off, low, high or max. Sent through extra_body because the SDK's own
# type for reasoning_effort does not list "off" and "max".
extra_body={"reasoning_effort": "high"},
)
message = response.choices[0].message
print(getattr(message, "reasoning_content", None)) # the model's reasoning, if any
print(message.content)import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.aerless.si/v1", apiKey: process.env.AERLESS_API_KEY });
const response = await client.chat.completions.create({
model: "deepseek-v4.1-flash-abliterated",
messages: [{ role: "user", content: "How many weekdays are there in March 2027?" }],
reasoning_effort: "high", // off, low, high or max
});
const message = response.choices[0].message;
console.log(message.reasoning_content); // the model's reasoning, if any
console.log(message.content);{
"id": "‹id›",
"object": "chat.completion",
"created": ‹unix time›,
"model": "deepseek-v4.1-flash-abliterated",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"reasoning_content": "‹the reasoning›",
"content": "‹the reply›"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": ‹input tokens›,
"completion_tokens": ‹output tokens›
}
}Usage and caching#
| Field | What it counts |
|---|---|
usage.prompt_tokens | Input tokens, cached ones included. |
usage.completion_tokens | Output tokens, reasoning included. |
usage.prompt_tokens_details.cached_tokens | Input tokens served from the cache. Present only when caching applied. |
How the charge is worked out
Without streaming, closing the connection does not stop the request: the model finishes the answer and it is charged in full.
The charge is (prompt tokens − cached tokens) × input price + cached tokens × cached price + completion tokens × output price, rounded up to a whole micro-dollar. See pricing. If a stream ends without a usage block, for example when the connection drops, the charge is based on an estimate of the tokens processed.
Caching#
A request that starts like an earlier one can have that prefix served from cache, faster and at the cached-input price. Hits are not guaranteed.
How to get more cache hits
- Put stable content first: system prompt, tool definitions, reference documents.
- Append to a conversation rather than editing earlier turns.
- Requests from one API key are routed to the same backend account where possible, to make cache hits more likely.