opendunes
Models and routing · 3 min
Copy page ▾

Auto router

Let a router pick the model for each request.

  1. Name the router.
  2. Limit what it picks from.
  3. Read which model answered.

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.

Good to know

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.

FieldHolds
allowed_modelsthe models it may pick: whole names, or patterns such as anthropic/*
excluded_modelsthe models it must not pick
cost_tierlow, medium, high, xhigh or max: how much quality to buy
JSON
{
  "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.

Watch out

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.

RouterPicksTakes
opendunes/autothe model best suited to the prompt, from OpenDunes's listthe three text routes
opendunes/freea free model, and the next free one when a source refuses. No chargechat completions only, for an account holding money, with a limit per minute
typesafe/jev-routera model and its reasoning effort, trading quality, speed and costthe three text routes; cost_tier is low, medium or high
nvidia/switchyarda cheaper or a stronger model, to lower what the request coststhe three text routes
Do

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

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.

StatusMeans
400allowed_models matches no model the router picks from; the message says where to change it
402the balanceBalanceWhat you can spend, in DA.More on Balance and charges → cannot cover the request
403the key may not use the router
404no such router, or one that is not on sale