{"record":{"id":"7bc3466a1b4ee745","repo":"continuedev/continue","slug":"aws-bedrock-stream-error-error-as-any-code","errorCode":null,"errorMessage":"AWS Bedrock stream error (${(error as any).code}): ${error.message}","messagePattern":"AWS Bedrock stream error \\((.+?)\\): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/openai-adapters/src/apis/Bedrock.ts","lineNumber":562,"sourceCode":"                  {\n                    index: 0,\n                    id: start.toolUse.toolUseId,\n                    type: \"function\",\n                    function: {\n                      name: start.toolUse.name,\n                      arguments: undefined,\n                    },\n                  },\n                ],\n              },\n            });\n          }\n        }\n      }\n    } catch (error) {\n      if (error instanceof Error) {\n        if (\"code\" in error) {\n          throw new Error(\n            `AWS Bedrock stream error (${(error as any).code}): ${error.message}`,\n          );\n        }\n        throw new Error(`Error processing Bedrock stream: ${error.message}`);\n      }\n      throw new Error(\n        \"Error processing Bedrock stream: Unknown error occurred\",\n      );\n    }\n  }\n\n  completionNonStream(\n    body: CompletionCreateParamsNonStreaming,\n  ): Promise<Completion> {\n    throw new Error(\"Bedrock does not support completions API\");\n  }\n\n  completionStream(","sourceCodeStart":544,"sourceCodeEnd":580,"githubUrl":"https://github.com/continuedev/continue/blob/5522c6f44ca0ac3528b37244818fbfa39b5af470/packages/openai-adapters/src/apis/Bedrock.ts#L544-L580","documentation":"Thrown when the AWS Bedrock converse/invoke streaming call fails with an error that carries a `code` property (typical of AWS SDK v3 service exceptions like ThrottlingException, ModelStreamErrorException, or AccessDeniedException). The adapter wraps the raw AWS error and prefixes it with 'AWS Bedrock stream error' plus the AWS error code so the underlying cause is visible. It originates from the catch block of chatCompletionStream, which is also reused by chatCompletionNonStream.","triggerScenarios":"Calling chatCompletionStream (or chatCompletionNonStream) and the underlying Bedrock InvokeModelWithResponseStreamCommand fails mid-stream: throttling (code: ThrottlingException), model not entitled (AccessDeniedException), invalid modelId (ValidationException), or network/credential errors surfaced by the AWS SDK with a `code` field.","commonSituations":"Missing or wrong AWS credentials/region in config; using a model ID not enabled for the account; hitting Bedrock rate limits or account quotas; streaming a non-streaming-capable model; AWS SDK v3 middleware errors that annotate `code`.","solutions":["Read the parenthesized AWS code in the message (e.g. ThrottlingException) and fix the corresponding cause: enable the model in the Bedrock console, verify credentials/region, or request a quota increase.","Add exponential-backoff retry around the call for ThrottlingException / ServiceUnavailable codes.","Verify the modelId string exactly matches a Bedrock-supported identifier (e.g. anthropic.claude-3-5-sonnet-...) and that it supports streaming.","If behind a proxy or cross-region setup, confirm network egress to bedrock-runtime.<region>.amazonaws.com is allowed."],"exampleFix":"// before\nconst stream = await api.chatCompletionStream(body);\n\n// after\ntry {\n  const stream = await api.chatCompletionStream(body);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('AWS Bedrock stream error')) {\n    const code = e.message.match(/\\((.*?)\\)/)?.[1];\n    if (code === 'ThrottlingException') await backoffAndRetry();\n  }\n  throw e;\n}","handlingStrategy":"retry","validationCode":"// Pre-check model availability & config before streaming\nimport { BedrockRuntimeClient, InvokeModelCommand } from '@aws-sdk/client-bedrock-runtime';\nconst probe = await client.send(new InvokeModelCommand({ modelId, body: JSON.stringify({ inputText: 'ping' }) }));","typeGuard":"function isBedrockServiceError(e: unknown): e is Error & { code: string } {\n  return e instanceof Error && 'code' in e;\n}","tryCatchPattern":"try {\n  await api.chatCompletionStream(body);\n} catch (e) {\n  const m = e instanceof Error ? e.message : String(e);\n  if (m.startsWith('AWS Bedrock stream error')) {\n    const code = m.match(/\\((.*?)\\)/)?.[1] ?? '';\n    if (['ThrottlingException', 'ServiceUnavailableException'].includes(code)) return retryWithBackoff();\n  }\n  throw e;\n}","preventionTips":["Verify modelId is enabled for the account in the Bedrock console before deploying.","Configure AWS credentials and region explicitly in the adapter config.","Wrap calls in exponential backoff for throttling-class AWS error codes."],"tags":["aws","bedrock","streaming","sdk-error","chat-completions"],"backgroundTag":"aws-bedrock-service-error","analyzedSha":"5522c6f44ca0ac3528b37244818fbfa39b5af470","analyzedAt":"2026-08-27T11:28:54.683Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}