{"record":{"id":"5b31b82bd079a6b0","repo":"JuliusBrussee/caveman","slug":"openclaw-fresh-config-cannot-route-through-caveman","errorCode":null,"errorMessage":"openclaw fresh config cannot route through Caveman without ${requiredKey}","messagePattern":"openclaw fresh config cannot route through Caveman without (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":6156,"sourceCode":"}\n\nfunction openClawDefaultApiKey(providerId: string): string | undefined {\n  return openClawSecretString(OPENCLAW_WELL_KNOWN_PROVIDERS[providerId]?.apiKey);\n}\n\nfunction openClawProviderApiKey(providerId: string, provider: JsonObject): string | undefined {\n  return openClawSecretString(provider.apiKey) ?? openClawDefaultApiKey(providerId);\n}\n\nfunction openClawResolvedProviderApiKey(providerId: string, provider: JsonObject): string | undefined {\n  const key = openClawProviderApiKey(providerId, provider);\n  return key ? resolveEnvTemplate(key) : undefined;\n}\n\nfunction freshOpenClawModelRef(ctx: OverlayBuilderContext): OpenClawModelRef {\n  const requiredKey = ctx.mode === \"managed\" ? \"CAVE_API_KEY\" : \"OPENAI_API_KEY\";\n  if (!firstEnvSecret(ctx.env, [requiredKey])) {\n    throw new Error(`openclaw fresh config cannot route through Caveman without ${requiredKey}`);\n  }\n  return { provider: \"openai\", model: OPENCLAW_FRESH_MODEL, raw: `openai/${OPENCLAW_FRESH_MODEL}` };\n}\n\nfunction appendUrlPath(base: string, path: string): string {\n  return `${base.replace(/\\/+$/, \"\")}${path}`;\n}\n\nexport function claudeConfigDir(env: NodeJS.ProcessEnv = process.env): string {\n  return env.CLAUDE_CONFIG_DIR ? resolve(env.CLAUDE_CONFIG_DIR) : join(homedir(), \".claude\");\n}\n\nexport function claudeGlobalConfigPath(env: NodeJS.ProcessEnv = process.env): string {\n  // Claude keeps its default global/MCP config beside ~/.claude, but moves\n  // that file inside a nonempty CLAUDE_CONFIG_DIR override.\n  return env.CLAUDE_CONFIG_DIR ? join(claudeConfigDir(env), \".claude.json\") : join(homedir(), \".claude.json\");\n}\n","sourceCodeStart":6138,"sourceCodeEnd":6174,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L6138-L6174","documentation":"When generating a fresh openclaw config that routes through Caveman, the model reference requires an API key. In managed mode that key must be CAVE_API_KEY; otherwise OPENAI_API_KEY. If the required key is absent (or empty) from the environment, config generation aborts rather than producing a config that cannot authenticate.","triggerScenarios":"freshOpenClawModelRef(ctx) is called during openclaw fresh-config generation with ctx.mode === \"managed\" and no CAVE_API_KEY in the environment, or with any other mode and no OPENAI_API_KEY — checked via firstEnvSecret(ctx.env, [requiredKey]).","commonSituations":"Switching between managed and direct modes without exporting the corresponding key; CI environments where secrets are injected only for one mode; a renamed env var after a CLI update (e.g. key moved from OPENAI_API_KEY to CAVE_API_KEY); key exported in a shell profile that the wrapper doesn't source.","solutions":["Export the key the mode requires: CAVE_API_KEY for managed mode, OPENAI_API_KEY otherwise","Make sure the key is exported (not just set) and visible in the process running the CLI: `env | grep API_KEY`","Run in the mode matching the key you actually have, or pass the mode explicitly","Add the key to your CI secret store / shell profile so fresh-config generation finds it","Verify the key value is non-empty — an empty string still fails firstEnvSecret"],"exampleFix":"// before\n$ caveman openclaw init --mode managed   # no CAVE_API_KEY\n// after\n$ export CAVE_API_KEY=cv-...\n$ caveman openclaw init --mode managed","handlingStrategy":"validation","validationCode":"const requiredKey = mode === 'managed' ? 'CAVE_API_KEY' : 'OPENAI_API_KEY';\nif (!process.env[requiredKey]) {\n  throw new Error(`set ${requiredKey} before generating an openclaw fresh config (mode=${mode})`);\n}","typeGuard":"function hasApiKey(env: NodeJS.ProcessEnv, key: string): env is NodeJS.ProcessEnv & Record<typeof key, string> {\n  return typeof env[key] === 'string' && env[key].length > 0;\n}","tryCatchPattern":"try {\n  cli.openclawInit({ mode });\n} catch (err) {\n  if ((err as Error).message.includes('cannot route through Caveman without')) {\n    const key = (err as Error).message.match(/without (\\w+)/)?.[1];\n    console.error(`Export ${key} (and ensure it is non-empty) before running openclaw init.`);\n  } else throw err;\n}","preventionTips":["Match the exported key to the mode: CAVE_API_KEY for managed, OPENAI_API_KEY otherwise","Export keys (not just set them) so child processes see them","Inject secrets into CI before config-generation steps","Check env | grep API_KEY in the exact shell running the CLI"],"tags":["env-var","api-key","openclaw","config-generation"],"backgroundTag":"missing-env-var","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"}