{"record":{"id":"98729fe6d5183d6e","repo":"lfnovo/open-notebook","slug":"error-getting-model-count-str-e","errorCode":null,"errorMessage":"Error getting model count: {str(e)}","messagePattern":"Error getting model count: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"api/routers/models.py","lineNumber":664,"sourceCode":"\n    Returns counts for each model type (language, embedding,\n    speech_to_text, text_to_speech) as well as total count.\n    \"\"\"\n    try:\n        counts = await get_provider_model_count(provider)\n        total = sum(counts.values())\n        return ProviderModelCountResponse(\n            provider=provider,\n            counts=counts,\n            total=total,\n        )\n    except HTTPException:\n        raise\n    except OpenNotebookError:\n        raise\n    except Exception as e:\n        logger.error(f\"Error getting model count for {provider}: {str(e)}\")\n        raise HTTPException(\n            status_code=500, detail=f\"Error getting model count: {str(e)}\"\n        )\n\n\n@router.get(\"/models/by-provider/{provider}\", response_model=List[ModelResponse])\nasync def get_models_by_provider(provider: str):\n    \"\"\"\n    Get all registered models for a specific provider.\n\n    Returns models from the database that belong to the specified provider.\n    \"\"\"\n    try:\n        from open_notebook.database.repository import repo_query\n\n        models = await repo_query(\n            \"SELECT * FROM model WHERE provider = $provider ORDER BY type, name\",\n            {\"provider\": provider},\n        )","sourceCodeStart":646,"sourceCodeEnd":682,"githubUrl":"https://github.com/lfnovo/open-notebook/blob/a7de90d38aaf18ee85fd661854d35c11e44613e2/api/routers/models.py#L646-L682","documentation":"Generic 500 from GET /api/v1/models/count/{provider} when counting the provider's models fails unexpectedly — almost always a database query failure, since counting is a single repo query.","triggerScenarios":"GET /models/count/{provider} while SurrealDB is unreachable or the query raises a non-domain error.","commonSituations":"DB outage or restart; provider string containing characters that break the query.","solutions":["Check API logs for 'Error getting model count for {provider}'","Verify DB connectivity","Retry after the DB is healthy"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"await fetch('/api/v1/health').then(r => { if (!r.ok) throw new Error('API unhealthy'); });","typeGuard":null,"tryCatchPattern":"try { return await api.getModelCount(provider); } catch (e) { if (e.status === 500) return null; }","preventionTips":["Treat count failures as transient","Health-check before dashboard loads","Show '—' instead of erroring the whole UI"],"tags":["models","count","http-500"],"backgroundTag":"internal-server-error","analyzedSha":"a7de90d38aaf18ee85fd661854d35c11e44613e2","analyzedAt":"2026-08-27T02:39:58.166Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}