Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.40.0"
".": "0.41.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: 130
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic/anthropic-f89e311096c42998ada5ab5580a2a3b0519265f1c005af625be7a0d11ad49d3c.yml
openapi_spec_hash: d2deb0fef6a15bf53cc6c53f07973a54
config_hash: 44bd45774e5a06742c1fb8f0e20e7864
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic/anthropic-891ba7f96c3771e1e3ba6cb37fe8cb6d8615b8a06b6c435d9df66f4aad144bb4.yml
openapi_spec_hash: ee61c0ee103fce12d7b9a73ec21762c0
config_hash: c07d90e7ac3e3b26d1d4b41323cd0428
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# Changelog

## 0.41.0 (2026-08-06)

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

### Features

* **api:** add `mid-conversation-tool-changes-2026-07-01` beta ([6cdad3e](https://github.com/anthropics/anthropic-sdk-php/commit/6cdad3ee73de292dc6b5770fa7a53146da48cc79))
* **api:** add support for session budgets, advisor tool, pinned inference location and skills auto-loading from GitHub ([37531b2](https://github.com/anthropics/anthropic-sdk-php/commit/37531b2d4f3d777cd24041f8bcb5d57393097695))


### Bug Fixes

* **client:** improve http-discovery error message ([3be4d22](https://github.com/anthropics/anthropic-sdk-php/commit/3be4d22c0ab056f5e430ca2522b1e8c7e3d326b6))


### Chores

* **api:** remove retired Claude Opus 4.1 models ([625f364](https://github.com/anthropics/anthropic-sdk-php/commit/625f364a5fae71724fb3525c47ef9695ccaac3f0))
* **docs:** small updates to descriptions ([a2c07ea](https://github.com/anthropics/anthropic-sdk-php/commit/a2c07ea7e44d72f1ecbed408e5b21bd064fd6281))
* **docs:** updates to a few documentation strings ([e497b81](https://github.com/anthropics/anthropic-sdk-php/commit/e497b81baa693d39596db41c9ab2832a480619ea))

## 0.40.0 (2026-07-24)

Full Changelog: [v0.39.0...v0.40.0](https://github.com/anthropics/anthropic-sdk-php/compare/v0.39.0...v0.40.0)
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ Full documentation is available at **[platform.claude.com/docs/en/api/sdks/php](
<!-- x-release-please-start-version -->

```sh
composer require "anthropic-ai/sdk:^0.40.0"
composer require "anthropic-ai/sdk:^0.41.0"
```

<!-- x-release-please-end -->

The SDK needs a [PSR-18](https://www.php-fig.org/psr/psr-18/) HTTP client. If you don't have one installed, add Guzzle:

```sh
composer require guzzlehttp/guzzle
```

## Getting started

```php
Expand Down
6 changes: 5 additions & 1 deletion examples/beta/agents_streaming_deltas.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Anthropic\Beta\Sessions\Events\ManagedAgentsSessionErrorEvent;
use Anthropic\Beta\Sessions\Events\ManagedAgentsSessionStatusIdleEvent;
use Anthropic\Beta\Sessions\Events\ManagedAgentsSpanModelRequestEndEvent;
use Anthropic\Beta\Sessions\Events\ManagedAgentsTextBlock;
use Anthropic\Client;
use Anthropic\Lib\Sessions\EventAccumulator;

Expand Down Expand Up @@ -64,7 +65,10 @@

function render_text(ManagedAgentsAgentMessageEvent $message): string
{
return implode('', array_map(fn ($block) => $block->text, $message->content));
return implode('', array_map(
fn ($block) => $block instanceof ManagedAgentsTextBlock ? $block->text : '',
$message->content,
));
}

// One snapshot per event id: previews grow delta by delta, then the buffered
Expand Down
23 changes: 14 additions & 9 deletions src/Bedrock/MantleClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Anthropic\Core\BaseClient;
use Anthropic\Core\Util;
use Anthropic\RequestOptions;
use Http\Discovery\Exception\NotFoundException;
use Http\Discovery\Psr17FactoryDiscovery;
use Http\Discovery\Psr18ClientDiscovery;
use Psr\Http\Message\RequestInterface;
Expand Down Expand Up @@ -75,15 +76,19 @@ public function __construct(
useBearerAuth: true,
);

$options = RequestOptions::parse(
RequestOptions::with(
uriFactory: Psr17FactoryDiscovery::findUriFactory(),
streamFactory: Psr17FactoryDiscovery::findStreamFactory(),
requestFactory: Psr17FactoryDiscovery::findRequestFactory(),
transporter: Psr18ClientDiscovery::find(),
),
$requestOptions,
);
try {
$options = RequestOptions::parse(
RequestOptions::with(
uriFactory: Psr17FactoryDiscovery::findUriFactory(),
streamFactory: Psr17FactoryDiscovery::findStreamFactory(),
requestFactory: Psr17FactoryDiscovery::findRequestFactory(),
transporter: Psr18ClientDiscovery::find(),
),
$requestOptions,
);
} catch (NotFoundException $e) {
throw new NotFoundException("No PSR-18 HTTP client or PSR-17 factory found. If you don't have one in your project, run `composer require guzzlehttp/guzzle`.", previous: $e);
}

parent::__construct(
headers: [
Expand Down
91 changes: 91 additions & 0 deletions src/Beta/Agents/BetaManagedAgentsAdvisor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

declare(strict_types=1);

namespace Anthropic\Beta\Agents;

use Anthropic\Beta\Agents\BetaManagedAgentsAdvisor\Type;
use Anthropic\Core\Attributes\Required;
use Anthropic\Core\Concerns\SdkModel;
use Anthropic\Core\Contracts\BaseModel;

/**
* Platform advisor roster entry: a model the session's primary thread may consult mid-turn.
*
* @phpstan-type BetaManagedAgentsAdvisorShape = array{
* model: string, type: Type|value-of<Type>
* }
*/
final class BetaManagedAgentsAdvisor implements BaseModel
{
/** @use SdkModel<BetaManagedAgentsAdvisorShape> */
use SdkModel;

/**
* The advisor model id.
*/
#[Required]
public string $model;

/** @var value-of<Type> $type */
#[Required(enum: Type::class)]
public string $type;

/**
* `new BetaManagedAgentsAdvisor()` is missing required properties by the API.
*
* To enforce required parameters use
* ```
* BetaManagedAgentsAdvisor::with(model: ..., type: ...)
* ```
*
* Otherwise ensure the following setters are called
*
* ```
* (new BetaManagedAgentsAdvisor)->withModel(...)->withType(...)
* ```
*/
public function __construct()
{
$this->initialize();
}

/**
* Construct an instance from the required parameters.
*
* You must use named parameters to construct any parameters with a default value.
*
* @param Type|value-of<Type> $type
*/
public static function with(string $model, Type|string $type): self
{
$self = new self;

$self['model'] = $model;
$self['type'] = $type;

return $self;
}

/**
* The advisor model id.
*/
public function withModel(string $model): self
{
$self = clone $this;
$self['model'] = $model;

return $self;
}

/**
* @param Type|value-of<Type> $type
*/
public function withType(Type|string $type): self
{
$self = clone $this;
$self['type'] = $type;

return $self;
}
}
10 changes: 10 additions & 0 deletions src/Beta/Agents/BetaManagedAgentsAdvisor/Type.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Anthropic\Beta\Agents\BetaManagedAgentsAdvisor;

enum Type: string
{
case ADVISOR = 'advisor';
}
4 changes: 2 additions & 2 deletions src/Beta/Agents/BetaManagedAgentsCustomToolParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class BetaManagedAgentsCustomToolParams implements BaseModel
use SdkModel;

/**
* Description of what the tool does, shown to the agent to help it decide when to use the tool. 1-4096 characters.
* Description of what the tool does, shown to the agent to help it decide when to use the tool.
*/
#[Required]
public string $description;
Expand Down Expand Up @@ -98,7 +98,7 @@ public static function with(
}

/**
* Description of what the tool does, shown to the agent to help it decide when to use the tool. 1-4096 characters.
* Description of what the tool does, shown to the agent to help it decide when to use the tool.
*/
public function withDescription(string $description): self
{
Expand Down
20 changes: 20 additions & 0 deletions src/Beta/Agents/BetaManagedAgentsModelConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* @phpstan-type BetaManagedAgentsModelConfigShape = array{
* id: string|BetaManagedAgentsModel|value-of<BetaManagedAgentsModel>,
* effort?: EffortShape|null,
* inferenceGeo?: string|null,
* speed?: null|Speed|value-of<Speed>,
* }
*/
Expand All @@ -46,6 +47,12 @@ final class BetaManagedAgentsModelConfig implements BaseModel
#[Optional(union: Effort::class)]
public BetaManagedAgentsEffortLow|BetaManagedAgentsEffortMedium|BetaManagedAgentsEffortHigh|BetaManagedAgentsEffortXhigh|BetaManagedAgentsEffortMax|null $effort;

/**
* Geographic region for model inference. When unset, requests fall through to the workspace's default_inference_geo.
*/
#[Optional('inference_geo')]
public ?string $inferenceGeo;

/**
* Inference speed mode. `fast` provides significantly faster output token generation at premium pricing. Not all models support `fast`; invalid combinations are rejected at create time.
*
Expand Down Expand Up @@ -85,13 +92,15 @@ public function __construct()
public static function with(
BetaManagedAgentsModel|string $id,
BetaManagedAgentsEffortLow|array|BetaManagedAgentsEffortMedium|BetaManagedAgentsEffortHigh|BetaManagedAgentsEffortXhigh|BetaManagedAgentsEffortMax|null $effort = null,
?string $inferenceGeo = null,
Speed|string|null $speed = null,
): self {
$self = new self;

$self['id'] = $id;

null !== $effort && $self['effort'] = $effort;
null !== $inferenceGeo && $self['inferenceGeo'] = $inferenceGeo;
null !== $speed && $self['speed'] = $speed;

return $self;
Expand Down Expand Up @@ -126,6 +135,17 @@ public function withEffort(
return $self;
}

/**
* Geographic region for model inference. When unset, requests fall through to the workspace's default_inference_geo.
*/
public function withInferenceGeo(string $inferenceGeo): self
{
$self = clone $this;
$self['inferenceGeo'] = $inferenceGeo;

return $self;
}

/**
* Inference speed mode. `fast` provides significantly faster output token generation at premium pricing. Not all models support `fast`; invalid combinations are rejected at create time.
*
Expand Down
20 changes: 20 additions & 0 deletions src/Beta/Agents/BetaManagedAgentsModelConfigParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* @phpstan-type BetaManagedAgentsModelConfigParamsShape = array{
* id: string|BetaManagedAgentsModel|value-of<BetaManagedAgentsModel>,
* effort?: EffortShape|null,
* inferenceGeo?: string|null,
* speed?: null|Speed|value-of<Speed>,
* }
*/
Expand All @@ -47,6 +48,12 @@ final class BetaManagedAgentsModelConfigParams implements BaseModel
#[Optional(union: Effort::class, nullable: true)]
public BetaManagedAgentsEffortLow|BetaManagedAgentsEffortMedium|BetaManagedAgentsEffortHigh|BetaManagedAgentsEffortXhigh|BetaManagedAgentsEffortMax|string|null $effort;

/**
* Geographic region for model inference. When unset, requests fall through to the workspace's default_inference_geo. On update, `model` is whole-object replacement — omitting inference_geo clears it.
*/
#[Optional('inference_geo', nullable: true)]
public ?string $inferenceGeo;

/**
* Inference speed mode. `fast` provides significantly faster output token generation at premium pricing. Not all models support `fast`; invalid combinations are rejected at create time.
*
Expand Down Expand Up @@ -86,13 +93,15 @@ public function __construct()
public static function with(
BetaManagedAgentsModel|string $id,
BetaManagedAgentsEffortLevel|BetaManagedAgentsEffortLow|array|BetaManagedAgentsEffortMedium|BetaManagedAgentsEffortHigh|BetaManagedAgentsEffortXhigh|BetaManagedAgentsEffortMax|string|null $effort = null,
?string $inferenceGeo = null,
Speed|string|null $speed = null,
): self {
$self = new self;

$self['id'] = $id;

null !== $effort && $self['effort'] = $effort;
null !== $inferenceGeo && $self['inferenceGeo'] = $inferenceGeo;
null !== $speed && $self['speed'] = $speed;

return $self;
Expand Down Expand Up @@ -127,6 +136,17 @@ public function withEffort(
return $self;
}

/**
* Geographic region for model inference. When unset, requests fall through to the workspace's default_inference_geo. On update, `model` is whole-object replacement — omitting inference_geo clears it.
*/
public function withInferenceGeo(?string $inferenceGeo): self
{
$self = clone $this;
$self['inferenceGeo'] = $inferenceGeo;

return $self;
}

/**
* Inference speed mode. `fast` provides significantly faster output token generation at premium pricing. Not all models support `fast`; invalid combinations are rejected at create time.
*
Expand Down
Loading