Client SDKs
The OpenAI library and the Anthropic library work against OpenDunes with two fields swapped: the address and the key.
- Install a library.
- Swap the address and the key.
- Send with the OpenAI library.
- Send with the Anthropic library.
- Read the charge and the balance.
1. Install a library
| Tab | OpenAI library | Anthropic library |
|---|---|---|
| Python | pip install openai | pip install anthropic |
| JavaScript | npm install openai | npm install @anthropic-ai/sdk |
| Go | go get github.com/openai/openai-go/v3 | go get github.com/anthropics/anthropic-sdk-go |
| cURL | none | none |
2. Swap the address and the key
| Library | Address | Key |
|---|---|---|
| OpenAI library | https://opendunes.com/v1 | OPENDUNES_API_KEY |
| Anthropic library | https://opendunes.com | OPENDUNES_API_KEY |
Everything else in your code stays as it is. The OpenAI library sends a conversation to POST /v1/chat/completions, the Anthropic library to POST /v1/messages. Create a key first if you have none.
The Anthropic library adds /v1 itself. Give it https://opendunes.com, without /v1.
3. Send with the OpenAI library
import os
from openai import OpenAI
API_KEY = os.environ["OPENDUNES_API_KEY"]
BASE_URL = "https://opendunes.com/v1"
MODEL = "anthropic/claude-sonnet-4.5"
client = OpenAI(base_url=BASE_URL, api_key=API_KEY)
raw = client.chat.completions.with_raw_response.create(
model=MODEL,
messages=[
{"role": "user", "content": "Two lines to welcome a shop in Oran."},
],
)
reply = raw.parse()
print(reply.choices[0].message.content)
print(reply.usage.cost)
print(raw.headers["X-Balance-Available"])With -i, X-Balance-Available is among the headers, and usage.cost is in the body.
4. Send with the Anthropic library
import os
from anthropic import Anthropic
API_KEY = os.environ["OPENDUNES_API_KEY"]
BASE_URL = "https://opendunes.com"
MODEL = "anthropic/claude-sonnet-4.5"
client = Anthropic(base_url=BASE_URL, api_key=API_KEY)
raw = client.messages.with_raw_response.create(
model=MODEL,
max_tokens=1024,
messages=[
{"role": "user", "content": "Two lines to welcome a shop in Oran."},
],
)
message = raw.parse()
print(message.content[0].text)
print(message.usage.cost)
print(raw.headers["X-Balance-Available"])With -i, X-Balance-Available is among the headers, and usage.cost is in the body.
5. Read the charge and the balance
These are the two fields only OpenDunes returns; the libraries pass them through, and the samples above read them.
| Field | Where | Holds |
|---|---|---|
usage.cost | the answer | the charge, in DADAThe Algerian dinar, the one currency the docs show.More on Balance and charges → |
X-Balance-Available | the header | your balanceBalanceWhat you can spend, in DA.More on Balance and charges → after it, in µDAµDAA millionth of a DA: 1 DA = 1 000 000 µDA.More on Balance and charges → |
A streamed answer carries no X-Balance-Available. Its charge is usage.cost, in the closing event: see Streaming.
Working in a framework? Frameworks gives the two fields each needs.