can1357/oh-my-pi · error · Error
No API key for ${model.provider}/${model.id}
Error message
No API key for ${model.provider}/${model.id} What it means
ModelControls.setModel refuses to switch the session's model when the model registry has no configured authentication for the target model (hasConfiguredAuth(model) is false). This guards the persistent model switch so a turn never starts against a provider the user cannot authenticate to. The message names the provider/model that lacks a key.
Source
Thrown at packages/coding-agent/src/session/model-controls.ts:226
if (!resolved.explicitThinkingLevel || resolved.thinkingLevel === undefined || !resolved.model) continue;
if (modelsAreEqual(resolved.model, model)) return resolved.thinkingLevel;
}
return undefined;
}
async setModel(
model: Model,
role: string = "default",
options?: {
selector?: string;
thinkingLevel?: ThinkingLevel;
persist?: boolean;
},
): Promise<{ switched: boolean }> {
const previousEditMode = this.#host.resolveActiveEditMode();
if (!this.#host.modelRegistry.hasConfiguredAuth(model)) {
throw new Error(`No API key for ${model.provider}/${model.id}`);
}
const targetModel = await this.#host.modelRegistry.refreshSelectedModelMetadata(model);
this.#host.modelRegistry.clearSuppressedSelector(formatModelStringWithRouting(targetModel));
this.#host.clearActiveRetryFallback();
await this.#host.setModelWithProviderSessionReset(targetModel);
this.#host.sessionManager.appendModelChange(`${targetModel.provider}/${targetModel.id}`, role);
if (options?.persist) {
this.#host.settings.setModelRole(
role,
formatRoleModelValue(
this.#host.settings,
this.#host.modelRegistry,
role,
targetModel,
options.selector,
options.thinkingLevel,View on GitHub (pinned to 9690622007)
Solutions
- Configure auth for the target provider (set its API key env var or add credentials via `omp` auth/config) before switching
- Pick a different model on a provider that already has configured auth
- Check hasConfiguredAuth(model) on the registry before calling setModel
- If auth should exist, verify the correct provider profile/config file is loaded and the key is present in the environment
Example fix
// before
await controls.setModel({ model: anthropicModel }); // throws if no key
// after
if (host.modelRegistry.hasConfiguredAuth(anthropicModel)) {
await controls.setModel({ model: anthropicModel });
} else {
await controls.setModel({ model: fallbackModel });
} Defensive patterns
Strategy: validation
Validate before calling
if (!session.modelRegistry.hasConfiguredAuth(model)) {
console.warn(`Skipping ${model.provider}/${model.id}: no API key configured`);
return;
}
await controls.setModel({ model }); Try / catch
try {
await controls.setModel({ model });
} catch (err) {
if (err instanceof Error && err.message.startsWith("No API key for")) {
// prompt user to configure provider auth or pick another model
} else throw err;
} Prevention
- Configure all providers you plan to switch to before the session starts
- Filter model pickers/lists with hasConfiguredAuth
- Validate keys exist in env/config during startup
- Centralize model selection behind an auth-checked helper
When it happens
Trigger: Calling setModel({ model, ... }) (directly or via applyRoleModel) with a Model whose provider has no API key / auth configured in the registry.
Common situations: Selecting a model from a provider that was never configured (no env var like ANTHROPIC_API_KEY, no models.json auth entry, no logged-in provider); switching roles to a model on an unconfigured provider; key was removed or expired from config before the switch.
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 ${resolved.model.provider}/${resolved.model.i
- No API key for ${nextModel.provider}/${nextModel.id}
- Devin auth error ${response.status} ${response.statusText}:
- gitlab-duo-agent
- ${providerLabel} login requires onPrompt callback
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/2ea1487c18200309.
Report an issue: GitHub.