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

laravelcloud logo
Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Visit Laravel Cloud

The latest

View all →
CPX: The Composer Package Executor for PHP image

CPX: The Composer Package Executor for PHP

Read article
Laravel AI SDK Adds Human-in-the-Loop Tool Approval image

Laravel AI SDK Adds Human-in-the-Loop Tool Approval

Read article
Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals image

Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals

Read article
Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs image

Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs

Read article
Blade Formatting in Laravel Pint image

Blade Formatting in Laravel Pint

Read article
Inertia DevTools Is Now on the Chrome Web Store image

Inertia DevTools Is Now on the Chrome Web Store

Read article