Move to OpenDunes
Move an app already running on the OpenAI or Anthropic library: three values change, the code stays.
Move this project's OpenAI or Anthropic client to OpenDunes. Change three values and nothing else. Base URL: https://opendunes.com/v1 for the OpenAI library, https://opendunes.com for the Anthropic library. Key: read it from the environment variable OPENDUNES_API_KEY; never write it in a file. Model IDs: lab/model, for example anthropic/claude-sonnet-4.5. Docs: https://opendunes.com/docs/llms.txt
- Get a key and a balance.
- Change the base URL and the key.
- Change the model ID.
- Send one request to check.
- Read what the answer adds.
1. Get a key and a balance
| You need | Where |
|---|---|
| an API keyAPI keyThe key you create and send with every request that calls a model.More on API keys → | API Keys, in the app: see API keys |
| a balanceBalanceWhat you can spend, in DA.More on Balance and charges → above zero | Credit, in the app: depositDepositMoney entering your balance, by CIB or Edahabia card.More on Balance and charges → by Edahabia or CIB |
| the key in your environment | export OPENDUNES_API_KEY="…" |
No foreign card: the balance is in DADAThe Algerian dinar, the one currency the docs show.More on Balance and charges →, and every request is charged to it.
2. Change the base URL and the key
| Library | Base URL | Key |
|---|---|---|
| OpenAI library | https://opendunes.com/v1 | OPENDUNES_API_KEY |
| Anthropic library | https://opendunes.com | OPENDUNES_API_KEY |
Where your code builds the client, change two arguments.
| Tab | OpenAI library | Anthropic library |
|---|---|---|
| Python | OpenAI(base_url=…, api_key=…) | Anthropic(base_url=…, api_key=…) |
| JavaScript | new OpenAI({ baseURL, apiKey }) | new Anthropic({ baseURL, apiKey }) |
| Go | option.WithBaseURL(…), option.WithAPIKey(…) | the same two options |
| cURL | the address, and Authorization: Bearer | the address, and x-api-key |
The Anthropic library adds /v1 itself. Give it https://opendunes.com, without /v1.
If your code builds the client with no arguments, the library reads both values from the environment. Set them there and change no line of code.
# OpenAI library
export OPENAI_BASE_URL="https://opendunes.com/v1"
export OPENAI_API_KEY="$OPENDUNES_API_KEY"
# Anthropic library
export ANTHROPIC_BASE_URL="https://opendunes.com"
export ANTHROPIC_API_KEY="$OPENDUNES_API_KEY"3. Change the model ID
Every model is named lab/model. Put the lab in front of the name you use today; a Claude model also takes a dot in its version, and no date.
| Library | Model IDModel IDThe name a request calls a model by, lab/model, copied from Models.More on Models → today | Model ID on OpenDunes |
|---|---|---|
| OpenAI library | gpt-6-sol | openai/gpt-6-sol |
| Anthropic library | claude-opus-5-5 | anthropic/claude-opus-5.5 |
| Anthropic library | claude-haiku-4-5-20251001 | anthropic/claude-haiku-4.5 |
The rest of the request stays as it is: the same body, with the new ID in model.
{
"model": "anthropic/claude-opus-5.5",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "Two lines to welcome a shop in Oran."
}
]
}Copy an ID from its page in Models rather than typing it: see Models. One key reaches every lab.
4. Send one request to check
Send one short request on the library your app uses. A printed answer and a charge mean the move worked.
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)
reply = client.chat.completions.create(
model=MODEL,
messages=[{"role": "user", "content": "Reply with OK."}],
)
print(reply.choices[0].message.content)
print(reply.usage.cost)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)
message = client.messages.create(
model=MODEL,
max_tokens=1024,
messages=[{"role": "user", "content": "Reply with OK."}],
)
print(message.content[0].text)
print(message.usage.cost)A 401 means the key did not reach the request: check OPENDUNES_API_KEY is set in this terminal. Every other status: Errors and retries.
5. Read what the answer adds
The answer keeps the shape your code already reads. Two things are new, and one status.
| Where | What it is | Illustrative |
|---|---|---|
usage.cost, in the answer | the charge, in DA | 0.020166 DA |
X-Balance-Available, the header | your balance after it, in µDAµDAA millionth of a DA: 1 DA = 1 000 000 µDA.More on Balance and charges → | 499979834 µDA |
| a 402 | the balance is at zero or below, or cannot pay the request's hold | new requests refused until a deposit |
A streamed answer carries no X-Balance-Available: its charge is usage.cost, in the closing event. Streaming shows it, and Balance and charges says how each request is charged.
No library retries a 402: the same request gets the same answer until a deposit covers what the balance owes. If your app retries on every error, let it stop on a 402.
Next: Quickstart chat app · OpenAI and Anthropic libraries · Frameworks
Last modified on