{"record":{"id":"a3386820809edbd5","repo":"JuliusBrussee/caveman","slug":"caveman-agent-unknown-model-json-stringify-requ","errorCode":null,"errorMessage":"caveman agent: unknown model ${JSON.stringify(requested)}","messagePattern":"caveman agent: unknown model (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/agent/src/runtime.ts","lineNumber":3247,"sourceCode":"  // future OAuth-capable Google provider cannot be relabeled as metered.\n  if (provider === \"google\" && process.env.GOOGLE_API_KEY) return \"metered\";\n  return \"unknown\";\n}\n\nfunction resolveModel(definition: AgentDefinition, models: Models, rootDir: string): Model<Api> {\n  if (typeof definition.model === \"object\" && \"provider\" in definition.model) {\n    return definition.model;\n  }\n  const requested = typeof definition.model === \"string\"\n    ? definition.model\n    : process.env.CAVE_MODEL ?? localProviderModel(rootDir);\n  if (requested) {\n    const slash = requested.indexOf(\"/\");\n    if (slash <= 0 || slash === requested.length - 1) {\n      throw new Error(\"caveman agent: pinned model must use provider/model format\");\n    }\n    const model = models.getModel(requested.slice(0, slash), requested.slice(slash + 1));\n    if (!model) throw new Error(`caveman agent: unknown model ${JSON.stringify(requested)}`);\n    return model;\n  }\n\n  const configured: Array<[string, string]> = [];\n  if (process.env.ANTHROPIC_API_KEY) configured.push([\"anthropic\", \"claude-haiku-4-5\"]);\n  if (process.env.OPENAI_API_KEY) configured.push([\"openai\", \"gpt-5.4-mini\"]);\n  if (process.env.GEMINI_API_KEY || process.env.GOOGLE_API_KEY) configured.push([\"google\", \"gemini-2.5-flash\"]);\n  if (configured.length !== 1) {\n    throw new Error(\n      configured.length === 0\n        ? \"caveman agent: no supported provider credential found\"\n        : \"caveman agent: multiple provider credentials found; set CAVE_MODEL once\",\n    );\n  }\n  const [provider, id] = configured[0]!;\n  const model = models.getModel(provider, id);\n  if (!model) throw new Error(`caveman agent: baseline model unavailable: ${provider}/${id}`);\n  return model;","sourceCodeStart":3229,"sourceCodeEnd":3265,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/agent/src/runtime.ts#L3229-L3265","documentation":"After the `provider/model` format check, the runtime looks the model up via `models.getModel(provider, id)` and throws `caveman agent: unknown model <json>` when no registered model matches the pinned identifier. The pin came from `definition.model`, `CAVE_MODEL`, or `.caveman/provider.json`, and the provider/model pair is not in the model registry.","triggerScenarios":"`CAVE_MODEL=openai/gpt-9-turbo` (nonexistent id), a typo like `anthropic/claude-haiku-4.5` vs the registered id, or a provider slug the registry does not know (`gpt/4o`).","commonSituations":"Using a model name from provider marketing docs that differs from the registry id; upgrading the runtime where registry ids changed; hand-editing `provider.json` with an invented pair.","solutions":["Correct the model id to a registered one, e.g. `openai/gpt-5.4-mini` or `anthropic/claude-haiku-4-5` (as listed in the runtime's baseline defaults).","Run the package's `doctor` CLI to see which providers/models the runtime recognizes.","Unset `CAVE_MODEL` (and fix `provider.json`) to let the runtime pick a baseline model from available credentials.","Check for version drift: a model registered in a newer runtime may be unknown here — update the package."],"exampleFix":"// before\nCAVE_MODEL=anthropic/claude-3-haiku-20240307\n// after\nCAVE_MODEL=anthropic/claude-haiku-4-5","handlingStrategy":"validation","validationCode":"import { getModel } from \"@mariozechner/pi-ai\";\nconst [provider, id] = (process.env.CAVE_MODEL ?? \"\").split(\"/\");\nif (process.env.CAVE_MODEL && !getModel(provider, id)) throw new Error(`unknown model: ${process.env.CAVE_MODEL}`);","typeGuard":"null","tryCatchPattern":"try {\n  await agent.run(task);\n} catch (e) {\n  if ((e as Error).message.startsWith(\"caveman agent: unknown model\")) {\n    console.error(\"Fix CAVE_MODEL/provider.json to a registered model id\");\n  } else throw e;\n}","preventionTips":["Verify the exact registered id with `doctor` before pinning a model.","Prefer one of the runtime's documented defaults (anthropic/claude-haiku-4-5, openai/gpt-5.4-mini, google/gemini-2.5-flash).","After upgrading the package, re-check pinned ids against the new registry."],"tags":["config","model-selection","not-found"],"backgroundTag":"resource-not-found","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}