odysseus-dev/odysseus · error · HTTPException

Could not discover models from endpoint

Error message

Could not discover models from endpoint

What it means

HTTP 500 from POST /v1/chat Case 3 with model='auto': the route tried to auto-pick a model and every path failed — the live /models fetch (build_models_url + GET with the endpoint's headers) raised (network error, non-2xx via raise_for_status, invalid JSON), or the fallback JSON parse of ep.cached_models failed. The blanket except converts all of it to one message.

Source

Thrown at routes/webhook/webhook_routes.py:361

                        hdrs = build_headers(api_key, base_url)
                        if models_url:
                            resp = await client.get(models_url, headers=hdrs)
                            resp.raise_for_status()
                            data = resp.json()
                            items = data if isinstance(data, list) else (data.get("data") or [])
                            ids = [m.get("id") for m in items if isinstance(m, dict) and m.get("id")]
                            if not ids and isinstance(data, dict):
                                ids = [
                                    m.get("name") or m.get("model")
                                    for m in (data.get("models") or [])
                                    if m.get("name") or m.get("model")
                                ]
                        else:
                            import json as _json
                            ids = _json.loads(ep.cached_models or "[]")
                        model = ids[0] if ids else "auto"
                except Exception:
                    raise HTTPException(500, "Could not discover models from endpoint")

            if not session_manager:
                raise HTTPException(500, "Session manager not available")

            sid = str(uuid.uuid4())
            sess = session_manager.create_session(
                session_id=sid, name="API Chat", endpoint_url=endpoint_url,
                model=model, owner=token_owner,
            )
            if api_key:
                sess.headers = build_headers(api_key, base_url)
                session_manager.save_sessions()
            session_id = sid

        # --- Send message and get response ---
        sess.add_message(ChatMessage("user", message))

        messages = [{"role": m.role, "content": m.content} for m in sess.history]

View on GitHub (pinned to f9235ebbf1)

Solutions

  1. Pass an explicit model in the request body to skip auto-discovery entirely
  2. Verify the endpoint's api_key and base_url by hitting its /models endpoint manually (curl)
  3. Re-fetch/repair cached models in Admin so the cache path works
  4. Check server egress to the provider (DNS, proxy, firewall)

Example fix

// before
{"message":"hi"}  // model defaults to 'auto' on the fallback endpoint

// after
{"message":"hi","model":"deepseek-chat"}
Defensive patterns

Strategy: fallback

Validate before calling

# avoid auto-discovery: send an explicit model whenever you know it
body["model"] = body.get("model") or known_model_for(endpoint)

Try / catch

if resp.status_code == 500 and 'discover models' in detail:
    retry_with_explicit_model(default_model)

Prevention

When it happens

Trigger: Endpoint's model server unreachable or its cert invalid; /models returns 401/403 because the endpoint api_key is wrong; response is not valid JSON; cached_models holds corrupt JSON and models_url is None.

Common situations: Expired or rotated model-provider API keys; self-hosted servers without a /v1/models route; reverse proxies returning HTML error pages with 200; stale cached_models after a schema change.

Related errors


AI-assisted analysis of odysseus-dev/odysseus@f9235ebbf1 (2026-08-14). Data as JSON: /api/errors/591a3a2f35ee609d. Report an issue: GitHub.