Laravel Packages

Use Amazon Bedrock in Laravel with Prism PHP

Published
Use Amazon Bedrock in Laravel with Prism PHP image

The Prism Bedrock package is a standalone Bedrock provider for the Prism PHP Package for Laravel. The Bedrock provider supports text generation, structured output, embeddings, and more:

use Prism\Prism\Prism;
use Prism\Bedrock\Bedrock;
 
$response = Prism::text()
->using(Bedrock::KEY, 'anthropic.claude-3-sonnet-20240229-v1:0')
->withPrompt('Explain quantum computing in simple terms')
->asText();
 
echo $response->text;

This package also supports cache-optimized prompts to reduce latency and costs:

use Prism\Prism\Prism;
use Prism\Bedrock\Bedrock;
use Prism\Prism\ValueObjects\Messages\UserMessage;
 
$response = Prism::text()
->using(Bedrock::KEY, 'anthropic.claude-3-sonnet-20240229-v1:0')
->withMessages([
new UserMessage('Message with cache breakpoint')
->withProviderOptions(['cacheType' => 'ephemeral']),
new UserMessage('Message with another cache breakpoint')
->withProviderOptions(['cacheType' => 'ephemeral']),
new UserMessage('Compare the last two messages.')
])
->asText();

Main Features

  • Auto-resolution of API schemas
  • A unified interface for multiple providers
  • Cache-optimized prompts to reduce latency and costs
  • Support for Converse, Anthropic, and Cohere (embeddings) schemas
  • And more...

You can learn more about this package, get full installation instructions, and view the source code on GitHub. The primary Prism documentation is also a helpful place to get started with this package regardless of the providers you use.

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Sponsored

acquaintsoft logo
Acquaint Softtech

Hire Laravel developers with AI expertise at $20/hr. Get started in 48 hours.

Visit Acquaint Softtech

The latest

View all →
Laravel Truss: Live Interactive Database ER Diagrams image

Laravel Truss: Live Interactive Database ER Diagrams

Read article
Laravel artisan dev: Run Server, Queue, Logs, and Vite image

Laravel artisan dev: Run Server, Queue, Logs, and Vite

Read article
Validate and Convert HEIC Images in Laravel image

Validate and Convert HEIC Images in Laravel

Read article
Saga Lara Flow: Durable Workflows and Compensating Transactions on Laravel Queues image

Saga Lara Flow: Durable Workflows and Compensating Transactions on Laravel Queues

Read article
Reject Unexpected Array Keys with Laravel Validation image

Reject Unexpected Array Keys with Laravel Validation

Read article
Major performance improvements & security patches for Filament v4.12 and v5.7! image

Major performance improvements & security patches for Filament v4.12 and v5.7!

Read article