Send messages to any supported model and receive a completion via the OpenAI-compatible chat endpoint.
Chat completions are the core inference primitive of the OpenDunes API. Send a conversation as an ordered array of messages, get a completion back — or stream it token by token.
POST https://opendunes.com/v1/chat/completionsThis is the only inference endpoint today. It is compatible with the OpenAI chat completions spec, so any code or library targeting the OpenAI API works without modification — just swap the base URL and key.
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model slug, e.g. openai/gpt-5.4 |
messages | array | Yes | Ordered conversation history |
stream | boolean | No | Stream tokens via SSE (default false) |
max_tokens | integer | No | Cap on generated tokens |
temperature | number | No | Sampling temperature, 0–2 (default 1) |
top_p | number | No | Nucleus sampling threshold, 0–1 (default 1) |
For the full parameter set, see Parameters. A field not listed there still travels to the model as you send it.
Each message object has a role and content.
| Role | Purpose |
|---|---|
system | Instructions that shape the model's behavior across the conversation |
user | Input from the human turn |
assistant | Prior model output, or a prefill to continue from |
tool | Tool-call result returned to the model (set tool_call_id) |
content can be a plain string or an array of content parts. Use the parts format to send images alongside text for vision-capable models:
{
"role": "user",
"content": [
{ "type": "text", "text": "What is in this image?" },
{ "type": "image_url", "image_url": { "url": "https://example.com/photo.jpg" } }
]
}import os
from openai import OpenAI
client = OpenAI(
base_url="https://opendunes.com/v1",
api_key=os.environ["OPENDUNES_API_KEY"],
)
resp = client.chat.completions.create(
model="anthropic/claude-sonnet-5",
messages=[
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "Marhba! Say hello in one line."},
],
temperature=0.7,
)
print(resp.choices[0].message.content){
"id": "chatcmpl-01938fae2a7b7000aabbccdd",
"object": "chat.completion",
"created": 1750000000,
"model": "anthropic/claude-sonnet-5",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Marhba bik! Hello and welcome — great to meet you."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 24,
"completion_tokens": 13,
"total_tokens": 37
}
}The usage object shows token counts for the request. Your balance is deducted at the model's DA-per-million-token rate; the X-Balance-Available header in the response carries your remaining balance in micro-DA.
Set "stream": true to receive tokens as server-sent events. See Streaming for the full event format and code examples.
Errors return a non-2xx status code with a JSON body. See Errors for the full status-code table and the exact response shape.