Follow Discord
Sweep 03 Dec 2026 · 19:13Z Build v2.1.336 553 read Stable v2.1.332 Latest v2.1.336 Next v2.1.336 Feeds RSS JSON llms.txt llms-full.txt Unofficial
One change · api

php changedcli-sdks-libraries/sdks/php

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+8added
Lines−47removed
From line 75 where the diff opens
First seen 14 Aug 2026 this site's first read of the page
Recorded edits19to this page, all time

The whole hunk

from line 75, old and new numbered
/
lines
from line 75
7575 
7676## Error handling
7777 
78When 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 `Anthropic\Core\Exceptions\APIException` is thrown:
78The SDK throws a subclass of `Anthropic\Core\Exceptions\APIException` 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.
7979 
80```php
81<?php
82// ...
83use Anthropic\Core\Exceptions\APIConnectionException;
84use Anthropic\Core\Exceptions\APIStatusException;
85use Anthropic\Core\Exceptions\RateLimitException;
86use Anthropic\Messages\Model;
87// ...
88try {
89 $message = $client->messages->create(
90 maxTokens: 1024,
91 messages: [['role' => 'user', 'content' => 'Hello, Claude']],
92 model: Model::CLAUDE_OPUS_5_5,
93 );
94} catch (APIConnectionException $e) {
95 echo 'The server could not be reached', PHP_EOL;
96 echo $e->getPrevious()?->getMessage(), PHP_EOL;
97} catch (RateLimitException $_) {
98 echo 'A 429 status code was received; we should back off a bit.', PHP_EOL;
99} catch (APIStatusException $e) {
100 echo 'Another non-200-range status code was received', PHP_EOL;
101 echo $e->getMessage();
102}
103```
80To see why a connection failed or timed out, call `getPrevious()` on the `Anthropic\Core\Exceptions\APIConnectionException`. The method returns the underlying exception or `null` if there isn’t one.
10481 
105Error codes are as follows:
106 
107| Cause | Error type |
108| ----- | ----- |
109| HTTP 400 | `BadRequestException` |
110| HTTP 401 | `AuthenticationException` |
111| HTTP 403 | `PermissionDeniedException` |
112| HTTP 404 | `NotFoundException` |
113| HTTP 409 | `ConflictException` |
114| HTTP 422 | `UnprocessableEntityException` |
115| HTTP 429 | `RateLimitException` |
116| HTTP >= 500 | `InternalServerException` |
117| Other HTTP error | `APIStatusException` |
118| Timeout | `APITimeoutException` |
119| Network error | `APIConnectionException` |
120 
12182## Retries
12283 
123Certain errors are automatically retried two times by default, with a short exponential backoff.
84By 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.
12485 
125Connection errors (for example, because of a network connectivity problem), 408 Request Timeout, 409 Conflict, 429 Rate Limit, >=500 Internal errors, and timeouts are all retried by default.
86If 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.
12687 
127You can use the `maxRetries` option to configure or disable this:
88Use the `maxRetries` request option to configure or disable retries:
12889 
12990```php
13091use Anthropic\Messages\Model;
Feedback