lfnovo/open-notebook · error · HTTPException
Error getting model count: {str(e)}
Error message
Error getting model count: {str(e)} What it means
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.
Source
Thrown at api/routers/models.py:664
Returns counts for each model type (language, embedding,
speech_to_text, text_to_speech) as well as total count.
"""
try:
counts = await get_provider_model_count(provider)
total = sum(counts.values())
return ProviderModelCountResponse(
provider=provider,
counts=counts,
total=total,
)
except HTTPException:
raise
except OpenNotebookError:
raise
except Exception as e:
logger.error(f"Error getting model count for {provider}: {str(e)}")
raise HTTPException(
status_code=500, detail=f"Error getting model count: {str(e)}"
)
@router.get("/models/by-provider/{provider}", response_model=List[ModelResponse])
async def get_models_by_provider(provider: str):
"""
Get all registered models for a specific provider.
Returns models from the database that belong to the specified provider.
"""
try:
from open_notebook.database.repository import repo_query
models = await repo_query(
"SELECT * FROM model WHERE provider = $provider ORDER BY type, name",
{"provider": provider},
)View on GitHub (pinned to a7de90d38a)
Solutions
- Check API logs for 'Error getting model count for {provider}'
- Verify DB connectivity
- Retry after the DB is healthy
Defensive patterns
Strategy: retry
Validate before calling
await fetch('/api/v1/health').then(r => { if (!r.ok) throw new Error('API unhealthy'); }); Try / catch
try { return await api.getModelCount(provider); } catch (e) { if (e.status === 500) return null; } Prevention
- Treat count failures as transient
- Health-check before dashboard loads
- Show '—' instead of erroring the whole UI
When it happens
Trigger: GET /models/count/{provider} while SurrealDB is unreachable or the query raises a non-domain error.
Common situations: DB outage or restart; provider string containing characters that break the query.
Related errors
- Error fetching models: {str(e)}
- Error creating model: {str(e)}
- Error deleting model: {str(e)}
- Error fetching default models: {str(e)}
- Error updating default models: {str(e)}
AI-assisted analysis of lfnovo/open-notebook@a7de90d38a (2026-08-27).
Data as JSON: /api/errors/98729fe6d5183d6e.
Report an issue: GitHub.