PHPackages                             aisdk/bedrock - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. aisdk/bedrock

ActiveLibrary

aisdk/bedrock
=============

Official Amazon Bedrock provider for the PHP AI SDK.

v0.8.1(1mo ago)024MITPHPPHP ^8.3CI passing

Since Jul 11Pushed 1mo agoCompare

[ Source](https://github.com/phpaisdk/bedrock)[ Packagist](https://packagist.org/packages/aisdk/bedrock)[ Docs](https://github.com/phpaisdk/bedrock)[ RSS](/packages/aisdk-bedrock/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (7)Dependencies (8)Versions (8)Used By (0)

aisdk/bedrock
=============

[](#aisdkbedrock)

[![GitHub Workflow Status](https://camo.githubusercontent.com/92f284414421bac9a95ce0d6e824400b47044250b0b232ed1bfcdd8e030e3fa4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f706870616973646b2f626564726f636b2f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d5465737473)](https://github.com/phpaisdk/bedrock/actions)[![Total Downloads](https://camo.githubusercontent.com/eec73852d93b9ea36a0f5df0af6d419781b234913d26481cca10c2d06deef8c6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616973646b2f626564726f636b)](https://packagist.org/packages/aisdk/bedrock)[![Latest Version](https://camo.githubusercontent.com/d728e31b1ca23ec94c0c3c75df5de63a5b227d61125c03098d897df762b0bb44/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616973646b2f626564726f636b)](https://packagist.org/packages/aisdk/bedrock)[![License](https://camo.githubusercontent.com/3f0715673af75b5b981316b52b32d41093f83412264097cb184a1f644bb8d9ff/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616973646b2f626564726f636b)](https://packagist.org/packages/aisdk/bedrock)[![Why PHP in 2026](https://camo.githubusercontent.com/d2b9305e630caf7daae4ca023de39ece0b885c37461629d42961533f00868b76/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5768795f5048502d696e5f323032362d3741383645383f7374796c653d666c61742d737175617265266c6162656c436f6c6f723d313831383162)](https://whyphp.dev)

---

Official Amazon Bedrock provider for the framework-agnostic PHP AI SDK. Anthropic models use native **InvokeModel** by default, other text models use **Converse**, and images and embeddings use **InvokeModel**. Bedrock's OpenAI-compatible Chat Completions and Responses surfaces are also available.

Installation
------------

[](#installation)

```
composer require aisdk/bedrock
```

Basic Usage
-----------

[](#basic-usage)

```
use AiSdk\Bedrock;
use AiSdk\Generate;

$result = Generate::text()
    ->model(Bedrock::model('anthropic.claude-3-5-sonnet-20240620-v1:0'))
    ->prompt('Explain closures in PHP.')
    ->run();

echo $result->text;
```

Bedrock model IDs pass through unchanged and do not need to be registered. This package does not ship a model inventory; the SDK performs internal adapter validation before Bedrock validates support for the selected model in the current account and region.

API surfaces
------------

[](#api-surfaces)

Anthropic model IDs automatically use the native Messages format through `InvokeModel`. You can override that choice per request:

```
$result = Generate::text('Explain this code.')
    ->model(Bedrock::model('anthropic.claude-3-5-haiku-20241022-v1:0'))
    ->providerOptions('amazon-bedrock', ['api' => 'converse'])
    ->run();
```

Supported values are `converse`, `invoke`, `mantle_chat`, and `mantle_responses`. Mantle selections automatically use the regional `bedrock-mantle.{region}.api.aws/v1` endpoint unless you configured a custom base URL. You can also set `api` in `Bedrock::create()` to choose one surface for that provider instance.

Streaming
---------

[](#streaming)

```
foreach (Generate::text('Tell me a story.')->model(Bedrock::model('anthropic.claude-3-haiku-20240307-v1:0'))->stream()->chunks() as $chunk) {
    echo $chunk;
}
```

Image generation
----------------

[](#image-generation)

```
$image = Generate::image('A studio product photograph')
    ->model(Bedrock::model('amazon.nova-canvas-v1:0'))
    ->aspectRatio('16:9')
    ->run();
```

Embeddings
----------

[](#embeddings)

Amazon Titan Text Embeddings V1/V2 and Cohere Embed v3/v4 use their native Bedrock request and response formats:

```
$embedding = Generate::embedding('A document to index')
    ->model(Bedrock::model('cohere.embed-v4:0'))
    ->dimensions(512)
    ->providerOptions('amazon-bedrock', [
        'input_type' => 'search_document',
    ])
    ->run();

$vector = $embedding->output->vector;
```

Cohere requires an `input_type`: `search_document`, `search_query`, `classification`, or `clustering`. Cohere v4 supports 256, 512, 1024, or 1536 dimensions; Cohere v3 has a fixed output size.

Titan V2 supports 256, 512, or 1024 dimensions and its `normalize` option can be passed through `providerOptions()`. Titan V1 has a fixed output size. Bedrock accepts one Titan text per invocation, so the SDK invokes the model once per input when you pass a list.

Other Bedrock embedding model families are rejected because their native wire formats are not interchangeable.

Video generation
----------------

[](#video-generation)

Amazon Nova Reel writes generated videos to your S3 bucket.

```
$result = Generate::video('A cinematic forest flyover')
    ->model(Bedrock::model('amazon.nova-reel-v1:1'))
    ->resolution('1280x720')
    ->duration(6)
    ->providerOptions('amazon-bedrock', ['outputS3Uri' => 's3://my-video-bucket/outputs'])
    ->run(timeout: 1200);
```

Live voice with Nova 2 Sonic
----------------------------

[](#live-voice-with-nova-2-sonic)

Nova Sonic uses Bedrock's full-duplex `InvokeModelWithBidirectionalStream`operation. Install the ready-made transport package for HTTP/2:

```
composer require aisdk/transport
```

```
use AiSdk\Bedrock;
use AiSdk\Live;
use AiSdk\Live\AudioDelta;
use AiSdk\Live\TranscriptDelta;
use AiSdk\Transport;

Bedrock::create([
    'accessKeyId' => getenv('AWS_ACCESS_KEY_ID'),
    'secretAccessKey' => getenv('AWS_SECRET_ACCESS_KEY'),
    'sessionToken' => getenv('AWS_SESSION_TOKEN') ?: null,
    'region' => 'us-east-1',
]);

$session = Live::voice()
    ->model(Bedrock::model('amazon.nova-2-sonic-v1:0'))
    ->instructions('Be concise and helpful.')
    ->voice('matthew')
    ->inputAudioFormat('pcm16')
    ->outputAudioFormat('pcm16')
    ->connect(Transport::auto());

$session->sendAudio($pcm16Chunk);

foreach ($session->events() as $event) {
    if ($event instanceof AudioDelta) {
        playPcm16($event->bytes);
    }

    if ($event instanceof TranscriptDelta) {
        echo $event->delta;
    }
}

$session->close();
```

The input is signed 16-bit little-endian linear PCM. Input sample rate defaults to 16 kHz and output defaults to 24 kHz. Provider-specific Nova settings can be overridden without expanding the shared core API:

```
$session = Live::voice()
    ->model(Bedrock::model('amazon.nova-2-sonic-v1:0'))
    ->turnDetection('medium')
    ->providerOptions('amazon-bedrock', [
        'inferenceConfiguration' => [
            'maxTokens' => 2048,
            'temperature' => 0.7,
            'topP' => 0.9,
        ],
        'turnDetectionConfiguration' => [
            'endpointingSensitivity' => 'MEDIUM',
        ],
        'inputAudioConfiguration' => [
            'sampleRateHertz' => 16000,
        ],
        'outputAudioConfiguration' => [
            'sampleRateHertz' => 24000,
        ],
    ])
    ->connect(Transport::http2());
```

`AiSdk\Live` and its transport contracts are provided by `aisdk/core`, so the ready-made transport is optional. Without `aisdk/transport`, pass an application transport that supports core's `Http2Endpoint`:

```
use App\Ai\AppHttp2Transport;

$session = Live::voice()
    ->model(Bedrock::model('amazon.nova-2-sonic-v1:0'))
    ->connect(new AppHttp2Transport());
```

The custom transport only moves full-duplex HTTP/2 byte frames and implements half-closing. AWS signing, EventStream framing, and Nova event semantics remain inside `aisdk/bedrock`.

`sendText()` provides Nova's cross-modal text input. Tools registered through `->tools()` are sent in `promptStart`; tool calls are normalized by core and their results are returned with Nova's required tool event sequence.

Nova Sonic continuously applies server turn detection, so it does not expose manual `commitAudio()`, `clearAudio()`, `requestResponse()`, or `cancelResponse()` actions. Bedrock also does not expose dedicated `Live::transcribe()` or `Live::translate()` sessions; voice sessions still emit normalized transcription events.

The legacy `amazon.nova-sonic-v1:0` model remains protocol-compatible for audio sessions, but it does not support Nova 2's cross-modal `sendText()` or configurable endpointing sensitivity.

Bedrock bearer API keys cannot authenticate bidirectional streaming. Live uses standard AWS credentials with SigV4. Explicit keys work without the AWS SDK; profiles and the default credential chain require `aws/aws-sdk-php`.

Authentication
--------------

[](#authentication)

Bedrock supports the full range of AWS authentication:

- **Bedrock API key** (bearer token) — no signing, no AWS SDK needed.
- **Explicit static access keys** — SigV4 signing (works standalone).
- **Named profile** — SSO + shared config/credentials files.
- **Default AWS credential chain** — env vars, shared config, SSO, IMDS (EC2), ECS container credentials, assume-role, and web-identity.

Profiles and the default chain use the official [`aws/aws-sdk-php`](https://github.com/aws/aws-sdk-php)credential providers. Install it to enable them:

```
composer require aws/aws-sdk-php
```

Bearer tokens and explicit static keys work without it for ordinary Bedrock requests. Live voice specifically requires SigV4 credentials and does not support bearer tokens.

VariableDescription`AWS_BEARER_TOKEN_BEDROCK`Bedrock API key (bearer token)`AWS_ACCESS_KEY_ID`AWS access key (SigV4)`AWS_SECRET_ACCESS_KEY`AWS secret key (SigV4)`AWS_SESSION_TOKEN`Optional session token (SigV4)`AWS_PROFILE`Named profile for SSO / shared config`AWS_REGION` / `AWS_DEFAULT_REGION`Region (defaults to `us-east-1`)```
// Bedrock API key
Bedrock::create(['apiKey' => 'bedrock-...', 'region' => 'us-east-1']);

// Explicit static credentials (SigV4)
Bedrock::create([
    'accessKeyId' => 'AKIA...',
    'secretAccessKey' => '...',
    'region' => 'us-east-1',
]);

// Named profile (SSO / shared config)
Bedrock::create(['profile' => 'my-sso-profile', 'region' => 'us-east-1']);

// Default credential chain (env, config, SSO, IMDS, ECS, assume-role, web-identity)
Bedrock::create(['region' => 'us-east-1']);
```

Reasoning
---------

[](#reasoning)

```
use AiSdk\Reasoning;

$result = Generate::text('Explain the tradeoff.')
    ->model(Bedrock::model('anthropic.claude-3-7-sonnet-20250219-v1:0'))
    ->reasoning(Reasoning::budget(2048))
    ->run();
```

Testing
-------

[](#testing)

```
composer test
```

The default suite is fixture- and conformance-based. Credentialed Live network verification is separate and is not run by `composer test`.

Documentation
-------------

[](#documentation)

- [PHP AI SDK documentation](https://phpaisdk.com/docs)
- [Amazon Bedrock documentation](https://phpaisdk.com/docs/bedrock)

Community
---------

[](#community)

- [Contributing](https://github.com/phpaisdk/.github/blob/main/CONTRIBUTING.md)
- [Support](https://github.com/phpaisdk/.github/blob/main/SUPPORT.md)
- For private security reports, email .

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance90

Actively maintained with recent releases

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

7

Last Release

47d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ef29d1962da41e7526023f215cf844494e209b2fd163742084cb919a3b508021?d=identicon)[aisdk](/maintainers/aisdk)

---

Top Contributors

[![RanaMoizHaider](https://avatars.githubusercontent.com/u/58527494?v=4)](https://github.com/RanaMoizHaider "RanaMoizHaider (13 commits)")

---

Tags

awsaibedrockclaudellmaisdk

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/aisdk-bedrock/health.svg)

```
[![Health](https://phpackages.com/badges/aisdk-bedrock/health.svg)](https://phpackages.com/packages/aisdk-bedrock)
```

###  Alternatives

[cognesy/instructor-php

The complete AI toolkit for PHP: unified LLM API, structured outputs, agents, and coding agent control

326133.2k1](/packages/cognesy-instructor-php)[helgesverre/toon

Token-Oriented Object Notation - A compact data format for reducing token consumption when sending structured data to LLMs

130283.8k41](/packages/helgesverre-toon)[mozex/anthropic-laravel

Laravel integration for the Anthropic API: facade, config publishing, install command, testing fakes, messages, streaming, tool use, thinking, and batches.

74410.0k1](/packages/mozex-anthropic-laravel)[mozex/anthropic-php

PHP client for the Anthropic API: messages, streaming, tool use, thinking, web search, code execution, batches, and more.

48688.4k21](/packages/mozex-anthropic-php)[sbsaga/toon

🧠 TOON for Laravel — a compact, human-readable, and token-efficient data format for AI prompts &amp; LLM contexts. Perfect for ChatGPT, Gemini, Claude, Mistral, and OpenAI integrations (JSON ⇄ TOON).

6877.8k](/packages/sbsaga-toon)[claude-php/claude-php-sdk-laravel

Laravel integration for the Claude PHP SDK - Anthropic Claude API

5229.7k](/packages/claude-php-claude-php-sdk-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
