{"record":{"id":"8dfd917c6b4f8031","repo":"HeyPuter/puter","slug":"bad-request-8dfd91","errorCode":"bad_request","errorMessage":"Model not found: ${args.model}","messagePattern":"Model not found: (.+?)","errorType":"exception","errorClass":"HttpError","httpStatus":400,"severity":"error","filePath":"src/backend/drivers/ai-chat/ChatCompletionDriver.ts","lineNumber":325,"sourceCode":"            throw new HttpError(401, 'Authentication required', {\n                legacyCode: 'unauthorized',\n            });\n\n        let intendedProvider = args.provider || '';\n        if (!args.model && !intendedProvider) {\n            intendedProvider = 'azure-openai'; // default provider\n        }\n        if (\n            !args.model &&\n            intendedProvider &&\n            this.#providers[intendedProvider]\n        ) {\n            args.model = this.#providers[intendedProvider].getDefaultModel();\n        }\n\n        let model = this.#resolveModel(args.model, intendedProvider);\n        if (!model) {\n            throw new HttpError(400, `Model not found: ${args.model}`, {\n                legacyCode: 'bad_request',\n            });\n        }\n\n        if (args.messages) {\n            args.messages = normalize_messages(args.messages);\n        }\n        if (args.tools) {\n            normalize_tools_object(args.tools);\n        }\n\n        const completionId = crypto\n            .randomUUID()\n            .replaceAll('-', '')\n            .slice(0, 25);\n\n        const validateEvent: EventMap['ai.prompt.validate'] = {\n            username: actor.user?.username || '',","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/HeyPuter/puter/blob/908ec23eda38526170322c3edf71ba45ecb1ca95/src/backend/drivers/ai-chat/ChatCompletionDriver.ts#L307-L343","documentation":"Raised by the AI chat `complete()` driver when `_resolveModel(args.model, intendedProvider)` returns null — the requested model name is not registered/available on this backend for the given provider. A `provider` with no matching model, a typo, or a model not configured/disabled all land here.","triggerScenarios":"Calling AI completion with a model name that isn't configured; specifying a provider whose model list doesn't include the name; a typo in the model string; the provider isn't registered at all so no default model resolves.","commonSituations":"Typo in the model name; self-hosted instance without that provider's models enabled; a model deprecated/removed in an upgrade; provider name mismatch.","solutions":["Use a model from the configured list — enumerate available models via the models endpoint first.","Configure the provider and its models on the backend (config/drivers).","Check the spelling of both model and provider; ensure the provider is registered.","If you omit the model, confirm the provider has a default model set."],"exampleFix":"// before\nputer.ai.chat('hi', { model: 'gpt-4-turbo-typo' });\n// after — use a valid configured model\nputer.ai.chat('hi', { model: 'gpt-4o' });","handlingStrategy":"validation","validationCode":"// Validate the model against the available list before calling:\nconst allowed = await listModels();\nif (!allowed.includes(args.model)) { throw new Error(`Model not available: ${args.model}`); }","typeGuard":null,"tryCatchPattern":"try { await aiChat({ model }); }\ncatch (e) {\n  if (e.code === 'bad_request' && /Model not found/.test(e.message)) { model = await pickDefaultModel(); return aiChat({ model }); }\n  throw e;\n}","preventionTips":["Enumerate configured models first and pick from that list.","Double-check spelling of model and provider names.","On self-host, ensure the provider and its models are configured."],"tags":["ai","model","validation","bad-request"],"backgroundTag":null,"analyzedSha":"908ec23eda38526170322c3edf71ba45ecb1ca95","analyzedAt":"2026-08-12T20:53:15.911Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}