revolution / laravel-amazon-bedrock
Tiny Amazon Bedrock wrapper for Laravel
Fund package maintenance!
invokable
Installs: 73
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
pkg:composer/revolution/laravel-amazon-bedrock
Requires
- php: ^8.3
- illuminate/support: ^12.0
Requires (Dev)
- laravel/pint: ^1.22
- orchestra/testbench: ^10.0
- pestphp/pest: ^4.1
- pestphp/pest-plugin-laravel: ^4.0
- revolution/laravel-boost-copilot-cli: ^1.0
README
Overview
A lightweight Laravel package to easily interact with Amazon Bedrock, specifically for generating text.
- Features: Text Generation only.
- Supported Model: Anthropic Claude Haiku/Sonnet/Opus 4 and later.(Default: Sonnet 4.5)
- Authentication: Bedrock API Key only.
- Cache Control: Always enabled ephemeral cache at system prompts.
- Minimal Dependencies: No extra dependencies except Laravel framework.
We created our own package because prism-php/bedrock often doesn't support breaking changes in prism-php/prism. If you need more functionality than this package, please use Prism.
Requirements
- PHP >= 8.3
- Laravel >= 12.x
Installation
composer require revolution/laravel-amazon-bedrock
Configuration
Publishing the config file is optional. Everything can be set in .env.
AWS_BEDROCK_API_KEY=your_api_key AWS_BEDROCK_MODEL=global.anthropic.claude-sonnet-4-5-20250929-v1:0 AWS_DEFAULT_REGION=us-east-1
Bedrock API key is obtained from the AWS Management Console.
Usage
Usage is almost the same, making it easy to return to Prism, but it doesn't have any other features.
use Revolution\Amazon\Bedrock\Facades\Bedrock; $response = Bedrock::text() ->using(Bedrock::KEY, config('bedrock.model')) ->withSystemPrompt('You are a helpful assistant.') ->withPrompt('Tell me a joke about programming.') ->asText(); echo $response->text;
Testing
use Revolution\Amazon\Bedrock\Facades\Bedrock; use Revolution\Amazon\Bedrock\ValueObjects\Usage; use Revolution\Amazon\Bedrock\Testing\TextResponseFake; it('can generate text', function () { $fakeResponse = TextResponseFake::make() ->withText('Hello, I am Claude!') ->withUsage(new Usage(10, 20)); // Set up the fake $fake = Bedrock::fake([$fakeResponse]); // Run your code $response = Bedrock::text() ->using(Bedrock::KEY, 'global.anthropic.claude-sonnet-4-5-20250929-v1:0') ->withPrompt('Who are you?') ->asText(); // Make assertions expect($response->text)->toBe('Hello, I am Claude!'); });
License
MIT