{"record":{"id":"f2b649a8b84b07a0","repo":"ruvnet/ruflo","slug":"anthropic-api-error-response-status","errorCode":null,"errorMessage":"Anthropic API error: ${response.status}","messagePattern":"Anthropic API error: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/mcp/src/sampling.ts","lineNumber":344,"sourceCode":"        headers: {\n          'Content-Type': 'application/json',\n          'x-api-key': apiKey,\n          'anthropic-version': '2023-06-01',\n        },\n        body: JSON.stringify({\n          model: 'claude-3-haiku-20240307',\n          max_tokens: request.maxTokens,\n          temperature: request.temperature,\n          system: request.systemPrompt,\n          messages: request.messages.map((m) => ({\n            role: m.role,\n            content: m.content.type === 'text' ? (m.content as any).text : m.content,\n          })),\n        }),\n      });\n\n      if (!response.ok) {\n        throw new Error(`Anthropic API error: ${response.status}`);\n      }\n\n      const data = await response.json() as any;\n\n      return {\n        role: 'assistant',\n        content: {\n          type: 'text',\n          text: data.content[0]?.text || '',\n        },\n        model: data.model,\n        stopReason: data.stop_reason === 'end_turn' ? 'endTurn' : 'maxTokens',\n      };\n    },\n    async isAvailable(): Promise<boolean> {\n      return !!apiKey;\n    },\n  };","sourceCodeStart":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/mcp/src/sampling.ts#L326-L362","documentation":"The Anthropic messages API returned a non-2xx status for the sampling call. The HTTP status is surfaced (rate limit, auth failure, overloaded, etc.) so the caller can distinguish provider-side failures from local validation issues.","triggerScenarios":"The Anthropic API returns a non-2xx HTTP status during a sampling request.","commonSituations":"Invalid or expired API key (401), rate limiting (429), overloaded API (529), or malformed request body (400).","solutions":["Read the response body for the API error detail and include it in the thrown error.","Verify ANTHROPIC_API_KEY is valid and has quota.","Retry with exponential backoff on 429/5xx statuses."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","contentChangedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}