Skip to content
Merged
  •  
  •  
  •  
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
*.swo
*.swp
composer.lock
docs/
.idea/
.php-cs-fixer.cache
.php-cs-fixer.php
.phpdoc/
.phpunit.cache
composer.lock
phpunit.xml
playground/
*.swo
*.swp
vendor/
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.2.0"
".": "0.3.0"
}
6 changes: 3 additions & 3 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 23
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic%2Fanthropic-0f40955413f5d04b30ecd6c2f5002ce36a85c320cc671911ff70902fed6e342c.yml
openapi_spec_hash: 92a37231c475ddfec0093718cd24f7ab
config_hash: 21a1f78a64f751cc59c36f88095511cc
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic%2Fanthropic-c150096acd4c91e98b0b888f5cb61e9c2d73c433f165f6fe343a8af50ff40daa.yml
openapi_spec_hash: b0fc4933c9280be98c637752c5cb3acc
config_hash: 6c2c7f9a9019f8299e3fa94c6ac190d1
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
# Changelog

## 0.3.0 (2025-09-02)

Full Changelog: [v0.2.0...v0.3.0](https://github.com/anthropics/anthropic-sdk-php/compare/v0.2.0...v0.3.0)

### ⚠ BREAKING CHANGES

* use builders for RequestOptions

### Features

* **client:** adds support for code-execution-2025-08-26 tool ([99a5428](https://github.com/anthropics/anthropic-sdk-php/commit/99a5428144c21c4d50142d780e820c7a5c93c751))
* expose streams and pages in the public namespace ([41382e4](https://github.com/anthropics/anthropic-sdk-php/commit/41382e45da26b356d66068c80948a56ab93b0958))
* use builders for RequestOptions ([fd0c23a](https://github.com/anthropics/anthropic-sdk-php/commit/fd0c23a3633157f24e0929f74875b3c34031a80f))


### Bug Fixes

* remove inaccurate `license` field in composer.json ([5296a0d](https://github.com/anthropics/anthropic-sdk-php/commit/5296a0d0e5e1079acebd76af86c98337483483c5))


### Chores

* add additional php doc tags ([55cc35f](https://github.com/anthropics/anthropic-sdk-php/commit/55cc35f45d7dc9c4ab240b2c7ed7a30fca9380c4))
* refactor request options ([1029de6](https://github.com/anthropics/anthropic-sdk-php/commit/1029de68d7ddd43266408acb05da29ffc4b6e93f))
* **refactor:** simplify base page interface ([4a69adf](https://github.com/anthropics/anthropic-sdk-php/commit/4a69adf0342a0be525c6ae4529e167238014d1b1))
* remove `php-http/multipart-stream-builder` as a required dependency ([bd27c94](https://github.com/anthropics/anthropic-sdk-php/commit/bd27c9418359f4d3aa1debe3aea4484299fe3566))
* simplify model initialization ([bc0e44f](https://github.com/anthropics/anthropic-sdk-php/commit/bc0e44f3c7bf20f668a8f840852556e24ad0cf45))

## 0.2.0 (2025-08-27)

Full Changelog: [v0.1.0...v0.2.0](https://github.com/anthropics/anthropic-sdk-php/compare/v0.1.0...v0.2.0)
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The REST API documentation can be found on [docs.anthropic.com](https://docs.ant
<!-- x-release-please-start-version -->

```
composer require "anthropic-ai/sdk 0.2.0"
composer require "anthropic-ai/sdk 0.3.0"
```

<!-- x-release-please-end -->
Expand Down Expand Up @@ -157,7 +157,7 @@ Certain errors will be automatically retried 2 times by default, with a short ex

Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict, 429 Rate Limit, >=500 Internal errors, and timeouts will all be retried by default.

You can use the `max_retries` option to configure or disable this:
You can use the `maxRetries` option to configure or disable this:

```php
<?php
Expand All @@ -175,7 +175,7 @@ $result = $client->messages->create(
maxTokens: 1024,
messages: [MessageParam::with(role: "user", content: "Hello, Claude")],
model: "claude-sonnet-4-20250514",
new RequestOptions(maxRetries: 5),
requestOptions: RequestOptions::with(maxRetries: 5),
);
```

Expand All @@ -187,7 +187,7 @@ $result = $client->messages->create(

You can send undocumented parameters to any endpoint, and read undocumented response properties, like so:

Note: the `extra_` parameters of the same name overrides the documented parameters.
Note: the `extra*` parameters of the same name overrides the documented parameters.

```php
<?php
Expand All @@ -199,7 +199,7 @@ $message = $client->messages->create(
maxTokens: 1024,
messages: [MessageParam::with(role: "user", content: "Hello, Claude")],
model: "claude-sonnet-4-20250514",
new RequestOptions(
requestOptions: RequestOptions::with(
extraQueryParams: ["my_query_parameter" => "value"],
extraBodyParams: ["my_body_parameter" => "value"],
extraHeaders: ["my-header" => "value"],
Expand Down
8 changes: 2 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"$schema": "https://getcomposer.org/schema.json",
"autoload": {
"files": [
"src/Core.php",
"src/Client.php"
],
"files": ["src/Core.php", "src/Client.php"],
"psr-4": {
"Anthropic\\": "src/"
}
Expand All @@ -26,13 +23,11 @@
"preferred-install": "dist",
"sort-packages": true
},
"license": "APACHE-2.0",
"description": "Anthropic PHP SDK",
"name": "anthropic-ai/sdk",
"require": {
"php": "^8.1",
"php-http/discovery": "^1",
"php-http/multipart-stream-builder": "^1",
"psr/http-client": "^1",
"psr/http-client-implementation": "^1",
"psr/http-factory-implementation": "^1",
Expand All @@ -49,6 +44,7 @@
"symfony/http-client": "^7"
},
"scripts": {
"build:docs": "curl --etag-save ./vendor/ag.etags --etag-compare ./vendor/ag.etags --create-dirs --remote-name --output-dir ./vendor/bin --no-progress-meter -- https://github.com/ApiGen/ApiGen/releases/latest/download/apigen.phar && php ./vendor/bin/apigen.phar --output docs -- src",
"lint": "./scripts/lint",
"test": "./scripts/test"
}
Expand Down
3 changes: 1 addition & 2 deletions src/APIErrorObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ final class APIErrorObject implements BaseModel
*/
public function __construct()
{
self::introspect();
$this->unsetOptionalProperties();
$this->initialize();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/AuthenticationError.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ final class AuthenticationError implements BaseModel
*/
public function __construct()
{
self::introspect();
$this->unsetOptionalProperties();
$this->initialize();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Beta/BetaAPIError.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ final class BetaAPIError implements BaseModel
*/
public function __construct()
{
self::introspect();
$this->unsetOptionalProperties();
$this->initialize();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Beta/BetaAuthenticationError.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ final class BetaAuthenticationError implements BaseModel
*/
public function __construct()
{
self::introspect();
$this->unsetOptionalProperties();
$this->initialize();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Beta/BetaBillingError.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ final class BetaBillingError implements BaseModel
*/
public function __construct()
{
self::introspect();
$this->unsetOptionalProperties();
$this->initialize();
}

/**
Expand Down
21 changes: 17 additions & 4 deletions src/Beta/BetaErrorResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
/**
* @phpstan-type beta_error_response = array{
* error: BetaInvalidRequestError|BetaAuthenticationError|BetaBillingError|BetaPermissionError|BetaNotFoundError|BetaRateLimitError|BetaGatewayTimeoutError|BetaAPIError|BetaOverloadedError,
* requestID: string|null,
* type: string,
* }
*/
Expand All @@ -25,24 +26,26 @@ final class BetaErrorResponse implements BaseModel
#[Api(union: BetaError::class)]
public BetaInvalidRequestError|BetaAuthenticationError|BetaBillingError|BetaPermissionError|BetaNotFoundError|BetaRateLimitError|BetaGatewayTimeoutError|BetaAPIError|BetaOverloadedError $error;

#[Api('request_id')]
public ?string $requestID;

/**
* `new BetaErrorResponse()` is missing required properties by the API.
*
* To enforce required parameters use
* ```
* BetaErrorResponse::with(error: ...)
* BetaErrorResponse::with(error: ..., requestID: ...)
* ```
*
* Otherwise ensure the following setters are called
*
* ```
* (new BetaErrorResponse)->withError(...)
* (new BetaErrorResponse)->withError(...)->withRequestID(...)
* ```
*/
public function __construct()
{
self::introspect();
$this->unsetOptionalProperties();
$this->initialize();
}

/**
Expand All @@ -52,10 +55,12 @@ public function __construct()
*/
public static function with(
BetaInvalidRequestError|BetaAuthenticationError|BetaBillingError|BetaPermissionError|BetaNotFoundError|BetaRateLimitError|BetaGatewayTimeoutError|BetaAPIError|BetaOverloadedError $error,
?string $requestID,
): self {
$obj = new self;

$obj->error = $error;
$obj->requestID = $requestID;

return $obj;
}
Expand All @@ -68,4 +73,12 @@ public function withError(

return $obj;
}

public function withRequestID(?string $requestID): self
{
$obj = clone $this;
$obj->requestID = $requestID;

return $obj;
}
}
3 changes: 1 addition & 2 deletions src/Beta/BetaGatewayTimeoutError.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ final class BetaGatewayTimeoutError implements BaseModel
*/
public function __construct()
{
self::introspect();
$this->unsetOptionalProperties();
$this->initialize();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Beta/BetaInvalidRequestError.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ final class BetaInvalidRequestError implements BaseModel
*/
public function __construct()
{
self::introspect();
$this->unsetOptionalProperties();
$this->initialize();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Beta/BetaNotFoundError.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ final class BetaNotFoundError implements BaseModel
*/
public function __construct()
{
self::introspect();
$this->unsetOptionalProperties();
$this->initialize();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Beta/BetaOverloadedError.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ final class BetaOverloadedError implements BaseModel
*/
public function __construct()
{
self::introspect();
$this->unsetOptionalProperties();
$this->initialize();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Beta/BetaPermissionError.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ final class BetaPermissionError implements BaseModel
*/
public function __construct()
{
self::introspect();
$this->unsetOptionalProperties();
$this->initialize();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Beta/BetaRateLimitError.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ final class BetaRateLimitError implements BaseModel
*/
public function __construct()
{
self::introspect();
$this->unsetOptionalProperties();
$this->initialize();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Beta/Files/DeletedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ final class DeletedFile implements BaseModel
*/
public function __construct()
{
self::introspect();
$this->unsetOptionalProperties();
$this->initialize();
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/Beta/Files/FileDeleteParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
/**
* Delete File.
*
* @see Anthropic\Beta\Files->delete
*
* @phpstan-type file_delete_params = array{betas?: list<AnthropicBeta::*|string>}
*/
final class FileDeleteParams implements BaseModel
Expand All @@ -31,8 +33,7 @@ final class FileDeleteParams implements BaseModel

public function __construct()
{
self::introspect();
$this->unsetOptionalProperties();
$this->initialize();
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/Beta/Files/FileListParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
/**
* List Files.
*
* @see Anthropic\Beta\Files->list
*
* @phpstan-type file_list_params = array{
* afterID?: string,
* beforeID?: string,
Expand Down Expand Up @@ -56,8 +58,7 @@ final class FileListParams implements BaseModel

public function __construct()
{
self::introspect();
$this->unsetOptionalProperties();
$this->initialize();
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Beta/Files/FileMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ final class FileMetadata implements BaseModel
*/
public function __construct()
{
self::introspect();
$this->unsetOptionalProperties();
$this->initialize();
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/Beta/Files/FileRetrieveMetadataParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
/**
* Get File Metadata.
*
* @see Anthropic\Beta\Files->retrieveMetadata
*
* @phpstan-type file_retrieve_metadata_params = array{
* betas?: list<AnthropicBeta::*|string>
* }
Expand All @@ -33,8 +35,7 @@ final class FileRetrieveMetadataParams implements BaseModel

public function __construct()
{
self::introspect();
$this->unsetOptionalProperties();
$this->initialize();
}

/**
Expand Down
Loading