earendil-works/pi · error · ModelsError

stream

stream

Error message

Provider ${input.id} has no API implementation for "${model.api}"

What it means

Dispatch guard in the Models stream wiring: the registered provider has no stream implementation for the specific model's api (the byApi record lacks that key and no single stream exists), so requests for that model cannot be routed.

Solutions

  1. Choose a model.api the provider implements, or register an implementation for that api.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/ai/src/models.ts:788 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of earendil-works/pi@4af9d21d3b (2026-08-24). Data as JSON: /api/errors/f0e54c9633ecae91. Report an issue: GitHub.

Appendix: source

Thrown at packages/ai/src/models.ts:788

			if (index >= 0) merged[index] = model;
			else merged.push(model);
		}
		return merged;
	};
	const single =
		typeof (input.api as ProviderStreams).stream === "function" ? (input.api as ProviderStreams) : undefined;
	const byApi = single ? undefined : (input.api as Partial<Record<string, ProviderStreams>>);

	const apiFor = (model: Model<Api>): ProviderStreams | undefined => single ?? byApi?.[model.api];

	const dispatch = (
		model: Model<Api>,
		run: (streams: ProviderStreams) => AssistantMessageEventStream,
	): AssistantMessageEventStream => {
		const streams = apiFor(model);
		if (!streams) {
			return lazyStream(model, async () => {
				throw new ModelsError("stream", `Provider ${input.id} has no API implementation for "${model.api}"`);
			});
		}
		return run(streams);
	};

	const provider: Provider<TApi> = {
		id: input.id,
		name: input.name ?? input.id,
		baseUrl: input.baseUrl,
		headers: input.headers,
		auth: input.auth,
		getModels: currentModels,
		refreshModels: fetchModels
			? async (context) => {
					if (context.stored) {
						const restored = context.stored.models
							.filter((model) => model.provider === input.id)
							.map((model) => model as Model<TApi>);

View on GitHub (pinned to 4af9d21d3b)