- Docs
- API reference
- Chat Completions
Chat Completions
https://api.airoutly.com/v1/chat/completionsGenerate a model reply to a conversation. Compatible with the OpenAI Chat Completions API, and works with every chat model on Airoutly, including Claude and Gemini.
Authentication
Send your API key as a Bearer token. The OpenAI SDKs do this for you when you pass api_key.
Authorization: Bearer $AIROUTLY_API_KEYRequest body
| Parameter | Description |
|---|---|
modelstringrequired | Model ID from the models page, such as gpt-5 or claude-sonnet-4-5. |
messagesarrayrequired | The conversation so far. Each message has a role (system, user, assistant or tool) and content. For multimodal models, content can be an array of text and image_url parts. |
streamboolean | Return the reply as server-sent events. Recommended for long outputs. |
stream_optionsobject | Set {"include_usage": true} to get token usage in the last chunk of a stream. |
max_tokensinteger | Upper limit on generated tokens. OpenAI reasoning models use max_completion_tokens instead. |
temperaturenumber | Sampling temperature, 0 to 2. Some reasoning models only accept the default. |
toolsarray | Functions the model may call. Use with tool_choice (auto, none, required or a specific function). |
response_formatobject | {"type": "json_object"} or a JSON schema, on models that support structured output. |
Other OpenAI parameters are passed through to the model. Whether they take effect depends on the model.
Example request
curl https://api.airoutly.com/v1/chat/completions \
-H "Authorization: Bearer $AIROUTLY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
]
}'import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.airoutly.com/v1",
api_key=os.environ["AIROUTLY_API_KEY"],
)
reply = client.chat.completions.create(
model="gpt-5",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"},
],
)
print(reply.choices[0].message.content)import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.airoutly.com/v1",
apiKey: process.env.AIROUTLY_API_KEY,
});
const reply = await client.chat.completions.create({
model: "gpt-5",
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "Hello!" },
],
});
console.log(reply.choices[0].message.content);Response
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1762300800,
"model": "gpt-5",
"choices": [{
"index": 0,
"message": { "role": "assistant", "content": "Hello! How can I help?" },
"finish_reason": "stop"
}],
"usage": { "prompt_tokens": 19, "completion_tokens": 8, "total_tokens": 27 }
}You are billed for the usage shown here, at the model’s price on the models page.
Streaming
With "stream": true, the reply arrives as a series of data: lines and ends with data: [DONE]. Add stream_options to get usage in the last chunk.
data: {"object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Hel"}}]}
data: {"object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"lo!"}}]}
data: {"object":"chat.completion.chunk","choices":[],"usage":{"prompt_tokens":19,"completion_tokens":8,"total_tokens":27}}
data: [DONE]Errors
Errors use the OpenAI error shape. Rely on the HTTP status and code; the message ends with a request ID to quote when you contact support. See error codes for what each one means.
{
"error": {
"message": "No available channel for model gpt-6 (request id: 20261105...)",
"type": "new_api_error",
"code": "model_not_found"
}
}