can1357/oh-my-pi · error · AIError.ConfigurationError

Unhandled API in mapOptionsForApi: ${model.api}

Error message

Unhandled API in mapOptionsForApi: ${model.api}

What it means

mapOptionsForApi converts generic request options (e.g. reasoning effort, budgets) into API-specific wire options, but only for APIs it knows. If model.api is not one of the handled cases, it throws AIError.ConfigurationError `Unhandled API in mapOptionsForApi: ${model.api}`. Like the stream dispatch error, it signals the library does not support this API kind — typically a version skew or bad model metadata.

Source

Thrown at packages/ai/src/stream.ts:2385

		case "gitlab-duo-agent":
			return castApi<"gitlab-duo-agent">({
				...base,
				cwd: options?.cwd,
				toolChoice: options?.toolChoice,
			});
		case "devin-agent": {
			const devinModel = model as Model<"devin-agent">;
			const effort =
				options?.reasoning && !options.disableReasoning
					? requireSupportedEffort(devinModel, options.reasoning)
					: undefined;
			return castApi<"devin-agent">({
				...base,
				chatModelUid: resolveWireModelId(devinModel, effort),
			});
		}
		default:
			throw new AIError.ConfigurationError(`Unhandled API in mapOptionsForApi: ${model.api}`);
	}
}

function getGoogleBudget(
	model: Model<"google-generative-ai">,
	effort: Effort,
	customBudgets?: ThinkingBudgets,
): number {
	requireSupportedEffort(model, effort);

	// Custom budgets take precedence if provided for this level
	if (customBudgets?.[effort] !== undefined) {
		return customBudgets[effort]!;
	}

	// See https://ai.google.dev/gemini-api/docs/thinking#set-budget
	const resolvedBudget = model.thinking?.effortBudgets?.[effort];
	if (resolvedBudget !== undefined) return resolvedBudget;

View on GitHub (pinned to 9690622007)

Solutions

  1. Upgrade @oh-my-pi/pi-ai so mapOptionsForApi handles the model's api.
  2. Fix the model entry's api field to a supported API kind.
  3. Align package versions (bun install / bun.lock update) so catalog-produced models match supported APIs.
  4. Remove unsupported custom models from the registry.

Example fix

// before
const model = { api: "new-hotness-api", ... } as Model;
await client.chat(model, msgs, { effort: "high" });
// after
bun update @oh-my-pi/pi-ai @oh-my-pi/pi-catalog
// or use a supported api:
const model = { api: "anthropic-messages", ... } as Model<"anthropic-messages">;
Defensive patterns

Strategy: try-catch

Validate before calling

if (!mapOptionsForApiSupports(model.api)) {
  throw new Error(`Options mapping unsupported for api "${model.api}" in this pi-ai version`);
}

Try / catch

try {
  await client.chat(model, messages, options);
} catch (err) {
  if (err instanceof AIError.ConfigurationError && err.message.includes("Unhandled API in mapOptionsForApi")) {
    console.error(`api "${model.api}" unsupported; upgrade packages or fix the model entry.`);
    return;
  }
  throw err;
}

Prevention

When it happens

Trigger: Any streaming/chat call whose model has an api value outside the switch's cases, causing the options-mapping step to hit the default branch.

Common situations: Newer/older package versions between pi-ai and the catalog; hand-built Model objects with an unsupported or typo'd api string; third-party registry entries using a custom api name.

Related errors


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