The 5-Minute Migration: Swapping Your OpenAI Base URL to OpenDunes
OpenDunes · June 19, 2026
When you hear about switching your application's infrastructure to a local, Law 18-07 compliant gateway, you probably expect the worst: weeks of code refactoring, learning a new proprietary SDK, dealing with undocumented endpoints, and fixing integration bugs.
For developers and engineering leads, code stability is paramount. You cannot afford to halt your development pipeline to restructure your AI integrations.
Fortunately, you do not have to.
OpenDunes is built on Bifrost OSS, a high-performance proxy architecture that maintains absolute parity with the standard OpenAI and OpenRouter API specifications. To migrate your application, swap your payment headaches for Dinars, and secure compliance, you only need to change two variables in your codebase.
Here is a step-by-step developer guide to configuring the OpenDunes API proxy (openai api proxy).
The Drop-In Replacement Mechanics
The OpenDunes gateway mirrors the standard OpenAI request and response JSON schemas exactly. When your backend dispatches a payload to our endpoints, we handle auth verification, DZD wallet balance checks, and compliance filters before routing the request upstream. The response is returned to your app in the exact format your existing code expects.
To migrate, you only need to modify:
- The Base URL Endpoint: Route requests to our local gateway.
- The API Authorization Key: Replace your OpenAI bearer token with your Dinar-funded OpenDunes key.
1. Python Integration Example
If your backend is built on Django, FastAPI, or Flask, here is how to swap the configuration using the official openai Python library:
import os
import openai
# Swapping the base client configuration
client = openai.OpenAI(
base_url="https://opendunes.com/v1", # Local gateway endpoint
api_key=os.environ.get("OPENDUNES_API_KEY") # Your od-xxxxx key
)
# Your query logic remains 100% unchanged
response = client.chat.completions.create(
model="gpt-4o", # Standard model names are supported directly
messages=[
{"role": "system", "content": "You are a helpful database admin."},
{"role": "user", "content": "Draft a SQL query to fetch daily active users."}
]
)
print(response.choices[0].message.content)
2. Node.js / TypeScript Example
For Next.js, Express, or NestJS applications, the migration is just as simple using the official Javascript SDK:
import OpenAI from 'openai';
const openai = new OpenAI({
baseURL: 'https://opendunes.com/v1', // Swapped URL
apiKey: process.env.OPENDUNES_API_KEY, // Your local DZD key
});
async function generateResponse() {
const completion = await openai.chat.completions.create({
messages: [{ role: 'user', content: 'Generate CSS grid container queries.' }],
model: 'gpt-4o',
});
console.log(completion.choices[0].message.content);
}
3. Environment Variable Configuration
To make the swap across your entire production stack instantly, configure your .env files. This allows you to toggle between environments without touching your core application logic.
Add these lines to your environment configuration:
# OpenDunes API Configuration
OPENAI_API_BASE=https://opendunes.com/v1
OPENAI_API_KEY=od-your-dinar-funded-api-key-here
Most modern frameworks (including Laravel, Django, and Next.js) will automatically inject these variables into the default OpenAI client constructor.
Wallet Management & Error Handling
Because OpenDunes operates on a pre-paid Dinar wallet, your backend should handle balance exceptions.
If your wallet runs out of credits, the gateway will immediately return a standard HTTP error:
- HTTP Status Code:
402 Payment Required - Response Payload:
{
"error": {
"message": "Insufficient balance in OpenDunes wallet. Please fund your account in DZD.",
"type": "insufficient_balance",
"code": "insufficient_credits"
}
}
You can write simple middleware to intercept 402 or 429 status codes and alert your administration dashboard before your users face service interruptions.
Build in Dinars, Query Globally
Migrating to OpenDunes does not mean limiting your model selection. You can query leading models using the same key, funded in Dinars via domestic CIB card, corporate bank transfer, or Edahabia.
Frequently Asked Questions
Does the proxy add latency to my API queries?
Minimal. The OpenDunes gateway is hosted on high-speed servers in Algiers (Djezzy Cloud), which means the handshake happens locally. The onward routing to global providers adds less than 15ms of overhead, which is imperceptible in standard LLM streaming completions.
Do I need to change my model parameter calls?
No. All standard parameters—including temperature, top_p, max_tokens, stream, and response_format (JSON mode)—are supported natively by our proxy layer.
How do I track token usage for billing?
Your developer dashboard provides real-time analytics, showing cost per API key, token consumption per model, and complete request logs, making it easy to generate invoicing reports for your clients.
Take 5 minutes to secure your stack. Create your account, generate your key, and swap to the OpenDunes API Gateway today.