Dashboard

Cookbook Recipe

Model Selection

Pick the right model at runtime

Choose a chat model and build its request from what GET /v1/models publishes, so a new model works with no code change.

GEThttps://api.devupai.com/v1/models

What you'll build

A program that describes a task in a small object (the capabilities it needs, and whether the model should reason), reads the model list, keeps the models that fit, and sends a Chat Completions request to the first one that answers. The reasoning parameter, tool_choice and the output cap come from the chosen model's own entry, and no model ID appears anywhere in the code.

Before you start

  • An API key (sk-devup-...) from your account dashboard, exported as DEVUP_API_KEY. See Authentication. The program checks the variable before it builds the client and stops with Set DEVUP_API_KEY. when it is missing, so no other variable is ever used.
  • Python 3.10 or later, or Node.js 22.12 or later.
pip install openai httpx

The complete program

The Node.js program uses the official devupai SDK for the model list and for every model call: client.models.list() sends the ETag for you and resolves to null on a 304. The Python program reads the model list with httpx, because the openai package raises on a 304, and makes every model call through the openai SDK.

In Node.js, model calls keep the SDK's default retries. The devupai SDK retries 408, 429, 502, 503 and 504 responses up to twice, waiting what the response asks for within the client timeout; it never retries 409 or 500. The client's timeout is one deadline for the whole call, retries and waits included, so the program sets it to two minutes. In Python, max_retries=0 turns off the client's automatic retries, which would also repeat a 409; an error on a model call is handled as described below. For a full retry policy, see Production error handling.

# choose_model.py: pick a chat model from GET /v1/models and call it.
import math
import os
import re
import sys
import time
from dataclasses import dataclass, field
from typing import Any, Callable, Literal, Optional

import httpx
import openai
from openai import OpenAI

BASE_URL = "https://api.devupai.com/v1"
CHAT_TYPE = "text-generation"
# Error codes that move the program on to the next candidate.
MOVE_ON = {"use_responses_api", "wrong_endpoint", "unsupported_parameter", "model_not_found"}
# Catalog statuses worth another try after the wait the response asks for.
RETRYABLE_CATALOG = {429, 503}
MAX_CATALOG_ATTEMPTS = 3
MAX_WAIT_S = 60.0


@dataclass
class Task:
    needs: list[str] = field(default_factory=list)  # supports.* flags, e.g. "tools"
    reasoning: Literal["off", "on", "any"] = "any"
    tool_choice: Optional[Literal["required"]] = None
    max_tokens: Optional[int] = None
    reasoning_value: Optional[Any] = None  # preferred value when reasoning is "on"


@dataclass
class CatalogCache:
    models: Optional[list[dict]] = None
    etag: Optional[str] = None
    fresh_until: float = 0.0


@dataclass
class Attempt:
    response: Any = None
    code: Optional[str] = None


class CatalogError(Exception):
    def __init__(self, status: int, code: Optional[str], request_id: Optional[str]):
        super().__init__(f"GET /v1/models answered {status}{' ' + code if code else ''}.")
        self.status = status
        self.code = code
        self.request_id = request_id


def header_number(value: Optional[str]) -> Optional[float]:
    """A header value as a finite number, or None when it is missing or not a number."""
    if value is None or value.strip() == "":
        return None
    try:
        number = float(value)
    except ValueError:
        return None
    return number if math.isfinite(number) else None


def retry_after_s(headers: httpx.Headers) -> float:
    """The wait a 429 or 503 asks for: retry-after-ms, then Retry-After (seconds), at least 1 s, at most MAX_WAIT_S."""
    ms = header_number(headers.get("retry-after-ms"))
    seconds = header_number(headers.get("retry-after"))
    wait = ms / 1000 if ms is not None else seconds if seconds is not None else 0.0
    if wait <= 0:
        return 1.0
    return min(wait, MAX_WAIT_S)


def max_age_s(cache_control: Optional[str]) -> float:
    """How long a response may be reused, from its Cache-Control max-age (0 when absent)."""
    match = re.search(r"max-age=(\d+)", cache_control or "")
    return float(match.group(1)) if match else 0.0


def error_code(response: httpx.Response) -> Optional[str]:
    try:
        return response.json()["error"]["code"]
    except (ValueError, KeyError, TypeError):
        return None  # a body that is not a JSON error object carries no code


