Follow Discord
Sweep 24 Nov 2026 · 22:58Z Build v2.1.332 549 read Stable v2.1.326 Latest v2.1.332 Next v2.1.332 Feeds RSS JSON llms.txt llms-full.txt Unofficial
One change · api

typescript changedcli-sdks-libraries/sdks/typescript

Nearest release: v2.1.332, published 6 hours before this site recorded the change. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.

Recorded here
Lines+13added
Lines−36removed
From line 374 where the diff opens
First seen 14 Aug 2026 this site's first read of the page
Recorded edits20to this page, all time

The whole hunk

from line 374, old and new numbered
/
lines
from line 374
374374 
375375## Handling errors
376376 
377When the library is unable to connect to the API, or if the API returns a non-success status code (that is, a 4xx or 5xx response), a subclass of `APIError` is thrown:
377The SDK throws a subclass of `Anthropic.APIError` when it can’t connect to the API or when the API returns an error response (4xx or 5xx). [SDK error types](https://platform.claude.com/docs/en/api/errors#sdk-error-types) lists the classes, and [Handle errors](https://platform.claude.com/docs/en/api/handle-errors) shows how to catch them.
378378 
379```typescript
380const message = await client.messages
381 .create({
382 max_tokens: 1024,
383 messages: [{ role: "user", content: "Hello, Claude" }],
384 model: "claude-opus-5-5"
385 })
386 .catch(async (err) => {
387 if (err instanceof Anthropic.APIError) {
388 console.log(err.status); // 400
389 console.log(err.name); // BadRequestError
390 console.log(err.headers); // {server: 'nginx', ...}
391 } else {
392 throw err;
393 }
394 });
395```
379The error’s `status` and `headers` properties hold the response’s status and headers (for example, `err.headers?.get("retry-after")`). Both are `undefined` if there was no response.
396380 
397Error codes are as follows:
381Two errors don’t come from a failed connection or an error response. A check for `APIError` matches the first but not the second:
398382 
399| Status code | Error type |
400| ----- | ----- |
401| 400 | `BadRequestError` |
402| 401 | `AuthenticationError` |
403| 403 | `PermissionDeniedError` |
404| 404 | `NotFoundError` |
405| 409 | `ConflictError` |
406| 422 | `UnprocessableEntityError` |
407| 429 | `RateLimitError` |
408| >=500 | `InternalServerError` |
409| N/A | `APIConnectionError` |
383* **`APIUserAbortError`:** You aborted a request with the `signal` request option (an `AbortSignal`) or called `abort()` on a [`client.messages.stream()` stream](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/typescript#streaming-helpers).
384* **`AnthropicError`:** The SDK itself failed. For example, it refused a long non-streaming request (see [Long requests](https://platform.claude.com/docs/en/cli-sdks-libraries/sdks/typescript#long-requests)). `AnthropicError` is the parent class of `APIError`.
410385 
411386## Request IDs
412387 
from line 400
425400 
426401## Retries
427402 
428Certain errors are automatically retried 2 times by default, with a short exponential backoff. Connection errors (for example, because of a network connectivity problem), 408 Request Timeout, 409 Conflict, 429 Rate Limit, and >=500 Internal errors are all retried by default.
403By default, the SDK retries certain errors up to two times (three attempts in all). It retries connection errors, timeouts, 408 Request Timeout, 409 Conflict, 429 Too Many Requests, and 5xx server errors.
429404 
430You can use the `maxRetries` option to configure or disable this:
405If a response has an `x-should-retry` header (`true` or `false`), the SDK follows it instead of the status. Between attempts, the SDK waits as long as the `retry-after` header says, or it uses a short exponential backoff.
406 
407Use the `maxRetries` option to configure or disable retries:
431408 
432409```typescript
433410// Configure the default for all requests:
Feedback