{"record":{"id":"ecfb5c72d7eb1c29","repo":"JuliusBrussee/caveman","slug":"caveman-code-multiple-provider-credentials-found","errorCode":null,"errorMessage":"caveman-code: multiple provider credentials found; set CAVE_MODEL to pick one","messagePattern":"caveman-code: multiple provider credentials found; set CAVE_MODEL to pick one","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/agent/src/code.ts","lineNumber":562,"sourceCode":"}\n\nfunction resolveCodingModelID(explicit: string | undefined): string {\n  const requested = explicit ?? process.env.CAVE_MODEL;\n  if (requested !== undefined && requested !== \"\") {\n    const slash = requested.indexOf(\"/\");\n    if (slash <= 0 || slash === requested.length - 1) {\n      throw new Error(\"caveman-code: model must use provider/model format\");\n    }\n    return requested;\n  }\n  const configured: string[] = [];\n  if (process.env.ANTHROPIC_API_KEY) configured.push(\"anthropic/claude-sonnet-4-6\");\n  if (process.env.OPENAI_API_KEY) configured.push(\"openai/gpt-5.5\");\n  if (process.env.GEMINI_API_KEY || process.env.GOOGLE_API_KEY) {\n    configured.push(\"google/gemini-2.5-pro\");\n  }\n  if (configured.length !== 1) {\n    throw new Error(\n      configured.length === 0\n        ? \"caveman-code: no supported provider credential found; set ANTHROPIC_API_KEY, OPENAI_API_KEY, or GEMINI_API_KEY\"\n        : \"caveman-code: multiple provider credentials found; set CAVE_MODEL to pick one\",\n    );\n  }\n  return configured[0]!;\n}\n\n// ---------------------------------------------------------------------------\n// Session\n// ---------------------------------------------------------------------------\n\nexport type SessionMode = \"optimized\" | \"observe-only\";\n\nexport interface CodingSessionOptions {\n  conversation?: ConversationState;\n  cave?: \"auto\" | \"off\";\n  gatewayURL?: string;","sourceCodeStart":544,"sourceCodeEnd":580,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/packages/agent/src/code.ts#L544-L580","documentation":"The credential-based default picks a provider only when the choice is unambiguous. If two or more of ANTHROPIC_API_KEY, OPENAI_API_KEY, GEMINI_API_KEY/GOOGLE_API_KEY are present, the agent refuses to guess which provider you meant and asks for an explicit CAVE_MODEL.","triggerScenarios":"Having e.g. both ANTHROPIC_API_KEY and OPENAI_API_KEY in the environment (common on dev machines with multiple provider CLIs installed) while CAVE_MODEL is unset.","commonSituations":"Developer shells with accumulative .envrc/.zshrc exports; CI templates that inject all available secrets 'just in case'; shared machines where different projects use different providers.","solutions":["Set CAVE_MODEL to the provider/model you want, e.g. `export CAVE_MODEL=anthropic/claude-sonnet-4-6`","Or unset the credentials you do not want used this run: `unset OPENAI_API_KEY GEMINI_API_KEY GOOGLE_API_KEY`","Scope secrets per-project (direnv, .env per repo) so only one provider's key is present"],"exampleFix":"# before: ambiguous\nexport ANTHROPIC_API_KEY=...\nexport OPENAI_API_KEY=...\n\n# after: disambiguate\nexport CAVE_MODEL=\"anthropic/claude-sonnet-4-6\"","handlingStrategy":"validation","validationCode":"const groups = [\n  [\"ANTHROPIC_API_KEY\"],\n  [\"OPENAI_API_KEY\"],\n  [\"GEMINI_API_KEY\", \"GOOGLE_API_KEY\"],\n] as const;\nconst active = groups.filter((g) => g.some((v) => process.env[v] && process.env[v] !== \"\"));\nif (active.length > 1 && !process.env.CAVE_MODEL) {\n  throw new Error(`ambiguous credentials (${active.length} providers); set CAVE_MODEL`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always set CAVE_MODEL in shared/CI environments where multiple provider keys coexist","Scope one provider's secrets per project via direnv or per-repo .env files"],"tags":["config","credentials","env","ambiguity"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}