PHPackages                             ubxty/bedrock-ai - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ubxty/bedrock-ai

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ubxty/bedrock-ai
================

A Laravel package for seamless AWS Bedrock integration with multi-key rotation, cross-region inference, usage tracking, pricing, and powerful CLI tools.

0.0.1(3mo ago)06MITPHPPHP ^8.2

Since Feb 15Pushed 3mo agoCompare

[ Source](https://github.com/ubxty/bedrock-ai)[ Packagist](https://packagist.org/packages/ubxty/bedrock-ai)[ RSS](/packages/ubxty-bedrock-ai/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (7)Versions (2)Used By (0)

Bedrock AI
==========

[](#bedrock-ai)

[![PHP 8.2+](https://camo.githubusercontent.com/187240af044d09d5b14a1d9d9ebdf3f7a993e4c7bc09bdb46b4ba661a891bf5b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e322532422d626c7565)](https://camo.githubusercontent.com/187240af044d09d5b14a1d9d9ebdf3f7a993e4c7bc09bdb46b4ba661a891bf5b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e322532422d626c7565)[![Laravel 11|12](https://camo.githubusercontent.com/391257e76c9420905a4f88825c9d116b09f985aa5eb286e2b062372cd66031f1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d313125323025374325323031322d726564)](https://camo.githubusercontent.com/391257e76c9420905a4f88825c9d116b09f985aa5eb286e2b062372cd66031f1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d313125323025374325323031322d726564)[![MIT License](https://camo.githubusercontent.com/5caa455d8debc46fb23abbadb45a733a937f3910a73fc875c2f7820468e1bb54/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e)](https://camo.githubusercontent.com/5caa455d8debc46fb23abbadb45a733a937f3910a73fc875c2f7820468e1bb54/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e)

A Laravel package for seamless **AWS Bedrock** integration. Provides multi-key credential rotation, cross-region inference profiles, CloudWatch usage tracking, real-time pricing, and powerful CLI tools—all with zero boilerplate.

---

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Requirements](#requirements)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Configuration](#configuration)
    - [Basic Setup](#basic-setup)
    - [Multiple AWS Keys (Failover)](#multiple-aws-keys-failover)
    - [Multiple Connections](#multiple-connections)
    - [Cost Limits](#cost-limits)
    - [Pricing &amp; Usage API](#pricing--usage-api)
- [Usage](#usage)
    - [Facade](#facade)
    - [Dependency Injection](#dependency-injection)
    - [Invoking Models](#invoking-models)
    - [Model Aliases](#model-aliases)
    - [Conversation Builder](#conversation-builder)
    - [Converse API](#converse-api)
    - [Streaming Responses](#streaming-responses)
    - [Token Estimation](#token-estimation)
    - [Listing Models](#listing-models)
    - [Testing Connection](#testing-connection)
    - [Pricing Data](#pricing-data)
    - [Usage Tracking](#usage-tracking)
    - [Events](#events)
    - [Invocation Logging](#invocation-logging)
    - [Health Check Route](#health-check-route)
- [CLI Commands](#cli-commands)
    - [bedrock:configure](#bedrockconfigure)
    - [bedrock:test](#bedrocktest)
    - [bedrock:models](#bedrockmodels)
    - [bedrock:usage](#bedrockusage)
    - [bedrock:pricing](#bedrockpricing)
- [Architecture](#architecture)
    - [Cross-Region Inference Profiles](#cross-region-inference-profiles)
    - [Multi-Key Rotation &amp; Retry](#multi-key-rotation--retry)
    - [HTTP Bearer Token Mode (ABSK)](#http-bearer-token-mode-absk)
    - [Model Spec Resolution](#model-spec-resolution)
- [Error Handling](#error-handling)
- [API Reference](#api-reference)
- [Testing](#testing)
- [License](#license)

---

Features
--------

[](#features)

FeatureDescription**Multi-key rotation**Configure multiple AWS credential sets with automatic failover**Cross-region inference**Automatic `us.`/`eu.` prefix for newer models (Claude 3.5+, Nova, Llama 3.3+)**Dual mode**AWS SDK or HTTP Bearer token (ABSK) — auto-detected from credentials**Rate limit retry**Exponential backoff with configurable retries per key**Titan + Claude support**Handles different request/response formats transparently**Converse API**Unified AWS Converse API across all model providers**Streaming**Real-time token streaming via `invokeModelWithResponseStream`**Conversation Builder**Fluent multi-turn conversation API with chaining**Model Aliases**Define short names for model IDs (e.g., `'claude'` → full model ID)**Token Estimation**Pre-call token count and cost estimation**Laravel Events**`BedrockInvoked`, `BedrockRateLimited`, `BedrockKeyRotated` events**Invocation Logger**Auto-log all invocations with configurable channels**Health Check Route**Registerable `/health/bedrock` endpoint for monitoring**CloudWatch usage**Track input/output tokens, invocations, latency from CloudWatch metrics**Real-time pricing**Fetch current Bedrock pricing from the AWS Pricing API**Cost limits**Configurable daily/monthly spending limits**5 CLI commands**Configure, test, list models, view usage, fetch pricing**Facade + DI**Use `Bedrock::invoke()` or inject `BedrockManager`---

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 11 or 12
- `aws/aws-sdk-php` ^3.300
- AWS credentials with Bedrock access

---

Installation
------------

[](#installation)

```
composer require ubxty/bedrock-ai
```

Publish the configuration file:

```
php artisan vendor:publish --tag=bedrock-config
```

Or use the interactive wizard:

```
php artisan bedrock:configure
```

---

Quick Start
-----------

[](#quick-start)

```
use Ubxty\BedrockAi\Facades\Bedrock;

// Simple invocation
$result = Bedrock::invoke(
    modelId: 'anthropic.claude-3-5-sonnet-20241022-v2:0',
    systemPrompt: 'You are a helpful assistant.',
    userMessage: 'What is the capital of France?'
);

echo $result['response'];       // "The capital of France is Paris."
echo $result['total_tokens'];   // 42
echo $result['cost'];           // 0.000234
echo $result['latency_ms'];     // 850
```

---

Configuration
-------------

[](#configuration)

### Basic Setup

[](#basic-setup)

Add these to your `.env`:

```
BEDROCK_AWS_KEY=AKIA...
BEDROCK_AWS_SECRET=your-secret-key
BEDROCK_REGION=us-east-1
```

Or use an ABSK Bearer Token (auto-detected):

```
BEDROCK_AWS_KEY=ABSKxxxxxxxxxxxxxxx
BEDROCK_AWS_SECRET=ABSKxxxxxxxxxxxxxxx
BEDROCK_REGION=us-east-1
```

### Multiple AWS Keys (Failover)

[](#multiple-aws-keys-failover)

In `config/bedrock.php`, add multiple keys to a connection. If the first key hits a rate limit or fails, the client automatically tries the next:

```
'connections' => [
    'default' => [
        'keys' => [
            [
                'label' => 'Primary',
                'aws_key' => env('BEDROCK_AWS_KEY'),
                'aws_secret' => env('BEDROCK_AWS_SECRET'),
                'region' => 'us-east-1',
            ],
            [
                'label' => 'Backup',
                'aws_key' => env('BEDROCK_AWS_KEY_2'),
                'aws_secret' => env('BEDROCK_AWS_SECRET_2'),
                'region' => 'us-west-2',
            ],
        ],
    ],
],
```

### Multiple Connections

[](#multiple-connections)

Define separate connections for different environments or use cases:

```
'connections' => [
    'default' => [
        'keys' => [/* ... */],
    ],
    'production' => [
        'keys' => [/* ... */],
    ],
    'staging' => [
        'keys' => [/* ... */],
    ],
],
```

Switch at runtime:

```
Bedrock::invoke('anthropic.claude...', $system, $user, connection: 'production');
// or
$client = Bedrock::client('staging');
```

### Cost Limits

[](#cost-limits)

```
BEDROCK_DAILY_LIMIT=10.00
BEDROCK_MONTHLY_LIMIT=300.00
```

When exceeded, a `CostLimitExceededException` is thrown.

### Pricing &amp; Usage API

[](#pricing--usage-api)

If you use separate IAM credentials for the Pricing or CloudWatch APIs:

```
BEDROCK_PRICING_KEY=AKIA...
BEDROCK_PRICING_SECRET=your-pricing-secret

BEDROCK_USAGE_KEY=AKIA...
BEDROCK_USAGE_SECRET=your-usage-secret
BEDROCK_USAGE_REGION=us-east-1
```

If not set, the package falls back to the default connection's first key.

---

Usage
-----

[](#usage)

### Facade

[](#facade)

```
use Ubxty\BedrockAi\Facades\Bedrock;

// Invoke a model
$result = Bedrock::invoke('anthropic.claude-3-5-sonnet-20241022-v2:0', $system, $user);

// Test connection
$test = Bedrock::testConnection();

// List models
$models = Bedrock::fetchModels();

// Check if configured
if (Bedrock::isConfigured()) { /* ... */ }

// Pricing
$pricing = Bedrock::pricing()->getPricing();

// Usage
$usage = Bedrock::usage()->getAggregatedUsage(30);
```

### Dependency Injection

[](#dependency-injection)

```
use Ubxty\BedrockAi\BedrockManager;

class MyService
{
    public function __construct(protected BedrockManager $bedrock) {}

    public function analyze(string $text): string
    {
        $result = $this->bedrock->invoke(
            'anthropic.claude-3-5-sonnet-20241022-v2:0',
            'You are an analyst.',
            $text,
            maxTokens: 2048
        );

        return $result['response'];
    }
}
```

### Invoking Models

[](#invoking-models)

```
$result = Bedrock::invoke(
    modelId: 'anthropic.claude-3-5-sonnet-20241022-v2:0',
    systemPrompt: 'You are a medical assistant.',
    userMessage: 'Explain hypertension in simple terms.',
    maxTokens: 1024,
    temperature: 0.5,
    pricing: [
        'input_price_per_1k' => 0.003,
        'output_price_per_1k' => 0.015,
    ]
);

// $result structure:
// [
//     'response' => 'Hypertension, or high blood pressure...',
//     'input_tokens' => 45,
//     'output_tokens' => 230,
//     'total_tokens' => 275,
//     'cost' => 0.003585,
//     'latency_ms' => 1250,
//     'status' => 'success',
//     'key_used' => 'Primary',
//     'model_id' => 'us.anthropic.claude-3-5-sonnet-20241022-v2:0',
// ]
```

**Supported models include:**

- Claude 3.5 Sonnet/Haiku, Claude 3 Opus/Sonnet/Haiku, Claude 4
- Amazon Titan Text Express/Lite/Premier
- Amazon Nova Pro/Lite/Micro
- Meta Llama 3/3.1/3.2/3.3/4
- Mistral Large/Small/Mixtral/Ministral
- Cohere Command R/R+
- AI21 Jamba

### Model Aliases

[](#model-aliases)

Define short names for frequently used model IDs in `config/bedrock.php`:

```
'aliases' => [
    'claude' => 'anthropic.claude-sonnet-4-20250514-v1:0',
    'haiku'  => 'anthropic.claude-3-5-haiku-20241022-v1:0',
    'nova'   => 'amazon.nova-pro-v1:0',
],
```

Use aliases anywhere a model ID is accepted:

```
Bedrock::invoke('claude', 'You are helpful.', 'Hello!');

$builder = Bedrock::conversation('haiku');

// Register aliases at runtime
Bedrock::aliases()->register('fast', 'anthropic.claude-3-5-haiku-20241022-v1:0');
```

### Conversation Builder

[](#conversation-builder)

Fluent API for multi-turn conversations:

```
$conversation = Bedrock::conversation('claude')
    ->system('You are a medical assistant.')
    ->user('What causes headaches?')
    ->maxTokens(2048)
    ->temperature(0.5);

// Send and get response
$result = $conversation->send();
echo $result['response'];

// Continue the conversation (assistant response is auto-added)
$conversation->user('Tell me more about migraines');
$result2 = $conversation->send();

// Estimate tokens and cost before sending
$estimate = $conversation->estimate();
echo "Estimated input tokens: {$estimate['input_tokens']}";
echo "Fits in context: " . ($estimate['fits'] ? 'yes' : 'no');
echo "Estimated cost: \${$estimate['estimated_cost']}";

// Reset conversation (keeps system prompt and settings)
$conversation->reset();
```

### Converse API

[](#converse-api)

The AWS Converse API provides a unified interface across all model providers—no need to handle different request formats:

```
// Direct converse call
$result = Bedrock::converse(
    modelId: 'anthropic.claude-sonnet-4-20250514-v1:0',
    messages: [
        ['role' => 'user', 'content' => 'What is PHP?'],
        ['role' => 'assistant', 'content' => 'PHP is a programming language.'],
        ['role' => 'user', 'content' => 'What makes it special?'],
    ],
    systemPrompt: 'You are a helpful teacher.',
    maxTokens: 1024
);

// Or get the client directly
$converseClient = Bedrock::converseClient();
$result = $converseClient->converse($modelId, $messages);
```

### Streaming Responses

[](#streaming-responses)

Stream responses in real-time for chat UIs and long outputs:

```
// Stream with InvokeModel API
$result = Bedrock::stream(
    modelId: 'anthropic.claude-sonnet-4-20250514-v1:0',
    systemPrompt: 'You are helpful.',
    userMessage: 'Write a poem about PHP.',
    onChunk: function (string $chunk, array $metadata) {
        echo $chunk; // Print each token as it arrives
        flush();
    }
);

// Stream with Converse API
$streamingClient = Bedrock::streamingClient();
$result = $streamingClient->converseStream(
    modelId: 'anthropic.claude-sonnet-4-20250514-v1:0',
    messages: [['role' => 'user', 'content' => 'Hello!']],
    onChunk: fn(string $text) => echo $text,
    systemPrompt: 'Be concise.'
);
```

### Token Estimation

[](#token-estimation)

Estimate token usage and cost before making API calls:

```
use Ubxty\BedrockAi\Support\TokenEstimator;

// Estimate tokens in a string
$tokens = TokenEstimator::estimate($text);

// Full invocation estimation
$estimation = TokenEstimator::estimateInvocation(
    systemPrompt: $system,
    userMessage: $user,
    modelId: 'anthropic.claude-sonnet-4-v1:0',
    maxOutputTokens: 4096
);

echo "Input tokens: ~{$estimation['input_tokens']}";
echo "Fits in context: " . ($estimation['fits'] ? 'yes' : 'no');
echo "Available output tokens: {$estimation['available_output']}";

// Estimate cost
$cost = TokenEstimator::estimateCost($system, $user, 1000, [
    'input_price_per_1k' => 0.003,
    'output_price_per_1k' => 0.015,
]);
echo "Estimated cost: \${$cost}";
```

### Listing Models

[](#listing-models)

```
// Raw model summaries from Bedrock
$raw = Bedrock::listModels();

// Normalized with specs
$models = Bedrock::fetchModels();

foreach ($models as $model) {
    echo "{$model['name']} ({$model['model_id']}) - Context: {$model['context_window']}";
}
```

### Testing Connection

[](#testing-connection)

```
$result = Bedrock::testConnection();

if ($result['success']) {
    echo "Connected! Found {$result['model_count']} models in {$result['response_time']}ms";
}
```

### Pricing Data

[](#pricing-data)

```
$pricing = Bedrock::pricing()->getPricing();

foreach ($pricing as $modelId => $data) {
    echo "{$data['model_name']}: Input \${$data['input_price']}/1K, Output \${$data['output_price']}/1K\n";
}

// Force refresh from AWS
$fresh = Bedrock::pricing()->refreshPricing();
```

### Usage Tracking

[](#usage-tracking)

```
$tracker = Bedrock::usage();

// Active models from CloudWatch
$models = $tracker->getActiveModels();

// Aggregated usage
$usage = $tracker->getAggregatedUsage(days: 30);

foreach ($usage as $modelId => $data) {
    echo "{$modelId}: {$data['invocations']} calls, {$data['total_tokens']} tokens\n";
}

// Daily trend for charts
$trend = $tracker->getDailyTrend(30);

// Cost estimation
$costs = $tracker->calculateCosts($usage, $pricingMap);
echo "Total cost: \${$costs['total_cost']}";
```

### Events

[](#events)

The package fires Laravel events for observability. Listen to them in your `EventServiceProvider` or with closures:

```
use Ubxty\BedrockAi\Events\BedrockInvoked;
use Ubxty\BedrockAi\Events\BedrockRateLimited;
use Ubxty\BedrockAi\Events\BedrockKeyRotated;

// In a listener or closure
Event::listen(BedrockInvoked::class, function (BedrockInvoked $event) {
    // $event->modelId, $event->inputTokens, $event->outputTokens
    // $event->cost, $event->latencyMs, $event->keyUsed, $event->connection
});

Event::listen(BedrockRateLimited::class, function (BedrockRateLimited $event) {
    // $event->modelId, $event->keyLabel, $event->retryAttempt, $event->waitSeconds
    Notification::send($admin, new RateLimitAlert($event));
});

Event::listen(BedrockKeyRotated::class, function (BedrockKeyRotated $event) {
    // $event->fromKeyLabel, $event->toKeyLabel, $event->reason, $event->modelId
});
```

### Invocation Logging

[](#invocation-logging)

Auto-log every Bedrock invocation for auditing and cost tracking:

```
BEDROCK_LOGGING_ENABLED=true
BEDROCK_LOG_CHANNEL=bedrock
```

In `config/bedrock.php`:

```
'logging' => [
    'enabled' => env('BEDROCK_LOGGING_ENABLED', false),
    'channel' => env('BEDROCK_LOG_CHANNEL', 'stack'),
],
```

Each invocation logs: model ID, tokens (input/output/total), cost, latency, status, and key used.

### Health Check Route

[](#health-check-route)

Register a health check endpoint for monitoring dashboards:

```
BEDROCK_HEALTH_CHECK_ENABLED=true
```

In `config/bedrock.php`:

```
'health_check' => [
    'enabled' => env('BEDROCK_HEALTH_CHECK_ENABLED', false),
    'path' => '/health/bedrock',
    'middleware' => ['auth:sanctum'], // optional
],
```

The endpoint returns:

```
{
    "status": "healthy",
    "message": "Connection successful! Found 42 available models.",
    "response_time_ms": 350,
    "model_count": 42
}
```

---

CLI Commands
------------

[](#cli-commands)

### `bedrock:configure`

[](#bedrockconfigure)

Interactive wizard for first-time setup.

```
php artisan bedrock:configure

# Show current config (masked secrets)
php artisan bedrock:configure --show

# Auto-test after configuring
php artisan bedrock:configure --test
```

**What it does:**

1. Prompts for AWS Key, Secret, Region, Label
2. Auto-detects SDK vs HTTP Bearer mode
3. Optionally configures Pricing API credentials
4. Generates `.env` entries
5. Optionally writes to `.env` automatically
6. Tests the connection

### `bedrock:test`

[](#bedrocktest)

Test connection and optionally invoke a model.

```
# Basic connection test
php artisan bedrock:test

# Test a specific model
php artisan bedrock:test anthropic.claude-3-5-sonnet-20241022-v2:0

# Custom prompt
php artisan bedrock:test anthropic.claude-3-5-sonnet-20241022-v2:0 --prompt="Explain gravity"

# Test all credential keys
php artisan bedrock:test --all-keys

# JSON output
php artisan bedrock:test anthropic.claude-3-5-sonnet-20241022-v2:0 --json
```

### `bedrock:models`

[](#bedrockmodels)

List available foundation models.

```
# All models
php artisan bedrock:models

# Filter by name/ID
php artisan bedrock:models --filter=claude

# Filter by provider
php artisan bedrock:models --provider=anthropic

# JSON output
php artisan bedrock:models --json
```

### `bedrock:usage`

[](#bedrockusage)

View CloudWatch usage metrics.

```
# Last 30 days (default)
php artisan bedrock:usage

# Custom time range
php artisan bedrock:usage --days=7

# Show daily breakdown
php artisan bedrock:usage --daily

# JSON output
php artisan bedrock:usage --json
```

### `bedrock:pricing`

[](#bedrockpricing)

Fetch real-time pricing from the AWS Pricing API.

```
# All models
php artisan bedrock:pricing

# Filter
php artisan bedrock:pricing --filter=claude

# Force refresh (bypass cache)
php artisan bedrock:pricing --refresh

# JSON output
php artisan bedrock:pricing --json
```

---

Architecture
------------

[](#architecture)

### Cross-Region Inference Profiles

[](#cross-region-inference-profiles)

Newer models (Claude 3.5+, Nova, Llama 3.3+, Claude 4) cannot be invoked directly. They require cross-region inference profiles with a `us.` or `eu.` prefix. This package handles this automatically:

```
anthropic.claude-3-5-sonnet-20241022-v2:0
  → us.anthropic.claude-3-5-sonnet-20241022-v2:0  (in us-east-1)
  → eu.anthropic.claude-3-5-sonnet-20241022-v2:0  (in eu-west-1)

```

Models that require inference profiles:

- `anthropic.claude-3-5-*`
- `anthropic.claude-3-7-*`
- `anthropic.claude-sonnet-4*`, `claude-opus-4*`, `claude-haiku-4*`
- `amazon.nova-*`
- `meta.llama3-3*`, `meta.llama4*`

You can register additional patterns:

```
use Ubxty\BedrockAi\Client\InferenceProfileResolver;

InferenceProfileResolver::addPattern('custom.model-prefix-');
```

### Multi-Key Rotation &amp; Retry

[](#multi-key-rotation--retry)

```
Request → Key 1 → Rate Limited → Retry (2s) → Retry (4s) → Retry (8s) → Key 2 → Success

```

- Each key gets up to `max_retries` attempts (default: 3) with exponential backoff
- On persistent failure, the next key is tried
- All keys exhausted → `RateLimitException` or `BedrockException`

### HTTP Bearer Token Mode (ABSK)

[](#http-bearer-token-mode-absk)

If your AWS key or secret starts with `ABSK`, the client automatically uses HTTP Bearer token mode instead of the AWS SDK. This is useful for:

- Bedrock API keys distributed via AWS console
- Environments without full IAM credentials

### Model Spec Resolution

[](#model-spec-resolution)

The `ModelSpecResolver` maps model IDs to known context windows and max token limits:

```
use Ubxty\BedrockAi\Models\ModelSpecResolver;

$specs = ModelSpecResolver::resolve('anthropic.claude-3-5-sonnet-20241022-v2:0');
// ['context_window' => 200000, 'max_tokens' => 8192]
```

---

Error Handling
--------------

[](#error-handling)

The package provides specific exception types:

```
use Ubxty\BedrockAi\Exceptions\BedrockException;
use Ubxty\BedrockAi\Exceptions\RateLimitException;
use Ubxty\BedrockAi\Exceptions\ConfigurationException;
use Ubxty\BedrockAi\Exceptions\CostLimitExceededException;

try {
    $result = Bedrock::invoke($modelId, $system, $user);
} catch (RateLimitException $e) {
    // All keys exhausted after retries
    // $e->getModelId(), $e->getKeyLabel()
} catch (CostLimitExceededException $e) {
    // Daily or monthly limit exceeded
    // $e->getLimitType(), $e->getLimit(), $e->getCurrentSpend()
} catch (ConfigurationException $e) {
    // Missing credentials or connection
} catch (BedrockException $e) {
    // General Bedrock errors (model not found, access denied, etc.)
    // User-friendly messages are automatically extracted
}
```

Raw Bedrock errors are automatically mapped to user-friendly messages:

Raw ErrorFriendly Message`model identifier is invalid`Invalid model: This model ID is not valid for Bedrock.`doesn't support on-demand throughput`Model unavailable: This model requires provisioned throughput.`Malformed input request`Request error: This model may not support text chat.`end of its life`Model deprecated: This model version has been retired.`AccessDeniedException`Access denied: You don't have permission to use this model.`ResourceNotFoundException`Model not found: The requested model does not exist in this region.---

API Reference
-------------

[](#api-reference)

### `BedrockManager`

[](#bedrockmanager)

MethodReturnsDescription`client(?string $connection)``BedrockClient`Get a client for the given connection`invoke(string $modelId, ...)``array`Invoke a model on the default connection`converse(array $messages, ...)``array`Invoke via the Converse API`converseClient(?string $connection)``ConverseClient`Get a Converse API client`stream(string $modelId, ..., callable $onChunk)``array`Stream a model response`streamingClient(?string $connection)``StreamingClient`Get a streaming client`conversation(?string $modelId)``ConversationBuilder`Start a fluent conversation`aliases()``ModelAliasResolver`Get the alias resolver`resolveAlias(string $alias)``string`Resolve an alias to a model ID`getLogger()``InvocationLogger`Get the invocation logger`testConnection(?string $connection)``array`Test connection`listModels(?string $connection)``array`List raw model summaries`fetchModels(?string $connection)``array`List normalized models with specs`pricing()``PricingService`Get the pricing service`usage()``UsageTracker`Get the usage tracker`isConfigured(?string $connection)``bool`Check if configured### `BedrockClient::invoke()` Return Value

[](#bedrockclientinvoke-return-value)

```
[
    'response' => string,      // The model's text response
    'input_tokens' => int,     // Tokens in the prompt
    'output_tokens' => int,    // Tokens in the response
    'total_tokens' => int,     // input + output
    'cost' => float,           // Estimated cost in USD
    'latency_ms' => int,       // End-to-end latency in milliseconds
    'status' => 'success',     // Always 'success' (failures throw)
    'key_used' => string,      // Label of the credential key that worked
    'model_id' => string,      // Resolved model ID (with inference prefix if applied)
]
```

### `PricingService`

[](#pricingservice)

MethodReturnsDescription`getPricing()``array`Cached pricing data`refreshPricing()``array`Force-refresh from AWS`testConnection()``array`Test Pricing API access### `UsageTracker`

[](#usagetracker)

MethodReturnsDescription`getActiveModels()``array`Models with CloudWatch metrics`getModelUsage(string $modelId, int $days)``array`Per-model daily metrics`getAggregatedUsage(int $days)``array`Aggregated across all models`calculateCosts(array $usage, array $pricingMap)``array`Cost estimation`getDailyTrend(int $days)``array`Daily breakdown for charts`testConnection()``array`Test CloudWatch access---

Testing
-------

[](#testing)

The package includes **179 tests** with **346 assertions** covering all components.

```
cd packages/ubxty/bedrock-ai
composer install
./vendor/bin/phpunit
```

---

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE) for details.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance82

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

93d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e2de529037b10593205d6c41aa1d5331ef027e398489b74355b6d222ac10f2f1?d=identicon)[ubxty](/maintainers/ubxty)

---

Top Contributors

[![ravdeepsingh22](https://avatars.githubusercontent.com/u/13014642?v=4)](https://github.com/ravdeepsingh22 "ravdeepsingh22 (10 commits)")

---

Tags

laravelawsaibedrocknovaclaudetitanllama

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ubxty-bedrock-ai/health.svg)

```
[![Health](https://phpackages.com/badges/ubxty-bedrock-ai/health.svg)](https://phpackages.com/packages/ubxty-bedrock-ai)
```

###  Alternatives

[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[laragear/preload

Effortlessly make a Preload script for your Laravel application.

119363.5k](/packages/laragear-preload)[symfony/ai-platform

PHP library for interacting with AI platform provider.

51927.7k136](/packages/symfony-ai-platform)[glhd/conveyor-belt

14797.0k](/packages/glhd-conveyor-belt)[napp/xray-laravel

AWS X-Ray for Laravel applications.

61407.3k](/packages/napp-xray-laravel)[mischasigtermans/laravel-altitude

Claude Code agents for the TALL stack, powered by Laravel Boost

1139.2k](/packages/mischasigtermans-laravel-altitude)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
