can1357/oh-my-pi · error · ToolError
completion() has no API key for ${formatModelString(model)}.
Error message
completion() has no API key for ${formatModelString(model)}. Configure credentials for this provider or choose another tier. What it means
After resolving a model for the requested tier, the bridge fetches its API key through the session's model registry (`registry.getApiKey(model)`). This ToolError is thrown when there is no model registry on the session or the resolver returns no key, meaning credentials for the resolved provider are missing. It guards the actual `completeSimple` request from failing with an opaque provider auth error.
Source
Thrown at packages/coding-agent/src/eval/completion-bridge.ts:129
const parsed = completionArgsSchema(args);
if (parsed instanceof type.errors) {
throw new ToolError(`completion() received invalid arguments: ${parsed.summary}`);
}
const { prompt, model: modelTier, system, schema } = parsed;
// Apply default value for model if not provided
const finalTier: CompletionTier = modelTier ?? "default";
const model = resolveTierModel(finalTier, options.session);
if (!model) {
throw new ToolError(
`completion() could not resolve a model for the "${finalTier}" tier. Configure modelRoles.${finalTier === "default" ? "default" : finalTier} or ensure a provider is available.`,
);
}
const registry = options.session.modelRegistry;
const apiKey = await registry?.getApiKey(model);
if (!registry || !apiKey) {
throw new ToolError(
`completion() has no API key for ${formatModelString(model)}. Configure credentials for this provider or choose another tier.`,
);
}
const tools: Tool[] | undefined = schema
? [
{
name: STRUCTURED_TOOL_NAME,
description: "Return your answer by calling this tool with the requested structured fields.",
parameters: schema,
strict: false,
},
]
: undefined;
const telemetry = resolveTelemetry(options.session.getTelemetry?.(), options.session.getSessionId?.() ?? undefined);
// Some providers (notably openai-codex) require a non-empty `instructions`View on GitHub (pinned to 9690622007)
Solutions
- Configure credentials for the resolved provider (API key env var, auth config, or provider login) and retry.
- Choose a different tier whose provider you do have credentials for (`completion(prompt, { model: "smol" })`).
- Verify the env var the provider expects (e.g. ANTHROPIC_API_KEY / OPENAI_API_KEY) is present in the process running the eval.
- If embedding the bridge in your own session, ensure `session.modelRegistry` is set with a working key resolver.
Example fix
// before
export ANTHROPIC_API_KEY= # unset
const out = await completion("classify this");
// after
export ANTHROPIC_API_KEY=sk-ant-...
const out = await completion("classify this"); Defensive patterns
Strategy: validation
Validate before calling
const registry = session.modelRegistry;
const model = /* resolve tier model as in the bridge */;
const apiKey = model && registry ? await registry.getApiKey(model) : undefined;
if (!registry || !apiKey) throw new Error(`No API key for ${model?.id ?? "resolved model"}`); Try / catch
try {
const out = await completion(prompt);
} catch (e) {
if (String(e).includes("no API key")) {
// guide user to set provider credentials or switch tier
} else throw e;
} Prevention
- Set the provider API key env vars in the environment running evals (including CI secrets).
- Point tiers at providers you actually have credentials for.
- Smoke-test one completion() call at eval startup to fail fast on missing credentials.
When it happens
Trigger: `completion(prompt, ...)` resolves a valid model (e.g. `anthropic/claude-...`) but `session.modelRegistry` is absent, or `getApiKey(model)` returns undefined because no API key/env var/OAuth credential is configured for that provider.
Common situations: Anthropic or OpenAI key not set in env or auth config; key configured for one provider but the tier's role points at another; running evals in a container where the credential file/env isn't mounted; model registry not attached to the eval ToolSession.
Understand the failure class
Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.
Related errors
- No API key for ${model.provider}/${model.id}
- No API key available for model ${model.provider}/${model.id}
- Provider ${providerName}: "apiKey" or "oauth" is required wh
- No API key for retry fallback ${selector.raw}
- No API key available for ${model.provider}/${model.id}. Conf
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/ac632fb158a425d0.
Report an issue: GitHub.