{"record":{"id":"591a3a2f35ee609d","repo":"odysseus-dev/odysseus","slug":"could-not-discover-models-from-endpoint","errorCode":null,"errorMessage":"Could not discover models from endpoint","messagePattern":"Could not discover models from endpoint","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"routes/webhook/webhook_routes.py","lineNumber":361,"sourceCode":"                        hdrs = build_headers(api_key, base_url)\n                        if models_url:\n                            resp = await client.get(models_url, headers=hdrs)\n                            resp.raise_for_status()\n                            data = resp.json()\n                            items = data if isinstance(data, list) else (data.get(\"data\") or [])\n                            ids = [m.get(\"id\") for m in items if isinstance(m, dict) and m.get(\"id\")]\n                            if not ids and isinstance(data, dict):\n                                ids = [\n                                    m.get(\"name\") or m.get(\"model\")\n                                    for m in (data.get(\"models\") or [])\n                                    if m.get(\"name\") or m.get(\"model\")\n                                ]\n                        else:\n                            import json as _json\n                            ids = _json.loads(ep.cached_models or \"[]\")\n                        model = ids[0] if ids else \"auto\"\n                except Exception:\n                    raise HTTPException(500, \"Could not discover models from endpoint\")\n\n            if not session_manager:\n                raise HTTPException(500, \"Session manager not available\")\n\n            sid = str(uuid.uuid4())\n            sess = session_manager.create_session(\n                session_id=sid, name=\"API Chat\", endpoint_url=endpoint_url,\n                model=model, owner=token_owner,\n            )\n            if api_key:\n                sess.headers = build_headers(api_key, base_url)\n                session_manager.save_sessions()\n            session_id = sid\n\n        # --- Send message and get response ---\n        sess.add_message(ChatMessage(\"user\", message))\n\n        messages = [{\"role\": m.role, \"content\": m.content} for m in sess.history]","sourceCodeStart":343,"sourceCodeEnd":379,"githubUrl":"https://github.com/odysseus-dev/odysseus/blob/f9235ebbf13f693a6fd29ce70b097f6ec83705bf/routes/webhook/webhook_routes.py#L343-L379","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass an explicit model in the request body to skip auto-discovery entirely","Verify the endpoint's api_key and base_url by hitting its /models endpoint manually (curl)","Re-fetch/repair cached models in Admin so the cache path works","Check server egress to the provider (DNS, proxy, firewall)"],"exampleFix":"// before\n{\"message\":\"hi\"}  // model defaults to 'auto' on the fallback endpoint\n\n// after\n{\"message\":\"hi\",\"model\":\"deepseek-chat\"}","handlingStrategy":"fallback","validationCode":"# avoid auto-discovery: send an explicit model whenever you know it\nbody[\"model\"] = body.get(\"model\") or known_model_for(endpoint)","typeGuard":null,"tryCatchPattern":"if resp.status_code == 500 and 'discover models' in detail:\n    retry_with_explicit_model(default_model)","preventionTips":["Pass an explicit model instead of relying on 'auto'","Verify endpoint api_key/base_url by curl-ing its /models route after any key rotation","Keep ep.cached_models fresh in Admin"],"tags":["model-discovery","endpoint","http-500","chat"],"backgroundTag":null,"analyzedSha":"f9235ebbf13f693a6fd29ce70b097f6ec83705bf","analyzedAt":"2026-08-14T21:47:48.359Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}