Auto router
Let a router pick the model for each request.
1. Name the router
Send opendunes/auto as the model. The router reads your prompt and picks, from a list of strong current models that OpenDunes keeps, the model best suited to it.
A request that names auto is answered by your account's default router. When you have chosen none in the Gateway page of your dashboard, that router is opendunes/auto.
import json
import os
import urllib.request
API_KEY = os.environ["OPENDUNES_API_KEY"]
ADDRESS = "https://opendunes.com/v1/chat/completions"
MODEL = "opendunes/auto"
PROMPT = "Write a one-line welcome for a bakery in Tlemcen."
body = {
"model": MODEL,
"messages": [{"role": "user", "content": PROMPT}],
}
request = urllib.request.Request(
ADDRESS,
data=json.dumps(body).encode(),
headers={
"Authorization": "Bearer " + API_KEY,
"Content-Type": "application/json",
},
)
with urllib.request.urlopen(request) as response:
reply = json.load(response)
print(reply["model"])
print(reply["choices"][0]["message"]["content"])
print(reply["usage"]["cost"])Routing is free. You pay the model that answers, at its usual price.
The router works on the three text routes: chat completions, messages and responses. It reads pictures and files as well as text.
2. Limit what it picks from
Add the auto-router plugin to the request to say which models it may choose.
| Field | Holds |
|---|---|
allowed_models | the models it may pick: whole names, or patterns such as anthropic/* |
excluded_models | the models it must not pick |
cost_tier | low, medium, high, xhigh or max: how much quality to buy |
{
"model": "opendunes/auto",
"plugins": [
{
"id": "auto-router",
"allowed_models": ["anthropic/*", "google/*"],
"excluded_models": ["google/gemini-2.5-flash"]
}
],
"messages": [{ "role": "user", "content": "Summarise this order." }]
}To keep the same limits on every request without touching code, set them in the Gateway page of your dashboard, under Routing. A field your request names wins over the account's.
Allowed models narrow the router's list and never widen it. A model you allow that is not on the list is not picked.
3. Read which model answered
Every router answer names the model it picked, as lab/model, in model. Log it: it is the one that was charged, and usage.cost is its charge.
| Router | Picks | Takes |
|---|---|---|
opendunes/auto | the model best suited to the prompt, from OpenDunes's list | the three text routes |
opendunes/free | a free model, and the next free one when a source refuses. No charge | chat completions only, for an account holding money, with a limit per minute |
typesafe/jev-router | a model and its reasoning effort, trading quality, speed and cost | the three text routes; cost_tier is low, medium or high |
nvidia/switchyard | a cheaper or a stronger model, to lower what the request costs | the three text routes |
Use opendunes/auto when your prompts vary a lot and you cannot say in advance which model suits each. Use a named model when the same job always needs the same one.
Don't allow only models outside the router's list: the request is refused with a 400. For a list of your own, with fallbacks, name the models yourself: Fallbacks.
Errors
The body says why. What to do on every status: Errors and retries.
| Status | Means |
|---|---|
| 400 | allowed_models matches no model the router picks from; the message says where to change it |
| 402 | the balanceBalanceWhat you can spend, in DA.More on Balance and charges → cannot cover the request |
| 403 | the key may not use the router |
| 404 | no such router, or one that is not on sale |