can1357/oh-my-pi · error

No API key available for model ${model.provider}/${model.id}

Error message

No API key available for model ${model.provider}/${model.id}

What it means

resolvePrimaryModel picks the model used to generate commit messages. After resolving a model it calls modelRegistry.getApiKey(model); if that returns undefined it throws because the commit pipeline cannot authenticate API calls without a credential. This fail-fast guard ensures the commit command never starts a model request it cannot complete.

Source

Thrown at packages/coding-agent/src/commit/model-selection.ts:53

	};

export async function resolvePrimaryModel(
	override: string | undefined,
	settings: Settings,
	modelRegistry: CommitModelRegistry,
): Promise<ResolvedCommitModel> {
	const available = modelRegistry.getAvailable();
	const matchPreferences = getModelMatchPreferences(settings);
	const resolved = override
		? resolveModelRoleValue(override, available, { settings, matchPreferences })
		: resolveRoleSelection(["commit", "smol", ...MODEL_ROLE_IDS], settings, available);
	const model = resolved?.model;
	if (!model) {
		throw new Error("No model available for commit generation");
	}
	const apiKey = await modelRegistry.getApiKey(model);
	if (!apiKey) {
		throw new Error(`No API key available for model ${model.provider}/${model.id}`);
	}
	return {
		model,
		apiKey: modelRegistry.resolver(model),
		thinkingLevel: concreteThinkingLevel(resolved?.thinkingLevel),
	};
}

export async function resolveSmolModel(
	settings: Settings,
	modelRegistry: CommitModelRegistry,
	fallbackModel: Model<Api>,
	fallbackApiKey: ApiKey,
): Promise<ResolvedCommitModel> {
	const available = modelRegistry.getAvailable();
	const resolvedSmol = resolveRoleSelection(["smol"], settings, available);
	if (resolvedSmol?.model) {
		const apiKey = await modelRegistry.getApiKey(resolvedSmol.model);

View on GitHub (pinned to 9690622007)

Solutions

  1. Authenticate with the provider of the resolved model (set the provider's API key env var or run the CLI's auth/login flow).
  2. Verify the env var name for the provider is correct and exported in the shell/CI environment (echo $ANTHROPIC_API_KEY etc.).
  3. Select a different model/provider that does have a configured key (model config or --model flag).
  4. If using a custom modelRegistry, fix getApiKey to resolve keys for that provider.

Example fix

// before (CI): commit generation fails
# no key in environment
// after
export ANTHROPIC_API_KEY=sk-ant-...
# or in CI secrets config:
env:
  ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
Defensive patterns

Strategy: validation

Validate before calling

const model = resolved?.model;
if (!model) throw new Error("No model available for commit generation");
const apiKey = await modelRegistry.getApiKey(model);
if (!apiKey) {
  // fall back to another configured provider/model instead of throwing
  console.error(`No API key for ${model.provider}/${model.id}; configure it or pick another model`);
}

Type guard

function hasApiKey(m: { provider: string; id: string } | undefined): m is { provider: string; id: string } {
  return m !== undefined;
}

Try / catch

try {
  const primary = await resolvePrimaryModel();
} catch (err) {
  if (err instanceof Error && err.message.startsWith("No API key available")) {
    // prompt user to run auth flow or select a different model
  } else throw err;
}

Prevention

When it happens

Trigger: Calling resolvePrimaryModel (directly or via primary()/primaryModelPromise) when the resolved model has no API key: the provider's key is unset in env/config, auth refresh failed, or modelRegistry.getApiKey was wired to a lookup that misses this provider.

Common situations: Running the commit command before ever authenticating with the provider (`omp auth` / login not done for that provider); a renamed or rotated env var (e.g. ANTHROPIC_API_KEY) removed from CI; switching default model to a provider the user never configured; a custom model registry in tests returning no key.

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


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/e793a32061014fff. Report an issue: GitHub.