def fetch_catalog(http: httpx.Client, api_key: str, cache: CatalogCache,
                  now: Callable[[], float], sleep: Callable[[float], None]) -> list[dict]:
    """GET /v1/models over plain HTTP. Reuses the cached list while Cache-Control allows,
    then revalidates it with If-None-Match: a 304 keeps the cached list."""
    if cache.models is not None and now() < cache.fresh_until:
        return cache.models
    tries = 1
    while True:
        headers = {"Authorization": f"Bearer {api_key}"}
        if cache.models is not None and cache.etag:
            headers["If-None-Match"] = cache.etag
        response = http.get(f"{BASE_URL}/models", headers=headers)
        if response.status_code == 304 and cache.models is not None:
            cache.fresh_until = now() + max_age_s(response.headers.get("cache-control"))
            return cache.models
        if response.status_code == 200:
            cache.models = response.json()["data"]
            cache.etag = response.headers.get("etag")
            cache.fresh_until = now() + max_age_s(response.headers.get("cache-control"))
            return cache.models
        if response.status_code in RETRYABLE_CATALOG and tries < MAX_CATALOG_ATTEMPTS:
            sleep(retry_after_s(response.headers))
            tries += 1
            continue
        raise CatalogError(response.status_code, error_code(response), response.headers.get("x-request-id"))


def catalog_loader(http: httpx.Client, api_key: str, cache: CatalogCache,
                   now: Callable[[], float], sleep: Callable[[float], None]) -> Callable[..., list[dict]]:
    """A loader for run(): refresh=True drops the cached list and fetches it again."""
    def load(refresh: bool = False) -> list[dict]:
        if refresh:
            cache.models, cache.etag, cache.fresh_until = None, None, 0.0
        return fetch_catalog(http, api_key, cache, now, sleep)
    return load


def has_reasoning_control(reasoning: Optional[dict]) -> bool:
    return (
        isinstance(reasoning, dict)
        and isinstance(reasoning.get("parameter"), str)
        and isinstance(reasoning.get("values"), list)
        and len(reasoning["values"]) > 0
    )


def reasoning_on_value(reasoning: dict, preferred: Any = None) -> Any:
    """The value that turns reasoning on: the task's preferred value when listed, else the first value other than "none"."""
    if preferred is not None and preferred != "none" and preferred in reasoning["values"]:
        return preferred
    return next((value for value in reasoning["values"] if value != "none"), None)


def reasoning_matches(reasoning: Optional[dict], want: str) -> bool:
    """True when the model's published reasoning data fits the task's reasoning need."""
    if want == "any":
        return True
    if not reasoning:
        return False  # mode not known yet
    if want == "off":
        return (
            reasoning.get("mode") == "none"
            or reasoning.get("mode") == "on_request"
            or (has_reasoning_control(reasoning) and "none" in reasoning["values"])
        )
    if reasoning.get("mode") == "always":
        return True
    return (
        reasoning.get("mode") == "on_request"
        and has_reasoning_control(reasoning)
        and reasoning_on_value(reasoning) is not None
    )


def task_checks(task: Task, tools: Optional[list[dict]]) -> list[tuple[str, Callable[[dict], bool]]]:
    """The checks a model must pass for this task, each with the name of the need it checks."""
    needs = list(dict.fromkeys(task.needs + (["tools"] if tools else [])))
    checks: list[tuple[str, Callable[[dict], bool]]] = [
        (f'type "{CHAT_TYPE}"', lambda m: m.get("type") == CHAT_TYPE),
        ("is_replaced false", lambda m: m.get("is_replaced") is not True),
    ]
    for need in needs:
        checks.append((f"supports.{need}", lambda m, need=need: (m.get("supports") or {}).get(need) is True))
    if task.tool_choice == "required":
        checks.append(("tool_choice.required", lambda m: (m.get("tool_choice") or {}).get("required") is True))
    checks.append((f'reasoning "{task.reasoning}"', lambda m: reasoning_matches(m.get("reasoning"), task.reasoning)))
    return checks


def select_candidates(models: list[dict], task: Task, tools: Optional[list[dict]] = None) -> list[dict]:
    """The models that fit the task and its tools, in catalog order."""
    checks = task_checks(task, tools)
    return [m for m in models if all(check(m) for _, check in checks)]


def unmet_need(models: list[dict], task: Task, tools: Optional[list[dict]] = None) -> Optional[str]:
    """The first need that leaves no model, for the message when nothing matches."""
    left = models
    for need, check in task_checks(task, tools):
        left = [m for m in left if check(m)]
        if not left:
            return need
    return None


