Download the PHP package revolution/laravel-amazon-bedrock without Composer
On this page you can find all versions of the php package revolution/laravel-amazon-bedrock. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download revolution/laravel-amazon-bedrock
More information about revolution/laravel-amazon-bedrock
Files in revolution/laravel-amazon-bedrock
Package laravel-amazon-bedrock
Short Description Amazon Bedrock driver for for Laravel AI SDK
License MIT
Informations about the package laravel-amazon-bedrock
Amazon Bedrock driver for Laravel AI SDK
[!CAUTION] With the release of the Laravel AI SDK v1.0, the official SDK is now sufficient for Bedrock, so this package is being discontinued.
Overview
An Amazon Bedrock driver for the Laravel AI SDK, enabling text generation, streaming, tool use (function calling), structured output, file attachments, embeddings, image generation, audio (TTS), and reranking via models on AWS Bedrock.
| Feature | API key | Supported Models |
|---|---|---|
| Text, Streaming | ✅ | Anthropic Claude, Amazon Nova, and most Bedrock models (all via Converse API) |
| Tool Use | ✅ | |
| Structured Output | ✅ | |
| File Attachments | ✅ | Image, document, audio, and video attachments via Converse API (model support varies) |
| Images | ✅ | Stability AI models (default), Amazon Nova Canvas (deprecated). |
| Audio(TTS) | ⚠️ | Amazon Polly (generative, neural, long-form, standard engines) |
| Transcription(STT) | ❌ | Not supported |
| Embeddings | ✅ | Amazon Titan Embeddings V2 (default), Cohere Embed English/Multilingual V3, Cohere Embed V4 (batch support). |
| Reranking | ⚠️ | Cohere Rerank 3.5, Amazon Rerank 1.0 |
| Files | ✅️ | Local file attachments supported via text generation; server-side upload and fromId() not supported |
[!NOTE] ⚠️ in this table means the feature is not available with only a Bedrock API key. It does not mean the feature itself is unsupported.
[!NOTE] Laravel AI SDK v0.6.3 added official Bedrock support for Text, Image, and Embeddings using a Bedrock API key. This package continues to be published because it also supports Audio (TTS via Amazon Polly) and Reranking — features not available through the official integration.
- Authentication: Bedrock API key, AWS IAM credentials (SigV4), or default AWS credential chain (IAM roles, instance profiles, etc.).
- Failover: Supports the AI SDK's multi-provider failover. Rate limit (429), overload (503, 529), and credit errors are mapped to failoverable exceptions.
- Cache Control: Ephemeral cache always enabled on system prompts via the Bedrock Converse API.
- Unified API: All models — Anthropic Claude, Amazon Nova, Meta Llama, Mistral, and more — are routed through the Bedrock Converse API for a consistent interface.
Requirements
- PHP >= 8.3
- Laravel >= 12.x
Installation
Configuration
Add the amazon-bedrock driver to config/ai.php:
Option 1: Bedrock API Key
The Bedrock API key is obtained from the AWS Management Console.
[!WARNING] The Bedrock API key can only be used with the Bedrock Runtime API. It cannot be used with
bedrock-agent-runtime(reranking) or Amazon Polly (audio/TTS). Use SigV4 or the default AWS credential chain for these features.
Option 2: AWS IAM Credentials (SigV4)
Use AWS access key and secret key with Signature Version 4 signing:
Option 3: Default AWS Credential Chain (IAM Roles)
For EC2 instances, ECS tasks, Lambda functions, or any environment with IAM roles — omit key and secret to use the default AWS credential provider chain:
The default credential chain automatically resolves credentials from environment variables, shared credentials files (~/.aws/credentials), ECS task roles, EC2 instance profiles, and more.
Optional config keys
| Key | Description | Default |
|---|---|---|
secret |
AWS secret access key (SigV4) | — |
token |
AWS session token (SigV4) | — |
timeout |
HTTP request timeout in seconds | 30 |
max_tokens |
Default max tokens per request | 8096 |
models.text.default |
Default text model | global.anthropic.claude-sonnet-5 |
models.text.cheapest |
Cheapest text model | global.anthropic.claude-haiku-4-5-20251001-v1:0 |
models.text.smartest |
Smartest text model | global.anthropic.claude-opus-5 |
models.embeddings.default |
Default embeddings model | amazon.titan-embed-text-v2:0 |
models.embeddings.dimensions |
Default embedding dimensions | 1024 |
models.image.default |
Default image model | stability.stable-image-core-v1:1 |
models.audio.default |
Default audio (TTS) engine | generative |
models.reranking.default |
Default reranking model | cohere.rerank-v3-5:0 |
Text Generation
Agent Class
Create an agent class using the Artisan command:
Anonymous Agent
For quick interactions without a dedicated class:
Streaming
Or iterate through the events manually:
Tool Use (Function Calling)
Define tools that Claude can invoke during generation:
Use the tool with an agent:
Or with an anonymous agent:
Tool calls also work with streaming — the SDK automatically executes tool calls and continues the conversation until the model produces a final text response.
File Attachments
Attach images, documents, audio, and video files to your prompts using the attachments parameter. The Bedrock Converse API handles the attachment blocks — actual format support varies by model (e.g., Anthropic Claude supports images and documents only).
Supported attachment types: Image, Document, Audio (via Laravel\Ai\Files\*). Video attachments are supported through Illuminate\Http\UploadedFile.
[!NOTE] Server-side file upload (
Document::fromPath()->put()) and reuse by ID (Document::fromId()) are not supported on Bedrock.
Conversation History
Maintain multi-turn conversations by implementing the Conversational interface in your agent class. The messages() method should return the previous conversation messages, which will be automatically included in each prompt:
Automatic Conversation Storage with RemembersConversations
For fully automatic conversation persistence (no manual messages() implementation needed), use the RemembersConversations trait. This requires the AI SDK database tables — run php artisan vendor:publish --provider="Laravel\Ai\AiServiceProvider" && php artisan migrate first.
Start a new conversation for a user:
Continue an existing conversation:
The Bedrock driver automatically includes conversation history in Bedrock Converse API requests, so all supported models benefit from multi-turn conversation context.
Structured Output
Get structured (typed) responses from Claude using the HasStructuredOutput interface:
Or with an anonymous structured agent:
Under the hood, the driver creates a synthetic tool (output_structured_data) that forces the model to return data matching your schema. This approach is compatible with all models on Bedrock via the Converse API.
Converse API (All Models)
All text generation and streaming is routed through the Bedrock Converse API, including Anthropic Claude models. This gives a unified interface to Anthropic Claude, Amazon Nova, Meta Llama, Mistral, Cohere, DeepSeek, and other models available on Bedrock.
Streaming, tool use, structured output, and file attachments work with models that support those features. See the Bedrock supported models table for feature availability per model.
Provider Options
To pass Bedrock-specific options such as anthropic_version, implement HasProviderOptions:
Supported provider options:
| Option | Description | Default |
|---|---|---|
top_k |
Top-K sampling parameter | — |
top_p |
Top-P (nucleus) sampling parameter | — |
additionalModelRequestFields |
Converse API additional model parameters | — |
Agent Configuration
Configure text generation options using PHP attributes:
Image Generation
Generate images using Stability AI models (default) or Amazon Nova Canvas:
Available Stability AI models (all require us-west-2 region):
[!NOTE] All Stability AI image models are available in
us-west-2only. ConfigureAWS_DEFAULT_REGION=us-west-2when using these models.
Image Editing with Stability AI
Stability AI Image Services editing models are also supported via the attachments() method. Pass an input image and use an editing model to transform it:
Available Stability AI editing models (all available in us-east-1, us-east-2, us-west-2):
| Model ID | Description |
|---|---|
stability.stable-image-inpaint-v1:0 |
Inpaint — fill/replace selected areas |
stability.stable-outpaint-v1:0 |
Outpaint — expand the image beyond its borders |
stability.stable-image-erase-object-v1:0 |
Erase — remove objects from an image |
stability.stable-image-remove-background-v1:0 |
Remove background |
stability.stable-image-search-replace-v1:0 |
Search and Replace — replace a described object |
stability.stable-image-search-recolor-v1:0 |
Search and Recolor — change an object's color |
stability.stable-image-style-guide-v1:0 |
Style Guide — apply a style reference image |
stability.stable-style-transfer-v1:0 |
Style Transfer — transfer an art style |
stability.stable-image-control-sketch-v1:0 |
Control Sketch — generate from a sketch |
stability.stable-image-control-structure-v1:0 |
Control Structure — follow a structural guide |
stability.stable-creative-upscale-v1:0 |
Creative Upscale — upscale with reimagining |
stability.stable-conservative-upscale-v1:0 |
Conservative Upscale — upscale preserving detail |
stability.stable-fast-upscale-v1:0 |
Fast Upscale — lightweight 4× upscaling |
Amazon Nova Canvas is also supported but is being deprecated by AWS:
Audio (TTS)
Generate speech audio from text using Amazon Polly:
Use male or female voice:
Use a specific Polly voice:
Store the generated audio:
Specify a different engine (model):
Default voices: default-female → Ruth, default-male → Matthew (both support the generative engine).
[!WARNING] Amazon Polly is a separate AWS service from Bedrock. The Bedrock API key (bearer token) cannot be used with Polly. Use AWS IAM credentials (SigV4) or the default AWS credential chain instead.
Embeddings
Generate vector embeddings using Amazon Titan Embeddings V2:
Specify custom dimensions (256, 512, or 1024 for Titan Embeddings V2):
Use a custom model:
Cohere Embed Models
Cohere Embed models are automatically detected and use a batch API — all inputs are sent in a single request instead of one request per input, making them more efficient for multiple texts.
Note: Cohere Embed models do not return token counts —
$response->tokenswill always be0. Titan Embeddings uses one HTTP request per input, while Cohere models batch all inputs into a single request.
Reranking
Rerank documents by relevance to a query using Cohere Rerank 3.5 or Amazon Rerank 1.0:
Use a custom model:
Note: The reranking API uses the bedrock-agent-runtime endpoint (not bedrock-runtime). Amazon Rerank 1.0 is not available in us-east-1 — use Cohere Rerank 3.5 in that region.
Testing
Supports the standard testing features of the AI SDK.
Although not mentioned in the official documentation, when using the agent() helper, you can mock it with AnonymousAgent::fake() or StructuredAnonymousAgent::fake().
License
MIT
All versions of laravel-amazon-bedrock with dependencies
illuminate/support Version ^12.0||^13.0
laravel/ai Version ^0.11
aws/aws-sdk-php Version ^3.369