{"record":{"id":"30bbab52d05db7fd","repo":"JuliusBrussee/caveman","slug":"caveman-agent-multiple-provider-credentials-found","errorCode":null,"errorMessage":"caveman agent: multiple provider credentials found; set CAVE_MODEL once","messagePattern":"caveman agent: multiple provider credentials found; set CAVE_MODEL once","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/agent/src/runtime.ts","lineNumber":3259,"sourceCode":"  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;\n}\n\nfunction localProviderModel(rootDir: string): string | undefined {\n  try {\n    const parsed = JSON.parse(readFileSync(resolve(rootDir, \".caveman/provider.json\"), \"utf8\")) as { model?: unknown };\n    return typeof parsed.model === \"string\" ? parsed.model : undefined;\n  } catch (error) {\n    if ((error as NodeJS.ErrnoException).code === \"ENOENT\") return undefined;\n    throw new Error(\"caveman agent: invalid .caveman/provider.json\");\n  }\n}\n","sourceCodeStart":3241,"sourceCodeEnd":3277,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/766dce6b1394ebb56a3090748d5a0240a5aefb36/packages/agent/src/runtime.ts#L3241-L3277","documentation":"The unpinned-model auto-detect requires exactly one provider credential so the provider choice is unambiguous. This error is thrown when more than one of ANTHROPIC_API_KEY / OPENAI_API_KEY / GEMINI_API_KEY|GOOGLE_API_KEY is set: the runtime refuses to guess between them and asks for an explicit pin via CAVE_MODEL.","triggerScenarios":"A workstation with both Anthropic and OpenAI keys exported (or any two of the three provider families) runs an agent with no CAVE_MODEL, no definition.model, and no model in .caveman/provider.json, so configured.length becomes 2 or 3.","commonSituations":"Dotfiles that export keys for several AI CLIs; CI jobs inheriting a broad secret group; adding a new provider's key without removing the old one; GOOGLE_API_KEY and OPENAI_API_KEY both set on a dev machine.","solutions":["Set CAVE_MODEL=provider/model once to make the choice explicit","Or pass definition.model or a model in .caveman/provider.json, which skips auto-detection entirely","Or unset all but one provider credential in that shell/session"],"exampleFix":"# before\nexport ANTHROPIC_API_KEY=sk-ant-...\nexport OPENAI_API_KEY=sk-...\n\n# after\nexport ANTHROPIC_API_KEY=sk-ant-...\nexport OPENAI_API_KEY=sk-...\nexport CAVE_MODEL=anthropic/claude-haiku-4-5","handlingStrategy":"validation","validationCode":"const families = new Set(\n  [\"ANTHROPIC_API_KEY\", \"OPENAI_API_KEY\", \"GEMINI_API_KEY\", \"GOOGLE_API_KEY\"]\n    .filter((k) => process.env[k] !== undefined)\n    .map((k) => k.split(\"_\")[0].toLowerCase()),\n);\nif (families.size > 1 && process.env.CAVE_MODEL === undefined) {\n  process.env.CAVE_MODEL = \"anthropic/claude-haiku-4-5\"; // choose explicitly\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set CAVE_MODEL in any environment that legitimately holds multiple provider keys","Scope CI secret groups so jobs only receive the one provider they need","Document for teammates that adding a second key requires an explicit pin"],"tags":["credentials","environment","configuration"],"backgroundTag":"ambiguous-provider-selection","analyzedSha":"766dce6b1394ebb56a3090748d5a0240a5aefb36","analyzedAt":"2026-08-18T03:14:35.516Z","contentChangedAt":"2026-08-18T03:14:35.516Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}