def at_path(path: str, value: Any) -> dict:
    """A request fragment that sets a parameter path: a dot means a nested field."""
    fragment = value
    for key in reversed(path.split(".")):
        fragment = {key: fragment}
    return fragment


def reasoning_param(reasoning: Optional[dict], task: Task) -> dict:
    """The reasoning parameter for this model and task, named and valued from the model's data."""
    if not has_reasoning_control(reasoning):
        return {}
    if task.reasoning == "off":
        # An "on_request" model does not reason unless asked: nothing to send.
        if reasoning.get("mode") == "on_request":
            return {}
        return at_path(reasoning["parameter"], "none") if "none" in reasoning["values"] else {}
    if task.reasoning == "on" and reasoning.get("mode") == "on_request":
        value = reasoning_on_value(reasoning, task.reasoning_value)
        return {} if value is None else at_path(reasoning["parameter"], value)
    return {}


def build_request(model: dict, task: Task, messages: list[dict], tools: Optional[list[dict]] = None,
                  with_reasoning: bool = True) -> dict:
    """The keyword arguments of client.chat.completions.create() for one model."""
    request: dict = {"model": model["id"], "messages": messages}
    if tools:
        request["tools"] = tools
    if task.tool_choice == "required" and (model.get("tool_choice") or {}).get("required") is True:
        request["tool_choice"] = "required"
    if task.max_tokens is not None:
        limit = model.get("max_output_tokens")
        request["max_tokens"] = min(task.max_tokens, limit) if isinstance(limit, int) else task.max_tokens
    if with_reasoning:
        extra = reasoning_param(model.get("reasoning"), task)
        if extra:
            request["extra_body"] = extra
    return request


def attempt(client: OpenAI, request: dict) -> Attempt:
    try:
        return Attempt(response=client.chat.completions.create(**request))
    except openai.APIStatusError as error:
        if error.code in MOVE_ON:
            return Attempt(code=error.code)
        raise


def try_model(client: OpenAI, model: dict, task: Task, messages: list[dict],
              tools: Optional[list[dict]], log: Callable[[str], None]) -> Attempt:
    """One candidate: the full request, then once without the reasoning parameter if the model refuses it."""
    first = attempt(client, build_request(model, task, messages, tools))
    sent_reasoning = bool(reasoning_param(model.get("reasoning"), task))
    if first.code != "unsupported_parameter" or not sent_reasoning:
        return first
    log(f"{model['id']}: unsupported_parameter, retried without {model['reasoning']['parameter']}")
    return attempt(client, build_request(model, task, messages, tools, with_reasoning=False))


def run(client: OpenAI, load_catalog: Callable[..., list[dict]], task: Task, messages: list[dict],
        tools: Optional[list[dict]] = None, log: Callable[[str], None] = print) -> tuple[str, Any]:
    """Tries the candidates in catalog order and returns the chosen model id and its answer."""
    if task.tool_choice == "required" and not tools:
        raise ValueError('tool_choice "required" needs at least one tool.')
    models = load_catalog()
    queue = select_candidates(models, task, tools)
    if not queue:
        raise LookupError(f"No model matches the task. Unmet need: {unmet_need(models, task, tools)}.")
    tried: set[str] = set()
    refreshed = False
    while queue:
        model = queue.pop(0)
        if model["id"] in tried:
            continue
        tried.add(model["id"])
        outcome = try_model(client, model, task, messages, tools, log)
        if outcome.code is None:
            return model["id"], outcome.response
        log(f"{model['id']}: {outcome.code}")
        if outcome.code == "model_not_found" and not refreshed:
            # The list changed since it was read: read it again once, keep going with the models not tried yet.
            refreshed = True
            models = load_catalog(refresh=True)
            queue = [m for m in select_candidates(models, task, tools) if m["id"] not in tried]
    raise LookupError(f"No candidate answered the request ({len(tried)} tried).")


def error_line(error: Exception) -> str:
    """One line for an error that stops the program, with the request id when there is one."""
    # First: no response arrived (a connection error or a timeout, on a model call or on the list).
    if isinstance(error, (openai.APIConnectionError, httpx.HTTPError)):
        return f"No response from the API: {error}"
    if isinstance(error, openai.APIStatusError):
        request_id = error.response.headers.get("x-request-id", "none")
        return f"Chat Completions answered {error.status_code} {error.code or 'no code'} (x-request-id: {request_id})."
    if isinstance(error, CatalogError):
        return f"{error} (x-request-id: {error.request_id or 'none'})"
    return str(error)


