{"record":{"id":"2e194ed7e937a300","repo":"paperclipai/paperclip","slug":"anthropic-managed-agents-request-failed-with-http","errorCode":null,"errorMessage":"Anthropic Managed Agents request failed with HTTP ${response.status}","messagePattern":"Anthropic Managed Agents request failed with HTTP (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/src/commands/managed-agent.ts","lineNumber":133,"sourceCode":"async function anthropicRequest(\n  key: string,\n  method: \"GET\" | \"POST\",\n  path: string,\n  body?: Record<string, unknown>,\n): Promise<Record<string, unknown>> {\n  const response = await fetch(`${ANTHROPIC_ORIGIN}${path}`, {\n    method,\n    headers: {\n      \"x-api-key\": key,\n      \"anthropic-version\": ANTHROPIC_VERSION,\n      \"anthropic-beta\": CLAUDE_MANAGED_BETA_VERSION,\n      ...(body ? { \"content-type\": \"application/json\" } : {}),\n    },\n    ...(body ? { body: JSON.stringify(body) } : {}),\n    signal: AbortSignal.timeout(15_000),\n  });\n  if (!response.ok) {\n    throw new Error(`Anthropic Managed Agents request failed with HTTP ${response.status}`);\n  }\n  if (response.status === 204) return {};\n  return record(await response.json());\n}\n\nasync function listAll(key: string, path: string): Promise<RemoteResource[]> {\n  const rows: RemoteResource[] = [];\n  let page: string | null = null;\n  do {\n    const suffix = page ? `${path.includes(\"?\") ? \"&\" : \"?\"}page=${encodeURIComponent(page)}` : \"\";\n    const response = await anthropicRequest(key, \"GET\", `${path}${suffix}`);\n    for (const value of Array.isArray(response.data) ? response.data : []) {\n      rows.push(record(value) as RemoteResource);\n    }\n    page = typeof response.next_page === \"string\" && response.next_page\n      ? response.next_page\n      : null;\n  } while (page);","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/paperclipai/paperclip/blob/5716fe907e596ce73501408fc6efdb19fb61edf2/cli/src/commands/managed-agent.ts#L115-L151","documentation":"`anthropicRequest` throws this whenever the Anthropic Managed Agents API (api.anthropic.com, beta managed-agents-2026-04-01) responds with a non-OK HTTP status. The response body is discarded, so the message carries only the numeric status — 401/403 mean auth problems, 404 a bad resource id, 429 rate limiting, 5xx an Anthropic-side issue. It is raised for every GET/POST the command makes (environments, agents, sessions).","triggerScenarios":"Expired or revoked ANTHROPIC_API_KEY (401/403); wrong environmentId/agentId (404); exceeding Managed Agents beta rate limits (429); Anthropic outage or beta endpoint changes (500/503); a request taking over the 15-second AbortSignal timeout surfaces as a fetch abort rather than this error, but gateway 504s do hit it.","commonSituations":"Rotating the Anthropic key without updating the shell env; deleting an environment/agent in the Anthropic console while the CLI still references its id; running many setup commands in a loop and tripping rate limits; beta header/version drift after an API change.","solutions":["Check the status in the message: 401/403 → re-export a valid ANTHROPIC_API_KEY; 404 → verify the resource id; 429 → back off and retry later; 5xx → retry after checking Anthropic status","Confirm the beta header/version is current for your CLI release — beta endpoints change","Re-run a single command manually to see if it is transient","Capture the response body with curl against the same endpoint for the detailed error JSON the CLI discards"],"exampleFix":"// before\ntry { await runManagedAgentSetup(opts); } catch { /* silent */ }\n// after\ntry {\n  await runManagedAgentSetup(opts);\n} catch (err) {\n  if (/HTTP 429/.test(String(err))) {\n    await sleep(60_000); // back off on rate limit, then retry once\n    await runManagedAgentSetup(opts);\n  } else {\n    throw err;\n  }\n}","handlingStrategy":"retry","validationCode":"// Preflight: verify credentials and resources before running the command\ncurl -s -o /dev/null -w \"%{http_code}\" -H \"x-api-key: $ANTHROPIC_API_KEY\" \\\n  -H \"anthropic-version: 2023-06-01\" -H \"anthropic-beta: managed-agents-2026-04-01\" \\\n  https://api.anthropic.com/v1/environments","typeGuard":null,"tryCatchPattern":"try {\n  await setupManagedAgent(opts);\n} catch (err) {\n  const m = /HTTP (\\d{3})/.exec(String(err));\n  const status = m ? Number(m[1]) : 0;\n  if (status === 429 || status >= 500) {\n    await backoffRetry(() => setupManagedAgent(opts), { attempts: 3 });\n  } else if (status === 401 || status === 403) {\n    throw new Error(\"Anthropic key invalid/forbidden — re-export ANTHROPIC_API_KEY\");\n  } else throw err;\n}","preventionTips":["Retry only transient statuses (429, 5xx) with exponential backoff","Rotate and re-export ANTHROPIC_API_KEY before it expires; watch for 401s","Verify resource ids exist before referencing them (404 means stale id)","Keep the CLI updated so the anthropic-beta header matches the current Managed Agents API","Check Anthropic status/d trust during 5xx bursts"],"tags":["http","network","anthropic-api","rate-limit"],"backgroundTag":"upstream-http-error","analyzedSha":"5716fe907e596ce73501408fc6efdb19fb61edf2","analyzedAt":"2026-09-02T18:44:00.616Z","contentChangedAt":"2026-09-02T18:44:00.616Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}