{"record":{"id":"560710420ac94424","repo":"can1357/oh-my-pi","slug":"http-response-status-from-modelsurl","errorCode":null,"errorMessage":"HTTP ${response.status} from ${modelsUrl}","messagePattern":"HTTP (.+?) from (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/config/model-discovery.ts","lineNumber":614,"sourceCode":"export async function discoverLlamaCppModels(\n\tproviderConfig: DiscoveryProviderConfig,\n\tctx: DiscoveryContext,\n): Promise<Model<Api>[]> {\n\tconst baseUrl = normalizeLlamaCppBaseUrl(providerConfig.baseUrl);\n\tconst modelsUrl = `${baseUrl}/models`;\n\n\tconst baseHeaders: Record<string, string> = { ...(providerConfig.headers ?? {}) };\n\tlet headers = baseHeaders;\n\tconst customTimeoutMs = providerConfig.discovery.timeoutMs;\n\tconst attempt = async (h: Record<string, string>) => {\n\t\tconst [payload, metadata] = await Promise.all([\n\t\t\twithTimeoutSignal(discoveryProbeTimeoutMs(baseUrl, 250, customTimeoutMs), async signal => {\n\t\t\t\tconst response = await ctx.fetch(modelsUrl, {\n\t\t\t\t\theaders: h,\n\t\t\t\t\tsignal,\n\t\t\t\t});\n\t\t\t\tif (!response.ok) {\n\t\t\t\t\tthrow new Error(`HTTP ${response.status} from ${modelsUrl}`);\n\t\t\t\t}\n\t\t\t\theaders = h;\n\t\t\t\treturn (await response.json()) as unknown;\n\t\t\t}),\n\t\t\tdiscoverLlamaCppServerMetadata(ctx, baseUrl, h, customTimeoutMs),\n\t\t]);\n\t\treturn [payload, metadata] as const;\n\t};\n\tconst apiKey = await ctx.getBearerApiKeyResolver(providerConfig.provider);\n\tconst [payload, serverMetadata] = apiKey\n\t\t? await withAuth(apiKey, key => attempt({ ...baseHeaders, Authorization: `Bearer ${key}` }))\n\t\t: await attempt(baseHeaders);\n\tconst models = parseLlamaCppModelList(payload);\n\tconst discovered: Model<Api>[] = [];\n\tfor (const item of models) {\n\t\tconst { id } = item;\n\t\tif (!id) continue;\n\t\tconst contextWindow =","sourceCodeStart":596,"sourceCodeEnd":632,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/config/model-discovery.ts#L596-L632","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["If llama-server uses --api-key, set the matching apiKey in the provider config so the Bearer attempt is made.","curl -i http://<host>:<port>/models (with the key) and confirm 200; fix the baseUrl to the llama-server root otherwise.","Update llama.cpp if /models is missing (404) — older builds did not expose the models endpoint.","Restart llama-server / check its logs if the status is 500/503, then retry discovery."],"exampleFix":"// before: llama-server run with --api-key sk-x but provider has no key\n{ \"provider\": \"llamacpp\", \"baseUrl\": \"http://localhost:8080\", \"discovery\": { \"type\": \"llama-cpp\" } }\n// after: supply the key\n{ \"provider\": \"llamacpp\", \"baseUrl\": \"http://localhost:8080\", \"apiKey\": \"sk-x\", \"discovery\": { \"type\": \"llama-cpp\" } }","handlingStrategy":"try-catch","validationCode":"const url = `${baseUrl.replace(/\\/$/, '')}/models`;\nconst res = await fetch(url, { headers: apiKey ? { Authorization: `Bearer ${apiKey}` } : {} });\nif (!res.ok) throw new Error(`llama.cpp /models probe failed: HTTP ${res.status} from ${url}`);","typeGuard":"null","tryCatchPattern":"try {\n  const models = await discoverLlamaCppModels(cfg, ctx);\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith(\"HTTP \")) {\n    const status = Number(err.message.match(/HTTP (\\d+)/)?.[1]);\n    if (status === 401 || status === 403) throw new Error(\"llama-server --api-key set but provider apiKey missing/wrong\");\n    return staticFallbackModels;\n  }\n  throw err;\n}","preventionTips":["If llama-server runs with --api-key, always set the same apiKey in the provider config.","Confirm GET /models returns 200 on the exact baseUrl before enabling discovery.","Update llama.cpp if the /models route is missing (404).","Wrap discovery in a fallback so a down server does not break startup."],"tags":["network","http","model-discovery","llama-cpp"],"backgroundTag":"http-non-2xx-model-list","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}