{"record":{"id":"4bcf28382fa7fa30","repo":"vercel/ai","slug":"error-message","errorCode":null,"errorMessage":"${error.message}","messagePattern":"\\$\\{error\\.message\\}","errorType":"exception","errorClass":"APICallError","httpStatus":500,"severity":"error","filePath":"packages/anthropic/src/anthropic-language-model.ts","lineNumber":2769,"sourceCode":"\n      let result = await firstChunkReader.read();\n\n      // when raw chunks are enabled, the first chunk is a raw chunk, so we need to read the next chunk\n      if (result.value?.type === 'raw') {\n        result = await firstChunkReader.read();\n      }\n\n      // The Anthropic API returns 200 responses when there are overloaded errors.\n      // We handle the case where the first chunk is an error here and transform\n      // it into an APICallError.\n      if (result.value?.type === 'error') {\n        const error = result.value.error;\n\n        if (!isProviderStreamError(error)) {\n          throw new Error('Expected a normalized Anthropic stream error');\n        }\n\n        throw new APICallError({\n          message: error.message,\n          url,\n          requestBodyValues: body,\n          statusCode: error.statusCode ?? 500,\n          responseHeaders,\n          responseBody: JSON.stringify(error.data),\n          isRetryable: error.isRetryable ?? false,\n        });\n      }\n    } finally {\n      firstChunkReader.cancel().catch(() => {});\n      firstChunkReader.releaseLock();\n    }\n\n    return {\n      stream: streamForConsumer,\n      request: { body },\n      response: { headers: responseHeaders },","sourceCodeStart":2751,"sourceCodeEnd":2787,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/anthropic/src/anthropic-language-model.ts#L2751-L2787","documentation":"When an Anthropic SSE stream reports a normalized error event, doStream re-throws it as an `APICallError` whose message is the provider's error message (the template `${error.message}`). This surfaces mid-stream provider failures (overloaded, rate limit, invalid request) with status code, headers, and the raw error data attached.","triggerScenarios":"Consuming `streamText`/stream APIs with an Anthropic model when the upstream stream emits an error event; the error must pass `isProviderStreamError` or a different error ('Expected a normalized Anthropic stream error') is thrown instead.","commonSituations":"Anthropic returning 529 overloaded_error mid-stream; rate_limit errors on long streams; invalid_request_error from unsupported parameters appearing after stream start; transient network drops interpreted as stream errors.","solutions":["Read the resulting APICallError's statusCode/message to identify the provider cause and adjust the request or retry accordingly.","Catch the error via the stream's onError/onFinish callbacks or try/catch around the stream consumption.","Enable retry/backoff for overloaded (529) and rate-limit (429) statuses.","Check `error.data`/responseBody for Anthropic's error type field (overloaded_error, rate_limit_error, etc.)."],"exampleFix":"// before\nconst { textStream } = streamText({ model: anthropic('claude-...'), prompt });\nfor await (const t of textStream) process.stdout.write(t);\n// after\nconst result = streamText({ model: anthropic('claude-...'), prompt, maxRetries: 3 });\ntry {\n  for await (const t of result.textStream) process.stdout.write(t);\n} catch (e) {\n  if (APICallError.isInstance(e) && e.statusCode === 529) { /* retry later */ }\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"function isAnthropicStreamApiError(e: unknown): e is import('@ai-sdk/provider').APICallError {\n  return import('@ai-sdk/provider').APICallError.isInstance(e);\n}","tryCatchPattern":"try {\n  for await (const delta of result.textStream) { /* ... */ }\n} catch (e) {\n  if (APICallError.isInstance(e)) {\n    const { statusCode, message } = e;\n    if (statusCode === 529 || statusCode === 429) { /* retry with backoff */ }\n  }\n  throw e;\n}","preventionTips":["Set maxRetries on streamText for transient provider errors.","Handle Anthropic error types (overloaded_error, rate_limit_error) explicitly.","Monitor stream onError/onFinish for mid-stream failures.","Keep model parameters within provider limits to avoid invalid_request errors."],"tags":["streaming","api-call-error","anthropic","provider"],"backgroundTag":"provider-stream-error","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}