mastra-ai/mastra · error · HTTPException
Model config with id ${modelConfigId} not found
Error message
Model config with id ${modelConfigId} not found What it means
Thrown (HTTP 404) when `modelConfigId` in the request does not match any id in the agent's non-empty model list — `modelList.find(config => config.id === modelConfigId)` returns undefined.
Source
Thrown at packages/server/src/server/handlers/agents.ts:3395
pathParamSchema: modelConfigIdPathParams,
bodySchema: updateAgentModelInModelListBodySchema,
responseSchema: modelManagementResponseSchema,
summary: 'Update model in model list',
description: 'Updates a specific model configuration in the agent model list',
tags: ['Agents', 'Models'],
requiresAuth: true,
handler: async ({ mastra, agentId, modelConfigId, model: bodyModel, maxRetries, enabled }) => {
try {
const agent = await getAgentFromSystem({ mastra, agentId });
const modelList = await agent.getModelList();
if (!modelList || modelList.length === 0) {
throw new HTTPException(400, { message: 'Agent model list is not found or empty' });
}
const modelConfig = modelList.find(config => config.id === modelConfigId);
if (!modelConfig) {
throw new HTTPException(404, { message: `Model config with id ${modelConfigId} not found` });
}
const newModel =
bodyModel?.modelId && bodyModel?.provider ? `${bodyModel.provider}/${bodyModel.modelId}` : modelConfig.model;
const updated = {
...modelConfig,
model: newModel,
...(maxRetries !== undefined ? { maxRetries } : {}),
...(enabled !== undefined ? { enabled } : {}),
};
agent.updateModelInModelList(updated);
return { message: 'Model updated in model list' };
} catch (error) {
return handleError(error, 'error updating model in model list');
}View on GitHub (pinned to 75dd419e61)
Solutions
- Re-fetch the agent's model list and use a current `modelConfigId` from it.
- Verify you are targeting the correct agentId — config ids are per-agent.
- If the config was deleted, recreate it before updating.
- Clear cached model lists in your UI after mutations so ids stay fresh.
Example fix
// before
await client.getAgent('agent-x').updateModel({ modelConfigId: 'stale-id', maxRetries: 3 });
// after
const list = await client.getAgent('agent-x').getModels();
await client.getAgent('agent-x').updateModel({ modelConfigId: list[0].id, maxRetries: 3 }); Defensive patterns
Strategy: validation
Validate before calling
const models = await client.getAgent(agentId).getModels();
if (!models?.some(m => m.id === modelConfigId)) throw new Error(`modelConfigId ${modelConfigId} not found on agent ${agentId}; refresh the model list`); Type guard
function hasModelConfig(models: Array<{ id: string }> | null, id: string): models is Array<{ id: string }> & { find(c: { id: string }): { id: string } } { return !!models && models.some(c => c.id === id); } Try / catch
try { await client.getAgent(agentId).updateModel({ modelConfigId, ...patch }); } catch (e) { if (is404(e) && /Model config with id/.test(e.message)) { const fresh = await client.getAgent(agentId).getModels(); /* retry with fresh id */ } else throw e; } Prevention
- Always source modelConfigId from a fresh GET of the model list, never from stale caches.
- Invalidate model-list caches after any create/delete mutation.
- Scope config ids per agent; never reuse ids across agents.
- Detect 404s on model configs and auto-refresh the list before surfacing errors to users.
When it happens
Trigger: Updating a model config using an id that does not exist: stale id from a deleted config, typo in the id, or ids regenerated after an agent re-save.
Common situations: Frontend holding a cached model list after another client deleted/recreated configs; switching agents but reusing a config id from a different agent; ids changed after server/storage migration.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- Model "${modelId}" is not available. Available models: ${ids
- ClaudeSDKAgent resumeData must include either sessionId or c
- ACP connection is not initialized
- Model "${this.options.model}" is not available. Available mo
- ClaudeSDKAgent resumeData.sessionId must be a string.
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/b505e552a4f87867.
Report an issue: GitHub.