can1357/oh-my-pi · error

HTTP ${response.status} from ${modelsUrl}

Error message

HTTP ${response.status} from ${modelsUrl}

What it means

discoverLlamaCppModels fetches `GET <baseUrl>/models` from a llama.cpp server (llama-server) to enumerate loaded models. Any non-ok HTTP status from that endpoint throws `Error("HTTP <status> from <modelsUrl>")`. The request runs inside withTimeoutSignal and may be attempted twice (with and without a Bearer key resolved from the provider's API-key resolver).

Source

Thrown at packages/coding-agent/src/config/model-discovery.ts:614

export async function discoverLlamaCppModels(
	providerConfig: DiscoveryProviderConfig,
	ctx: DiscoveryContext,
): Promise<Model<Api>[]> {
	const baseUrl = normalizeLlamaCppBaseUrl(providerConfig.baseUrl);
	const modelsUrl = `${baseUrl}/models`;

	const baseHeaders: Record<string, string> = { ...(providerConfig.headers ?? {}) };
	let headers = baseHeaders;
	const customTimeoutMs = providerConfig.discovery.timeoutMs;
	const attempt = async (h: Record<string, string>) => {
		const [payload, metadata] = await Promise.all([
			withTimeoutSignal(discoveryProbeTimeoutMs(baseUrl, 250, customTimeoutMs), async signal => {
				const response = await ctx.fetch(modelsUrl, {
					headers: h,
					signal,
				});
				if (!response.ok) {
					throw new Error(`HTTP ${response.status} from ${modelsUrl}`);
				}
				headers = h;
				return (await response.json()) as unknown;
			}),
			discoverLlamaCppServerMetadata(ctx, baseUrl, h, customTimeoutMs),
		]);
		return [payload, metadata] as const;
	};
	const apiKey = await ctx.getBearerApiKeyResolver(providerConfig.provider);
	const [payload, serverMetadata] = apiKey
		? await withAuth(apiKey, key => attempt({ ...baseHeaders, Authorization: `Bearer ${key}` }))
		: await attempt(baseHeaders);
	const models = parseLlamaCppModelList(payload);
	const discovered: Model<Api>[] = [];
	for (const item of models) {
		const { id } = item;
		if (!id) continue;
		const contextWindow =

View on GitHub (pinned to 9690622007)

Solutions

  1. If llama-server uses --api-key, set the matching apiKey in the provider config so the Bearer attempt is made.
  2. curl -i http://<host>:<port>/models (with the key) and confirm 200; fix the baseUrl to the llama-server root otherwise.
  3. Update llama.cpp if /models is missing (404) — older builds did not expose the models endpoint.
  4. Restart llama-server / check its logs if the status is 500/503, then retry discovery.

Example fix

// before: llama-server run with --api-key sk-x but provider has no key
{ "provider": "llamacpp", "baseUrl": "http://localhost:8080", "discovery": { "type": "llama-cpp" } }
// after: supply the key
{ "provider": "llamacpp", "baseUrl": "http://localhost:8080", "apiKey": "sk-x", "discovery": { "type": "llama-cpp" } }
Defensive patterns

Strategy: try-catch

Validate before calling

const url = `${baseUrl.replace(/\/$/, '')}/models`;
const res = await fetch(url, { headers: apiKey ? { Authorization: `Bearer ${apiKey}` } : {} });
if (!res.ok) throw new Error(`llama.cpp /models probe failed: HTTP ${res.status} from ${url}`);

Type guard

null

Try / catch

try {
  const models = await discoverLlamaCppModels(cfg, ctx);
} catch (err) {
  if (err instanceof Error && err.message.startsWith("HTTP ")) {
    const status = Number(err.message.match(/HTTP (\d+)/)?.[1]);
    if (status === 401 || status === 403) throw new Error("llama-server --api-key set but provider apiKey missing/wrong");
    return staticFallbackModels;
  }
  throw err;
}

Prevention

When it happens

Trigger: discoverLlamaCppModels called (via discoverModelsByProviderType) when llama-server returns 401/403 because --api-key is set but no matching key was resolved; 404 because baseUrl does not include the right prefix or an old llama.cpp build lacks /models; 500/503 while the server is starting or overloaded.

Common situations: llama-server started with --api-key but provider config omits apiKey; baseUrl pointed at the native root of an old build without the /models route; a proxy returning 502 because llama-server crashed; pointing the llama.cpp discovery type at an Ollama/vLLM endpoint.

Related errors


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