Typescript
Error Handling

Error Handling

Primarily, errors happen when the library is unable to connect to the API (from network connection problems).

Catching Errors

async function main() {
  const completion = await anthropic.Completion
    .create({
      model: "anthropic.claude-v2",
      prompt="Why is the sky blue?"
      max_tokens_to_sample: 256,
    })
    .catch((e) => {
      console.log(err.status);
      console.log(err.name);
      console.log(err.headers);
    });
}
main().catch(console.error);

Retries

new AnthropicBedrock({
  maxRetries: 3, // default is 2
});

Timeouts

By default requests timeout after a minute, however you can adjust the timeout option. This could be useful when maxing out the context length.

new AnthropicBedrock({
  timeout: 5 * 1000, // default is 60 * 1000 (60 secs)
});

Error Codes

Status CodeError Type
400BadRequestError
401AuthenticationError
403PermissionDeniedError
404NotFoundError
422UnprocessableEntityError
429RateLimitError
>=500InternalServerError
N/AAPIConnectionError