Send messages to any model and stream responses token-by-token using the OpenAI Python SDK.
client.chat.completions.create() is the core method — it maps directly to POST /v1/chat/completions. Every model in the catalog is available through it.
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-opus-4.8",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the capital of Algeria?"},
],
max_tokens=256,
temperature=0.7,
)
print(resp.choices[0].message.content)The response object is a standard ChatCompletion. Check resp.usage for token counts — input and output tokens are both billed at the model's DA rate.
Set stream=True to receive delta chunks over SSE as they are generated. The stream closes with data: [DONE].
import os
from openai import OpenAI
client = OpenAI(
base_url="https://opendunes.com/v1",
api_key=os.environ["OPENDUNES_API_KEY"],
)
stream = client.chat.completions.create(
model="google/gemini-2.5-pro",
messages=[{"role": "user", "content": "Explain recursion in plain Arabic."}],
stream=True,
)
for chunk in stream:
delta = chunk.choices[0].delta.content
if delta:
print(delta, end="", flush=True)
print()The final chunk in the stream carries usage (prompt tokens, completion tokens). Your remaining DA balance is in the X-Balance-Available response header after each request.
Pass an array of content parts to include an image alongside text. The model must support the vision capability — filter by ?capability=vision in the model catalog.
resp = client.chat.completions.create(
model="anthropic/claude-opus-4.8",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "Describe what is in this image."},
{
"type": "image_url",
"image_url": {"url": "https://example.com/image.jpg"},
},
],
}
],
)
print(resp.choices[0].message.content)| Parameter | Type | Description |
|---|---|---|
model | string | Required. Model slug, e.g. openai/gpt-5.4. |
messages | array | Required. Array of {role, content} objects. |
stream | bool | Stream tokens as SSE. Default false. |
max_tokens | int | Cap on output tokens. |
temperature | float | 0–2. Higher = more varied output. |
top_p | float | 0–1. Nucleus sampling threshold. |
Note. Tool/function calling (
tools,tool_choice) and structured outputs (response_format) are supported and forwarded on every request — see the Tool Calling page.