def main() -> None:
    api_key = os.environ.get("DEVUP_API_KEY")
    if not api_key:
        print("Set DEVUP_API_KEY.", file=sys.stderr)
        sys.exit(1)
    client = OpenAI(api_key=api_key, base_url=BASE_URL, max_retries=0)
    with httpx.Client(timeout=30) as http:
        load_catalog = catalog_loader(http, api_key, CatalogCache(), time.monotonic, time.sleep)

        task = Task(needs=["tools"], reasoning="off")
        tools = [
            {
                "type": "function",
                "function": {
                    "name": "get_weather",
                    "description": "Current weather for a city.",
                    "parameters": {
                        "type": "object",
                        "properties": {"city": {"type": "string"}},
                        "required": ["city"],
                    },
                },
            }
        ]
        messages = [{"role": "user", "content": "What is the weather in Oran?"}]

        try:
            model_id, _response = run(client, load_catalog, task, messages, tools)
        except (openai.APIStatusError, openai.APIConnectionError, httpx.HTTPError,
                CatalogError, LookupError, ValueError) as error:
            print(error_line(error), file=sys.stderr)
            sys.exit(1)
        print(f"Chosen model: {model_id}")


if __name__ == "__main__":
    main()

Run it with python choose_model.py or node choose-model.mjs. It prints the chosen model's id, preceded by one line for each candidate it moved past or retried, with the error code. The lines that appear depend on the catalog and on the answers:

Output shape
<model ID>: use_responses_api
<model ID>: unsupported_parameter, retried without <parameter>
Chosen model: <model ID>

An error that stops the program is printed on one line with its status, its code and the response's x-request-id (err.requestId in Node.js). A connection error or a timeout has no response; each program checks for it first (APIConnectionError in Node.js, openai.APIConnectionError or httpx.HTTPError in Python) and prints "No response from the API" with its message instead.

How it works

1Read the model list once and revalidate it

The program sends the key to GET /v1/models as Authorization: Bearer. A 200 carries Cache-Control: private with a max-age, and a strong ETag. The program reuses the list while max-age allows, then sends the stored ETag in If-None-Match. A 304 has an empty body, so the cached list stays in use. In Node.js, client.models.list({ ifNoneMatch, maxRetries: 0 }).withResponse() sends the header, resolves data to null on a 304, and gives the ETag and Cache-Control headers through response.headers. Pass the ETag as ifNoneMatch, not as a header: only then does a 304 resolve instead of throwing.

A 429 or 503 on the model list waits for the time the response asks for (retry-after-ms, then Retry-After; in Node.js the SDK reads both into err.retryAfterMs), at least one second and at most 60 seconds, and tries again, up to three attempts in both languages. The SDK's own retries are turned off for this call so this code decides when to try again.

def fetch_catalog(http: httpx.Client, api_key: str, cache: CatalogCache,
                  now: Callable[[], float], sleep: Callable[[float], None]) -> list[dict]:
    """GET /v1/models over plain HTTP. Reuses the cached list while Cache-Control allows,
    then revalidates it with If-None-Match: a 304 keeps the cached list."""
    if cache.models is not None and now() < cache.fresh_until:
        return cache.models
    tries = 1
    while True:
        headers = {"Authorization": f"Bearer {api_key}"}
        if cache.models is not None and cache.etag:
            headers["If-None-Match"] = cache.etag
        response = http.get(f"{BASE_URL}/models", headers=headers)
        if response.status_code == 304 and cache.models is not None:
            cache.fresh_until = now() + max_age_s(response.headers.get("cache-control"))
            return cache.models
        if response.status_code == 200:
            cache.models = response.json()["data"]
            cache.etag = response.headers.get("etag")
            cache.fresh_until = now() + max_age_s(response.headers.get("cache-control"))
            return cache.models
        if response.status_code in RETRYABLE_CATALOG and tries < MAX_CATALOG_ATTEMPTS:
            sleep(retry_after_s(response.headers))
            tries += 1
            continue
        raise CatalogError(response.status_code, error_code(response), response.headers.get("x-request-id"))

2Keep the models that fit the task

