Skip to content

laravel/ai forces installation of aws/aws-sdk-php — should be moved to suggest #1000

Closed

Description

@agungsugiarto

Summary

laravel/ai (tested with v0.11.2) declares aws/aws-sdk-php: ^3.369.1 under require in vendor/laravel/ai/composer.json:

"require": {
    "php": "^8.3",
    "aws/aws-sdk-php": "^3.369.1",
    "illuminate/console": "^12.0|^13.0",
    ...
},
"suggest": {
    "laravel/mcp": "Required to use MCP client tools or MCP server tools with Laravel AI agents."
}

The AWS SDK is only needed for a single optional driver — Bedrock — but Composer forces it on every consumer, even when they only use openai, gemini, anthropic, ollama, etc. It should be demoted to suggest, following the existing precedent for the optional laravel/mcp integration.

Evidence / Analysis

  1. Only Bedrock touches Aws\ classes. Full-text search inside vendor/laravel/ai/src:

    • src/Gateway/Bedrock/Concerns/CreatesBedrockClient.php:
      use Aws\BedrockRuntime\BedrockRuntimeClient;
      use Aws\Credentials\AssumeRoleCredentialProvider;
      use Aws\Credentials\CredentialProvider;
      use Aws\Middleware;
      use Aws\Sts\StsClient;
    • src/Gateway/Bedrock/BedrockException.php:
      use Aws\BedrockRuntime\Exception\BedrockRuntimeException;
    • src/Providers/BedrockProvider.php, src/Gateway/Bedrock/BedrockTextGateway.php, BedrockImageGateway.php, BedrockRerankingGateway.php — only wire the gateways above.
    • No other provider/gateway (OpenAI, Gemini, Anthropic, Groq, Xai, Ollama, Mistral, DeepSeek, VoyageAI, Cohere, ElevenLabs, Jina) references Aws\.
  2. Usage is lazy, not eager. AiManager::createBedrockDriver() only instantiates BedrockProvider when the bedrock connection is resolved. BedrockRuntimeClient / StsClient are only constructed inside CreatesBedrockClient::createBedrockClient() / createStsClient() at request time. If the app never selects the bedrock driver, the SDK classes are never loaded.

  3. Precedent already exists in the same composer.json. laravel/mcp is correctly placed under suggest:

    "suggest": {
        "laravel/mcp": "Required to use MCP client tools or MCP server tools with Laravel AI agents."
    }

    AWS SDK deserves identical treatment: Required to use the Bedrock driver.

Impact

  • Install bloat: aws/aws-sdk-php (~tens of MB, hundreds of service clients, e.g. vendor/aws in this checkout) is downloaded for 100% of users but used by a minority (Bedrock-only).
  • Larger attack / audit surface and slower composer install/update, CI, Docker builds.
  • Version conflicts: apps that pin AWS SDK differently (or use a hardened/forked SDK, or want no AWS code at all) are forced into ^3.369.1.
  • Conceptual inconsistency: 16+ HTTP-based providers in config/ai.php work with plain HTTP (Guzzle/Laravel HTTP client) and need no extra SDK; only bedrock needs SigV4/STS/Bearer helpers from the SDK.
  • Shared-hosting / offline penalty: relevant for downstream distributions such as OpenSID that target village servers with limited bandwidth/disk.

Expected Behavior

Move the dependency to suggest:

"require": {
    "php": "^8.3",
    "illuminate/console": "^12.0|^13.0",
    ...
},
"suggest": {
    "aws/aws-sdk-php": "Required to use the AWS Bedrock driver (^3.369.1).",
    "laravel/mcp": "Required to use MCP client tools or MCP server tools with Laravel AI agents."
}

And fail gracefully with an actionable message when Bedrock is requested without the SDK, e.g. in CreatesBedrockClient or AiManager::createBedrockDriver():

if (! class_exists(\Aws\BedrockRuntime\BedrockRuntimeClient::class)) {
    throw new \RuntimeException(
        'The AWS Bedrock driver requires [aws/aws-sdk-php]. Install it via: composer require aws/aws-sdk-php:^3.369.1'
    );
}

This mirrors how Laravel ecosystem packages (Cashier, Scout drivers, Socialite providers, Notification channels) handle optional SDKs.

Proposed Fix (upstream laravel/ai)

  1. Remove "aws/aws-sdk-php": "^3.369.1" from require.
  2. Add "aws/aws-sdk-php": "Required to use the Bedrock AI provider." to suggest.
  3. Add class_exists guard + RuntimeException / AiException with install hint in CreatesBedrockClient::createBedrockClient() (and optionally createStsClient()).
  4. Document in README / https://laravel.com/docs/ai-sdk that Bedrock needs composer require aws/aws-sdk-php.
  5. Optional: add CI matrix job testing --no-suggest / without AWS SDK to prove non-Bedrock drivers still work.

Workaround (downstream, until fixed upstream)

No clean workaround — require is transitive and cannot be skipped. Options are all undesirable:

  • Accept the bloat (composer require laravel/ai always brings aws/aws-sdk-php).
  • Fork laravel/ai and strip the requirement (maintenance burden).
  • Post-install removal hacks (breaks autoloader / integrity checks).

Environment

  • laravel/ai: v0.11.2 (vendor/laravel/ai/composer.json, composer.lock:3126)
  • Transitive: aws/aws-sdk-php: 3.395.2 (composer.lock:944)
  • Downstream: opendesa/opensid (composer.json:30), PHP ^8.4, Laravel ^13.8
  • Config under test: vendor/laravel/ai/config/ai.php (providers.bedrock, lines 71–85)

Checklist

  • Verified use Aws\ only appears in Gateway/Bedrock/* (2 files) via codebase search.
  • Verified Bedrock client creation is lazy (AiManager::createBedrockDriver, CreatesBedrockClient trait).
  • Verified existing suggest precedent (laravel/mcp) in same composer.json.
  • Upstream fix: move aws/aws-sdk-php from require → suggest + runtime guard.
  • Docs update for Bedrock installation step.

Activity

  1. github-actions commented on Sep 15, 2026

    @github-actions

    Thank you for reporting this issue!

    As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

    If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

    Thank you!

  2. Mohammad-Ranjbar commented on Sep 15, 2026

    @Mohammad-Ranjbar

    Hi, I’d like to work on this.

    To keep the change focused, I plan to move aws/aws-sdk-php out of the production requirements, add it as a development dependency and Composer suggestion, add an actionable failure when the Bedrock driver is used without the SDK, and cover that behavior with a regression test.

    Would you prefer the Bedrock installation documentation update in the same pull request?

  3. nunomaduro commented on Sep 16, 2026

    @nunomaduro
    Member

    just raised this discussion with @pushpak1300, we will came back to you on this.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions