JuliusBrussee/caveman · error · Error
openclaw fresh config cannot route through Caveman without
Error message
openclaw fresh config cannot route through Caveman without ${requiredKey} What it means
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.
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
Example fix
// before $ caveman openclaw init --mode managed # no CAVE_API_KEY // after $ export CAVE_API_KEY=cv-... $ caveman openclaw init --mode managed
Defensive patterns
Strategy: validation
Validate before calling
const requiredKey = mode === 'managed' ? 'CAVE_API_KEY' : 'OPENAI_API_KEY';
if (!process.env[requiredKey]) {
throw new Error(`set ${requiredKey} before generating an openclaw fresh config (mode=${mode})`);
} Type guard
function hasApiKey(env: NodeJS.ProcessEnv, key: string): env is NodeJS.ProcessEnv & Record<typeof key, string> {
return typeof env[key] === 'string' && env[key].length > 0;
} Try / catch
try {
cli.openclawInit({ mode });
} catch (err) {
if ((err as Error).message.includes('cannot route through Caveman without')) {
const key = (err as Error).message.match(/without (\w+)/)?.[1];
console.error(`Export ${key} (and ensure it is non-empty) before running openclaw init.`);
} else throw err;
} Prevention
- 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
When it happens
Trigger: 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]).
Common situations: 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.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- cannot safely resolve Qwen's effective OPENAI_API_KEY
- bedrock Mantle endpoint is not enabled
- cannot preserve opencode inline configuration; launching…
- CAVEMAN_AUTH_TOKEN must be at least
- CAVEMAN_AUTH_TOKEN must contain no spaces or control…
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/5b31b82bd079a6b0.
Report an issue: GitHub.
Appendix: source
Thrown at packages/cli/src/index.ts:6156
}
function openClawDefaultApiKey(providerId: string): string | undefined {
return openClawSecretString(OPENCLAW_WELL_KNOWN_PROVIDERS[providerId]?.apiKey);
}
function openClawProviderApiKey(providerId: string, provider: JsonObject): string | undefined {
return openClawSecretString(provider.apiKey) ?? openClawDefaultApiKey(providerId);
}
function openClawResolvedProviderApiKey(providerId: string, provider: JsonObject): string | undefined {
const key = openClawProviderApiKey(providerId, provider);
return key ? resolveEnvTemplate(key) : undefined;
}
function freshOpenClawModelRef(ctx: OverlayBuilderContext): OpenClawModelRef {
const requiredKey = ctx.mode === "managed" ? "CAVE_API_KEY" : "OPENAI_API_KEY";
if (!firstEnvSecret(ctx.env, [requiredKey])) {
throw new Error(`openclaw fresh config cannot route through Caveman without ${requiredKey}`);
}
return { provider: "openai", model: OPENCLAW_FRESH_MODEL, raw: `openai/${OPENCLAW_FRESH_MODEL}` };
}
function appendUrlPath(base: string, path: string): string {
return `${base.replace(/\/+$/, "")}${path}`;
}
export function claudeConfigDir(env: NodeJS.ProcessEnv = process.env): string {
return env.CLAUDE_CONFIG_DIR ? resolve(env.CLAUDE_CONFIG_DIR) : join(homedir(), ".claude");
}
export function claudeGlobalConfigPath(env: NodeJS.ProcessEnv = process.env): string {
// Claude keeps its default global/MCP config beside ~/.claude, but moves
// that file inside a nonempty CLAUDE_CONFIG_DIR override.
return env.CLAUDE_CONFIG_DIR ? join(claudeConfigDir(env), ".claude.json") : join(homedir(), ".claude.json");
}
View on GitHub (pinned to 3ee70a1026)