The 5-Minute Migration: Swapping Your OpenAI Base URL to OpenDunes
Your code already speaks the OpenAI format. Change two values, the base URL and the key, and the same code runs through OpenDunes, paid in dinars.
- Change the two values that point your code at OpenDunes.
- Write the model's name the way the API expects it.
- Keep your key out of your code.
You built your app on the OpenAI libraries, then the bill got stuck on a refused card. You expect weeks of rewriting. You need five minutes.
OpenDunes speaks the OpenAI format: the requests your code sends and the answers it reads stay the same. You change two values, and nothing else.
Change the base URL and the key
Your code talks to the API through two settings. The first says where to send the request, the second proves the request is yours.
The base URL is the address every request starts with. Its job is to tell your code which service answers.
Both values sit in one place in your code: where you create the client.
Do I have to rewrite my calls, my prompts or my parsing?
No. The request body, the message format and the answer you read back keep their shape. Your prompts and your parsing code stay as they are.
If your card was refused on the official checkout, the billing wall that sends you looking for a base URL explains why, and what it means for your account.
Update your Python code
Here is the official openai Python library, pointed at OpenDunes. Only the two lines with a comment change.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://opendunes.com/v1", # changed
api_key=os.environ["OPENDUNES_API_KEY"], # changed
)
response = client.chat.completions.create(
model="openai/gpt-6-luna",
messages=[{"role": "user", "content": "Summarise this order in one line."}],
)
print(response.choices[0].message.content)Write the model's full name, as its model page shows it: openai/gpt-6-luna. The part before the slash is the lab that made the model.
Update your JavaScript code
The official JavaScript library takes the same two values.
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://opendunes.com/v1", // changed
apiKey: process.env.OPENDUNES_API_KEY, // changed
});
const completion = await client.chat.completions.create({
model: "openai/gpt-6-luna",
messages: [{ role: "user", content: "Summarise this order in one line." }],
});
console.log(completion.choices[0].message.content);The official libraries also read OPENAI_BASE_URL from the environment. Set the address once there, next to your key.
OPENDUNES_API_KEY=your-key-here
OPENAI_BASE_URL=https://opendunes.com/v1Keep your key out of your code
Your key spends your balance. Anyone who reads it can spend it too.
Paste the key into a source file and push it to a shared repository.
Keep the key in an environment variable or a secret store, and create one key per app so you can revoke one without stopping the others.
Let's see what a real workload costs once it runs.
Your back office summarises 10,000 orders a month with GPT-6 Luna. Its model page shows about 0.11 DA a message, read on 5 October 2026. That comes to about 1,100 DA a month, taken from your dinar balance.
Now send your first request yourself.
Context: you have an OpenDunes key and a terminal.
Task: send one question to openai/gpt-6-luna with curl, then read the answer's text in the reply.
Show the answerHide the answer
Export your key, then send the request:
export OPENDUNES_API_KEY=your-key-here
curl https://opendunes.com/v1/chat/completions \
-H "Authorization: Bearer $OPENDUNES_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "openai/gpt-6-luna", "messages": [{"role": "user", "content": "Hello"}]}'The answer's text sits in choices[0].message.content.
- OpenDunes speaks the OpenAI format: your calls, prompts and parsing stay the same.
- Change two values: the base URL
https://opendunes.com/v1and the key. - Write the model's full name, lab first:
openai/gpt-6-luna. - Keep each key in an environment variable, one key per app.
Frequently Asked Questions
Do I need a new SDK?
No. Keep the official OpenAI library you already use, in Python or JavaScript, and change its base URL and key.
Do streaming and tool calls still work?
They keep the OpenAI format. Each model's page lists what that model supports, such as tools, vision or structured output, so check it before you switch models.
Can I switch back later?
Yes. The change is two values, so going back is two values too. Your prompts and your parsing code never changed.
Your code now runs in dinars. In the next article, you see how to charge your own customers in dinars without a monthly card payment. See you there!
Pay for AI in dinars
- Deposit your dinars with Edahabia or CIB
- An OpenAI-compatible API key
- One balance for the chat and the API