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

serpapi logo
SerpApi

The Web Search API for Your LLM and AI Applications

Visit SerpApi

The latest

View all →
Cancel In-Flight Form Submissions in Inertia.js v3.7 image

Cancel In-Flight Form Submissions in Inertia.js v3.7

Read article
Laravel Starter Kits Now Ship with Vite+ image

Laravel Starter Kits Now Ship with Vite+

Read article
Pessimistic Locking in Laravel Eloquent with refreshForUpdate() image

Pessimistic Locking in Laravel Eloquent with refreshForUpdate()

Read article
Mask Query Bindings in Laravel Exception Messages image

Mask Query Bindings in Laravel Exception Messages

Read article
whereBinary(): Case-Sensitive MySQL Queries in Laravel image

whereBinary(): Case-Sensitive MySQL Queries in Laravel

Read article
Compile PHP to Native Binaries with TypePHP image

Compile PHP to Native Binaries with TypePHP

Read article