Chat Completions
MarkdownA model's response to a conversation in the OpenAI format. The most widely used format: almost all clients support it.
Full guide
https://api.ailoot.ai/v1/chat/completionscurl https://api.ailoot.ai/v1/chat/completions \
-H "Authorization: Bearer $AILOOT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5-5",
"messages": [
{"role": "user", "content": "Explain what an API is in two sentences."}
]
}' from openai import OpenAI
import os
client = OpenAI(max_retries=0,
base_url="https://api.ailoot.ai/v1",
api_key=os.environ["AILOOT_API_KEY"],
)
resp = client.chat.completions.create(
model="claude-sonnet-5-5",
messages=[{"role": "user", "content": "Explain what an API is in two sentences."}],
)
print(resp.choices[0].message.content)import OpenAI from "openai";
const client = new OpenAI({ maxRetries: 0,
baseURL: "https://api.ailoot.ai/v1",
apiKey: process.env.AILOOT_API_KEY,
});
const resp = await client.chat.completions.create({
model: "claude-sonnet-5-5",
messages: [{ role: "user", content: "Explain what an API is in two sentences." }],
});
console.log(resp.choices[0].message.content);{
"id": "chatcmpl-8f2c…",
"object": "chat.completion",
"created": 1790812800,
"model": "claude-sonnet-5-5",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "An API is an agreement on how one program asks another to do something…"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 21,
"completion_tokens": 48,
"total_tokens": 69
}
}Authentication
- Authorizationheaderrequired
The key in the format
Bearer sk-…. The following headers also work:x-api-keyorx-goog-api-key.
Request body
- modelstringrequired
Model ID from the catalog, for example
claude-sonnet-5-5. The model must support the OpenAI Chat format. - messagesarrayrequired
Conversation history: objects with
role(system,developer,user,assistant,tool) andcontent— a string or an array of parts (text,image_url). - streambooleanoptional
A response in the Server-Sent Events format. Defaults to
false. Billable text is delivered in a single block after the cost is calculated, rather than word by word. - stream_optionsobjectoptional
{"include_usage": true}— include the finalusageas the last event in the stream. - max_tokensintegeroptional
Maximum response tokens. The newer name is
max_completion_tokens. If no limit is set, Ailoot uses 4096 (or less if the model's response limit is lower; Grok has its own limit). For longer responses, set the limit explicitly; otherwise, the response stops at 4096 tokens withfinish_reason: "length". The limit is included in the reserve: the higher it is, the more available balance you need. - temperaturenumberoptional
Response randomness, usually from 0 to 2. Reasoning models may ignore it.
- top_pnumberoptional
An alternative to temperature: the fraction of probability mass used to select tokens.
- stopstring | arrayoptional
Strings that stop generation.
- toolsarrayoptional
Definitions of functions the model can call. Uses the OpenAI format:
{"type": "function", "function": {...}}. - tool_choicestring | objectoptional
auto,none,requiredor a specific function. - response_formatobjectoptional
{"type": "json_object"}or{"type": "json_schema", ...}for a structured response, if the model supports it. - reasoning_effortstringoptional
Reasoning depth for reasoning models:
low,medium,high.
Other OpenAI parameters are passed through unchanged; support for each parameter is determined by the model's developer.
Response
- choices[].messageobject
Model response:
content, or for tool calls —tool_calls. - choices[].finish_reasonstring
stop— the response is complete;length— reachedmax_tokens(the response is still considered complete and billed for actual usage);tool_calls— the model is calling a tool. - usageobject
prompt_tokens,completion_tokens,total_tokens— these are used to calculate the charge.