Each check reads one published field of the model object. A candidate has type: "text-generation", is not marked is_replaced: true, and has true for every supports flag the task needs. When tools are passed, supports.tools is required as well, whether or not the task lists it. A task that forces a tool call also needs tool_choice.required: true; that key is present only when known, and false means the model does not enforce it. The reasoning object decides the reasoning need:

  • "off": mode is "none" (no reasoning to turn off), or "on_request" (the model reasons only when asked, so nothing is sent), or values lists "none", which turns reasoning off when sent.
  • "on": mode is "always", or "on_request" with a parameter and at least one value other than "none" in values.
  • "any": every model.
  • No reasoning object: the mode is not known yet, so the model is kept only for "any".
def reasoning_matches(reasoning: Optional[dict], want: str) -> bool:
    """True when the model's published reasoning data fits the task's reasoning need."""
    if want == "any":
        return True
    if not reasoning:
        return False  # mode not known yet
    if want == "off":
        return (
            reasoning.get("mode") == "none"
            or reasoning.get("mode") == "on_request"
            or (has_reasoning_control(reasoning) and "none" in reasoning["values"])
        )
    if reasoning.get("mode") == "always":
        return True
    return (
        reasoning.get("mode") == "on_request"
        and has_reasoning_control(reasoning)
        and reasoning_on_value(reasoning) is not None
    )


def task_checks(task: Task, tools: Optional[list[dict]]) -> list[tuple[str, Callable[[dict], bool]]]:
    """The checks a model must pass for this task, each with the name of the need it checks."""
    needs = list(dict.fromkeys(task.needs + (["tools"] if tools else [])))
    checks: list[tuple[str, Callable[[dict], bool]]] = [
        (f'type "{CHAT_TYPE}"', lambda m: m.get("type") == CHAT_TYPE),
        ("is_replaced false", lambda m: m.get("is_replaced") is not True),
    ]
    for need in needs:
        checks.append((f"supports.{need}", lambda m, need=need: (m.get("supports") or {}).get(need) is True))
    if task.tool_choice == "required":
        checks.append(("tool_choice.required", lambda m: (m.get("tool_choice") or {}).get("required") is True))
    checks.append((f'reasoning "{task.reasoning}"', lambda m: reasoning_matches(m.get("reasoning"), task.reasoning)))
    return checks

The candidates keep their catalog order; the program does not sort them. Each check carries the name of the need it tests, so when no model is left the error names the first need that emptied the list, for example supports.vision.

3Build the request from the model's data

The reasoning parameter's name comes from reasoning.parameter and its value from reasoning.values, never from the code. Send only a listed value: that list is what the model accepts. parameter is a path; a dot means a nested field, so reasoning.enabled is sent as {"reasoning": {"enabled": …}}. For "off" the program sends "none" only to a model that lists it and is not "on_request". For "on" it sends a listed value only to an "on_request" model: the task's preferred value when listed, otherwise the first value other than "none". An "always" model reasons without being asked, so nothing is sent.

tool_choice is sent as "required" only when the task asks for it and the model publishes tool_choice.required: true. To keep the model from calling tools, send "none" (enforced when tool_choice.none is true), or leave tools out. When the task sets max_tokens / maxTokens, it is clamped to the model's max_output_tokens when that field is present.

def at_path(path: str, value: Any) -> dict:
    """A request fragment that sets a parameter path: a dot means a nested field."""
    fragment = value
    for key in reversed(path.split(".")):
        fragment = {key: fragment}
    return fragment


def reasoning_param(reasoning: Optional[dict], task: Task) -> dict:
    """The reasoning parameter for this model and task, named and valued from the model's data."""
    if not has_reasoning_control(reasoning):
        return {}
    if task.reasoning == "off":
        # An "on_request" model does not reason unless asked: nothing to send.
        if reasoning.get("mode") == "on_request":
            return {}
        return at_path(reasoning["parameter"], "none") if "none" in reasoning["values"] else {}
    if task.reasoning == "on" and reasoning.get("mode") == "on_request":
        value = reasoning_on_value(reasoning, task.reasoning_value)
        return {} if value is None else at_path(reasoning["parameter"], value)
    return {}


def build_request(model: dict, task: Task, messages: list[dict], tools: Optional[list[dict]] = None,
                  with_reasoning: bool = True) -> dict:
    """The keyword arguments of client.chat.completions.create() for one model."""
    request: dict = {"model": model["id"], "messages": messages}
    if tools:
        request["tools"] = tools
    if task.tool_choice == "required" and (model.get("tool_choice") or {}).get("required") is True:
        request["tool_choice"] = "required"
    if task.max_tokens is not None:
        limit = model.get("max_output_tokens")
        request["max_tokens"] = min(task.max_tokens, limit) if isinstance(limit, int) else task.max_tokens
    if with_reasoning:
        extra = reasoning_param(model.get("reasoning"), task)
        if extra:
            request["extra_body"] = extra
    return request

