php changedcli-sdks-libraries/sdks/php
Nearest release: v2.1.309, published 3 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+42added
Lines−40removed
From line
30
where the diff opens
First seen
14 Aug 2026
this site's first read of the page
Recorded edits11to this page, all time
The whole hunk
from line 30, old and new numbered
/
from line 30
3030$client = new Client();
3131
3232$message = $client->messages->create(
33 maxTokens: 1024,
34 messages: [['role' => 'user', 'content' => 'Hello, Claude']],
35 model: 'claude-opus-5-5',
33 maxTokens: 1024,
34 messages: [['role' => 'user', 'content' => 'Hello, Claude']],
35 model: 'claude-opus-5-5',
3636);
3737
3838$textBlock = array_find($message->content, static fn ($block): bool => $block->type === 'text');
from line 43
4343
4444## Value objects
4545
46The recommended way to initialize value objects is the static `with` constructor `Base64ImageSource::with(data: "U3RhaW5sZXNzIHJvY2tz", ...)` with named parameters.
46The recommended way to initialize value objects is the static `with` constructor `Base64ImageSource::with(data: 'U3RhaW5sZXNzIHJvY2tz', ...)` with named parameters.
4747
48However, builders are also provided `(new Base64ImageSource)->withData("U3RhaW5sZXNzIHJvY2tz")`.
48However, builders are also provided, for example `(new Base64ImageSource())->withData('U3RhaW5sZXNzIHJvY2tz')`.
4949
5050## Streaming
5151
from line 55
5555$client = new Client();
5656
5757$stream = $client->messages->createStream(
58 maxTokens: 1024,
59 messages: [['role' => 'user', 'content' => 'Hello, Claude']],
60 model: 'claude-opus-5-5',
58 maxTokens: 1024,
59 messages: [['role' => 'user', 'content' => 'Hello, Claude']],
60 model: Model::CLAUDE_OPUS_5_5,
6161);
6262
6363foreach ($stream as $event) {
64 echo $event->type . PHP_EOL;
64 echo $event->type . PHP_EOL;
6565}
6666```
6767
from line 69
6969
7070```php
7171$client = new Client(
72 requestOptions: RequestOptions::with(streamingTransporter: $myStreamingClient),
72 requestOptions: RequestOptions::with(streamingTransporter: $myStreamingClient),
7373);
7474```
7575
from line 83
8383use Anthropic\Core\Exceptions\APIConnectionException;
8484use Anthropic\Core\Exceptions\APIStatusException;
8585use Anthropic\Core\Exceptions\RateLimitException;
86use Anthropic\Messages\Model;
8687// ...
8788try {
88 $message = $client->messages->create(
89 maxTokens: 1024,
90 messages: [['role' => 'user', 'content' => 'Hello, Claude']],
91 model: 'claude-opus-5-5',
92 );
89 $message = $client->messages->create(
90 maxTokens: 1024,
91 messages: [['role' => 'user', 'content' => 'Hello, Claude']],
92 model: Model::CLAUDE_OPUS_5_5,
93 );
9394} catch (APIConnectionException $e) {
94 echo "The server could not be reached", PHP_EOL;
95 echo $e->getPrevious()?->getMessage(), PHP_EOL;
95 echo 'The server could not be reached', PHP_EOL;
96 echo $e->getPrevious()?->getMessage(), PHP_EOL;
9697} catch (RateLimitException $_) {
97 echo "A 429 status code was received; we should back off a bit.", PHP_EOL;
98 echo 'A 429 status code was received; we should back off a bit.', PHP_EOL;
9899} catch (APIStatusException $e) {
99 echo "Another non-200-range status code was received", PHP_EOL;
100 echo $e->getMessage();
100 echo 'Another non-200-range status code was received', PHP_EOL;
101 echo $e->getMessage();
101102}
102103```
103104
from line 127
126127You can use the `maxRetries` option to configure or disable this:
127128
128129```php
130use Anthropic\Messages\Model;
129131use Anthropic\RequestOptions;
130132// ...
131133// Configure the default for all requests:
from line 135
133135
134136// Or, configure per-request:
135137$result = $client->messages->create(
136 maxTokens: 1024,
137 messages: [['role' => 'user', 'content' => 'Hello, Claude']],
138 model: 'claude-opus-5-5',
139 requestOptions: RequestOptions::with(maxRetries: 5),
138 maxTokens: 1024,
139 messages: [['role' => 'user', 'content' => 'Hello, Claude']],
140 model: Model::CLAUDE_OPUS_5_5,
141 requestOptions: RequestOptions::with(maxRetries: 5),
140142);
141143```
142144
from line 155
153155
154156// fetch items from the current page
155157foreach ($page->getItems() as $item) {
156 echo $item->id, PHP_EOL;
158 echo $item->id, PHP_EOL;
157159}
158160// make additional network requests to fetch items from all pages, including and after the current page
159161// ...
160162foreach ($page->pagingEachItem() as $item) {
161 echo $item->id, PHP_EOL;
163 echo $item->id, PHP_EOL;
162164// ...
163165}
164166```
from line 181
179181use Anthropic\RequestOptions;
180182// ...
181183$message = $client->messages->create(
182 maxTokens: 1024,
183 messages: [['role' => 'user', 'content' => 'Hello, Claude']],
184 model: 'claude-opus-5-5',
185 requestOptions: RequestOptions::with(
186 extraQueryParams: ['my_query_parameter' => 'value'],
187 extraBodyParams: ['my_body_parameter' => 'value'],
188 extraHeaders: ['my-header' => 'value'],
189 ),
184 maxTokens: 1024,
185 messages: [['role' => 'user', 'content' => 'Hello, Claude']],
186 model: 'claude-opus-5-5',
187 requestOptions: RequestOptions::with(
188 extraQueryParams: ['my_query_parameter' => 'value'],
189 extraBodyParams: ['my_body_parameter' => 'value'],
190 extraHeaders: ['my-header' => 'value'],
191 ),
190192);
191193```
192194
from line 204
202204$client = new Client();
203205
204206$response = $client->request(
205 method: "post",
206 path: '/undocumented/endpoint',
207 query: ['dog' => 'woof'],
208 headers: ['useful-header' => 'interesting-value'],
209 body: ['hello' => 'world']
207 method: 'post',
208 path: '/undocumented/endpoint',
209 query: ['dog' => 'woof'],
210 headers: ['useful-header' => 'interesting-value'],
211 body: ['hello' => 'world']
210212);
211213```
212214
No line in this hunk matches that.