Skip to content

Bedrock provider#270

Open
tott wants to merge 2 commits intolaravel:0.xfrom
tott:bedrock-provider
Open

Bedrock provider#270
tott wants to merge 2 commits intolaravel:0.xfrom
tott:bedrock-provider

Conversation

@tott
Copy link

@tott tott commented Mar 14, 2026

Add AWS Bedrock Provider

This PR adds basic support for AWS Bedrock as an AI provider, enabling access to models from Anthropic, Amazon, Meta, Mistral, and more through a unified interface. This is likely not in a place to be fully merged as it requires further testing but it should help people looking for this in reference to #39, and potentially can serve as a starting point for a full-featured implementation

Features

Text Generation

  • Support for Claude, Titan, Llama, Mistral, and other models
  • Streaming via Bedrock's converseStream API
  • Tool/function calling
  • Structured output support with JSON validation

Embeddings

  • Amazon Titan Embed Text
  • Configurable dimensions

Image Generation

  • Amazon Nova Canvas
  • Amazon Titan Image Generator

Speech Transcription

  • Amazon Nova Sonic

Implementation Details

Authentication
Supports three authentication methods:

  1. IAM credentials (access key, secret key, session token)
  2. Bearer token (AWS_BEARER_TOKEN_BEDROCK)
  3. Default AWS credential chain (environment, ~/.aws/credentials, IAM roles)

Tool Calling

  • Full multi-turn conversation loop with configurable maxSteps
  • Automatic tool execution with invocation callbacks
  • Token usage tracking across all tool calls

Message Formatting
Proper support for:

  • AssistantMessage with tool calls
  • ToolResultMessage for tool outputs
  • UserMessage with document attachments
  • Conversation history maintenance across tool loops

Configuration Example

'bedrock' => [
    'driver' => 'bedrock',
    'region' => env('AWS_BEDROCK_REGION', 'us-east-1'),
    'access_key_id' => env('AWS_ACCESS_KEY_ID'),
    'secret_access_key' => env('AWS_SECRET_ACCESS_KEY'),
    'session_token' => env('AWS_SESSION_TOKEN'),
    'use_default_credential_provider' => env('AWS_USE_DEFAULT_CREDENTIALS', true),
    'models' => [
        'text' => [
            'default' => 'us.anthropic.claude-sonnet-4-5-20250929-v1:0',
            'cheapest' => 'us.anthropic.claude-haiku-4-5-20250929-v1:0',
            'smartest' => 'us.anthropic.claude-opus-4-6-20250929-v1:0',
        ],
        'embeddings' => [
            'default' => 'amazon.titan-embed-text-v2:0',
            'dimensions' => 1024,
        ],
        'image' => [
            'default' => 'amazon.nova-canvas-v1:0',
        ],
        'transcription' => [
            'default' => 'amazon.nova-sonic-v1:0',
        ],
    ],
],

Usage Example

use Laravel\Ai\Facades\Ai;

  // Text generation
  $response = Ai::provider('bedrock')
      ->textProvider()
      ->text('Explain quantum computing');

  // With tools
  $agent = new MyAgent;
  $response = $agent
      ->provider('bedrock')
      ->prompt('What is the weather in Paris?');

  // Image generation
  $image = Ai::provider('bedrock')
      ->imageProvider()
      ->image('A serene mountain landscape', size: '16:9');

  // Embeddings
  $embeddings = Ai::provider('bedrock')
      ->embeddingProvider()
      ->embeddings(['Hello world', 'Goodbye world']);

Dependencies

Adds aws/aws-sdk-php: ^3.339 for AWS SDK integration.

tott and others added 2 commits March 13, 2026 11:06
Bring in 0.3.0 changes
Adds full support for AWS Bedrock as an AI provider with text generation,
embeddings, image generation, and speech transcription capabilities.

Features:
- Text generation with 50+ models (Claude, Titan, Llama, Mistral)
- Tool/function calling with multi-turn conversation support
- Streaming text generation via Bedrock's converseStream API
- Image generation (Nova Canvas, Titan Image, Stability AI)
- Speech transcription (Nova Sonic) with diarization
- Embeddings (Titan Embed, Cohere Embed)
- Support for IAM credentials, bearer tokens, and default credential chain
- Comprehensive exception handling and error recovery
- Rate limiting via HandlesRateLimiting trait

Closes laravel#39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant