{"record":{"id":"11842e6e82e70d9f","repo":"Mintplex-Labs/anything-llm","slug":"http-resp-status-await-resp-text-slice-0","errorCode":null,"errorMessage":"HTTP ${resp.status}: ${(await resp.text()).slice(0, 200)}","messagePattern":"HTTP (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"open-computer/services/interface-service/preflight/index.js","lineNumber":150,"sourceCode":"                    type: \"array\",\n                    items: { type: \"string\" },\n                    description:\n                      \"For plan_first or delegate_sequential: 3-6 compact bullets to guide execution.\",\n                  },\n                },\n                required: [\"mode\", \"reason\"],\n              },\n            },\n          },\n        ],\n        tool_choice: \"required\",\n      }),\n    });\n\n    clearTimeout(timeout);\n\n    if (!resp.ok) {\n      throw new Error(\n        `HTTP ${resp.status}: ${(await resp.text()).slice(0, 200)}`,\n      );\n    }\n\n    const data = await resp.json();\n    const args = parsePreflightToolArgs(data.choices?.[0]?.message);\n    const mode =\n      args.mode === \"delegate_sequential\"\n        ? \"delegate_sequential\"\n        : args.mode === \"plan_first\"\n          ? \"plan_first\"\n          : \"simple\";\n    return {\n      mode,\n      reason: String(args.reason || \"model decision\").slice(0, 200),\n      plan_hint: mode !== \"simple\" ? normalizePlanHint(args.plan_hint) : [],\n    };\n  } catch (err) {","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/open-computer/services/interface-service/preflight/index.js#L132-L168","documentation":"Thrown by the interface-service prompt preflight classifier when POST ${OPENAI_BASE_URL||https://api.openai.com/v1}/chat/completions returns a non-2xx status; the message embeds the status and the first 200 bytes of the response body. The call is an OpenAI-compatible chat completion with tool_choice 'required' used to route prompts to simple/plan_first/delegate_sequential modes. Importantly the surrounding try/catch downgrades this to a console.warn and a 'simple' routing decision, so the system keeps working — this error degrades planning quality rather than breaking the request.","triggerScenarios":"settings.OPENAI_API_KEY invalid or expired (401); OPENAI_BASE_URL wrong or missing the /v1 suffix (404); OPENAI_MODEL set to a name the endpoint doesn't serve (404/400); rate limits or quota exhausted (429/402); self-hosted gateway (LM Studio/Ollama/vLLM) reachable from the host but not from resolveBaseUrlForGuest's guest-side address (connection errors surface similarly); endpoints that reject the 'tools'+tool_choice payload (400).","commonSituations":"Swapping the model provider without updating OPENAI_BASE_URL/OPENAI_MODEL; expired API key in the service settings; local LLM server not running when the agent starts; hitting provider rate limits during heavy automated sessions.","solutions":["Check the status/body in the message: 401 -> fix OPENAI_API_KEY; 404 -> fix OPENAI_BASE_URL (include /v1) or OPENAI_MODEL; 429 -> wait/raise limits","Verify the chat/completions endpoint works with curl from the same machine the service runs on, including the tools+tool_choice payload","If using a local gateway, confirm it is bound to an address reachable via resolveBaseUrlForGuest (not 127.0.0.1 of the host only)","If you don't need planning, set SKIP_PLANNING=1 or PROMPT_PREFLIGHT=false — the preflight is skipped and this call never happens"],"exampleFix":"# before: OPENAI_BASE_URL=http://localhost:1234 (missing /v1) -> HTTP 404\nexport OPENAI_BASE_URL=http://localhost:1234\n# after\nexport OPENAI_BASE_URL=http://localhost:1234/v1\nexport OPENAI_MODEL=qwen2.5:14b   # a model the gateway actually serves","handlingStrategy":"fallback","validationCode":"async function preflightReachable(baseUrl, apiKey, model) {\n  try {\n    const r = await fetch(`${baseUrl.replace(/\\/$/, '')}/chat/completions`, {\n      method: 'POST',\n      headers: { 'Content-Type': 'application/json', ...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {}) },\n      body: JSON.stringify({ model, messages: [{ role: 'user', content: 'ping' }], max_tokens: 1 }),\n    });\n    return r.ok;\n  } catch { return false; }\n}\n// run once at service start; log loudly if false","typeGuard":null,"tryCatchPattern":"// Already handled internally: runPromptPreflight catches and returns { mode: 'simple', reason: `failed: ...` }.\n// In your own wrapper, mirror it:\ntry { return await runPromptPreflight(prompt); } catch { return { mode: 'simple', reason: 'preflight unavailable' }; }","preventionTips":["Smoke-test OPENAI_BASE_URL (including /v1), OPENAI_API_KEY, and OPENAI_MODEL together at startup — one curl against /chat/completions with max_tokens 1","Remember the base URL must be reachable from the guest VM (resolveBaseUrlForGuest), not just the host","Set SKIP_PLANNING=1 in environments where the preflight model is intentionally absent so you don't depend on the degraded path"],"tags":["llm","openai","http","api-key","preflight","open-computer"],"backgroundTag":"openai-api-error","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}