{"record":{"id":"a778368809d515e5","repo":"different-ai/openwork","slug":"cua-api-error-response-status-errortext-slic","errorCode":null,"errorMessage":"CUA API error ${response.status}: ${errorText.slice(0, 300)}","messagePattern":"CUA API error (.+?): (.+?)","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/handsfree/src/cua-runner.mjs","lineNumber":36,"sourceCode":"  onProgress?.({ kind: \"start\", width: displayInfo.width, height: displayInfo.height });\n\n  const items = [{ role: \"user\", content: String(task ?? \"\") }];\n  const messages = [];\n\n  for (let turn = 0; turn < maxTurns; turn += 1) {\n    if (signal?.aborted) return { ok: true, messages, turns: turn, aborted: true };\n    onProgress?.({ kind: \"turn\", turn: turn + 1 });\n\n    const response = await fetch(\"https://api.openai.com/v1/responses\", {\n      method: \"POST\",\n      headers: { Authorization: `Bearer ${apiKey}`, \"Content-Type\": \"application/json\" },\n      body: JSON.stringify({ model, input: items, tools: [{ type: \"computer\" }] }),\n      signal,\n    });\n\n    if (!response.ok) {\n      const errorText = await response.text().catch(() => \"\");\n      throw new Error(`CUA API error ${response.status}: ${errorText.slice(0, 300)}`);\n    }\n\n    const result = await response.json();\n    const output = result.output || [];\n    if (!output.length) throw new Error(\"No output from CUA model.\");\n    items.push(...output);\n\n    let computerCall = null;\n    for (const item of output) {\n      if (item.type === \"message\") {\n        const text = item.content?.map((part) => part.text || \"\").join(\"\") || \"\";\n        if (text) {\n          messages.push(text);\n          onProgress?.({ kind: \"message\", text });\n        }\n      }\n      if (item.type === \"computer_call\") computerCall = item;\n    }","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/packages/handsfree/src/cua-runner.mjs#L18-L54","documentation":"After POSTing the conversation items to the OpenAI computer-use endpoint, runCuaLoop checks response.ok. Any non-2xx (401 invalid key, 402 quota, 429 rate limit, 400 bad model/input, 5xx) becomes this error with the HTTP status and up to 300 chars of the response body, so the actual API error reason is embedded in the message.","triggerScenarios":"Any failed fetch from the loop's model request — invalid/revoked API key (401), out-of-credit org (402), rate limiting (429), unknown `model` name, malformed `items` pushed into the conversation (400), or transient 500/503 from OpenAI.","commonSituations":"Expired or rotated OpenAI keys; free-tier org with no computer-use access; sending stale tool outputs or oversized screenshots producing a 400; regional outages returning 5xx; corporate proxy stripping the Authorization header.","solutions":["Read the embedded errorText in the message — it contains OpenAI's JSON error explaining the real cause (e.g. 'Incorrect API key', 'insufficient_quota').","For 401/402: fix the API key or billing at platform.openai.com; for 429: add backoff/retry with exponential delay.","For 400: confirm `model` supports the computer-use tool and that pushed items are valid Responses-API output items.","Wrap the runCuaLoop call in retry logic for 429/5xx statuses before surfacing to the user."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await runCuaLoop(opts);\n} catch (e) {\n  const m = /CUA API error (\\d+)/.exec(e.message);\n  const status = m ? Number(m[1]) : 0;\n  if (status === 429 || status >= 500) await backoffRetry(opts);\n  else throw e; // 401/402/400 are not retryable\n}","preventionTips":["Validate the API key with a cheap models.list call before long-running loops","Monitor org quota/credits before batch CUA jobs","Pin a model name known to support the computer-use tool"],"tags":["http-error","openai","network","api"],"backgroundTag":"http-error-response","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}