4Move on by error code

Every request goes to /v1/chat/completions. The program sends the request and moves on at 400 use_responses_api, so it also works for models whose tool_calls is not published yet. 400 wrong_endpoint moves on the same way. A refused request is not billed.

Some models refuse the reasoning parameter together with tools and answer 400 unsupported_parameter. The program builds the same request again without that field, retries once on the same model and logs <id>: unsupported_parameter, retried without <parameter>; the answer then uses the model's default reasoning. If that request is refused too, the program moves on. The Node.js program branches on err.code of a DevupAPIError, the Python program on error.code of an openai.APIStatusError. Any other error stops the program: in Node.js after the SDK's own retries, in Python at once, since its client has max_retries=0.

def attempt(client: OpenAI, request: dict) -> Attempt:
    try:
        return Attempt(response=client.chat.completions.create(**request))
    except openai.APIStatusError as error:
        if error.code in MOVE_ON:
            return Attempt(code=error.code)
        raise


def try_model(client: OpenAI, model: dict, task: Task, messages: list[dict],
              tools: Optional[list[dict]], log: Callable[[str], None]) -> Attempt:
    """One candidate: the full request, then once without the reasoning parameter if the model refuses it."""
    first = attempt(client, build_request(model, task, messages, tools))
    sent_reasoning = bool(reasoning_param(model.get("reasoning"), task))
    if first.code != "unsupported_parameter" or not sent_reasoning:
        return first
    log(f"{model['id']}: unsupported_parameter, retried without {model['reasoning']['parameter']}")
    return attempt(client, build_request(model, task, messages, tools, with_reasoning=False))

5Read the list again when a model is gone

A model can leave the catalog between reading the list and calling it, which answers 404 model_not_found. The program drops its cached list, reads it again once, and continues with the candidates it has not tried yet. Each candidate it moves past is printed with its code.

        outcome = try_model(client, model, task, messages, tools, log)
        if outcome.code is None:
            return model["id"], outcome.response
        log(f"{model['id']}: {outcome.code}")
        if outcome.code == "model_not_found" and not refreshed:
            # The list changed since it was read: read it again once, keep going with the models not tried yet.
            refreshed = True
            models = load_catalog(refresh=True)
            queue = [m for m in select_candidates(models, task, tools) if m["id"] not in tried]

In production

  • Keep one cached list per process and revalidate it with If-None-Match once its Cache-Control max-age has passed; don't fetch it per request.
  • Fail clearly when no model matches: report the unmet need to whoever owns the task, instead of falling back to a fixed model.
  • Never pin capabilities in code. The task names its needs and the catalog says which models meet them, so a new model that fits is picked up at the next refresh.
  • Log the per-candidate error codes, so you can see which models a task moves past and why.
  • In Node.js, model calls keep the SDK's default retries within one client timeout; set that timeout to the longest answer you expect. The Python client has its automatic retries turned off with max_retries=0, so a 409 is never sent again. For a full retry policy, see Production error handling.

Errors this recipe handles

CodeStatusWhat the program does
use_responses_api400Chat Completions does not serve this model for this request. The program moves on to the next candidate.
wrong_endpoint400The model is served on another endpoint. The program moves on to the next candidate.
unsupported_parameter400The model does not accept the reasoning parameter in this request (for example together with tools). The program retries once on the same model without it, then moves on.
model_not_found404The model left the catalog after the list was read. The program drops its cached list, reads it again once, and continues with the candidates it has not tried.
missing_tools400A tool_choice / toolChoice of "required" needs at least one tool. The program refuses this locally, before anything is sent: add a tool, or leave tool_choice / toolChoice out of the task.
invalid_api_key401GET /v1/models did not accept the key. The program stops; copy the key again from your dashboard into DEVUP_API_KEY.
rate_limit_exceeded429On the model list, the program waits for retry-after-ms or Retry-After and tries again, up to three attempts.
service_unavailable503On the model list, the program waits for Retry-After and tries again, up to three attempts.

The 401, 429 and 503 rows apply to GET /v1/models. On model calls, the devupai SDK retries 408, 429, 502, 503 and 504 itself, and the Python openai client sends no retry (max_retries=0); any other error stops the program with its status, code and x-request-id.

Next steps