- Can I use this package directly in Laravel, or do I need Symfony?
- While this package is built for Symfony, you can integrate it into Laravel via Symfony’s bridge packages like `symfony/flex` or by manually wrapping the Bedrock client in Laravel’s service container. The abstractions (e.g., `ClientInterface`) align well with Laravel’s dependency injection, so no full Symfony stack is required.
- How do I configure AWS credentials for Bedrock in Laravel?
- Use Laravel’s existing `.env` file to store AWS credentials (e.g., `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`) and region (e.g., `BEDROCK_REGION=us-east-1`). The package relies on the AWS SDK for PHP, which Laravel already supports via packages like `fruitcake/laravel-aws`. No additional setup is needed beyond standard AWS SDK configuration.
- Does this package support structured outputs like Claude’s JSON schemas?
- Yes, the package includes helpers for structured outputs (e.g., Claude’s JSON schemas), which integrate seamlessly with Laravel’s `Response::json()` or Eloquent models. This reduces manual parsing and ensures type-safe handling of Bedrock responses in your application logic.
- How can I dynamically route requests to different Bedrock models (e.g., Claude for premium users, Llama for others)?
- Use the `Provider` abstraction (v0.8.0) to implement a strategy pattern in Laravel’s service container. Bind different model providers to interfaces and resolve them based on user tiers, cost constraints, or other logic. This approach keeps your code decoupled and easy to extend.
- Will this package work with Laravel 10/11, or are there version-specific limitations?
- The package is designed for Symfony 6.4+, which is compatible with Laravel 10/11 via Symfony’s bridge packages. However, test thoroughly in your Laravel version, as some Symfony AI abstractions (e.g., `Message`, `Stream`) may require minor adjustments if Laravel’s DI container behaves differently.
- How do I handle Bedrock’s rate limits (e.g., 5 requests/second for Claude) in Laravel?
- Leverage Laravel’s queue system (e.g., `BedrockJob`) with exponential backoff or implement middleware to throttle requests. The AWS SDK also supports retry logic, but combining it with Laravel’s queues ensures graceful degradation under load. Monitor usage with AWS Budgets or custom logging.
- Can I cache Bedrock model responses in Laravel (e.g., Redis) to reduce latency?
- Yes, cache responses using Laravel’s cache drivers (Redis, database) with a TTL-based strategy. For real-time features, pre-warm models via Laravel’s queue workers or use a hybrid approach: cache frequent responses locally while falling back to Bedrock for dynamic or high-accuracy needs.
- What alternatives exist if I want to avoid AWS Bedrock vendor lock-in?
- Consider packages like `symfony/ai-openai` for OpenAI or `illuminate/ai` for custom LLMs. The `Provider` abstraction in this package is designed to be provider-agnostic, so you could extend it to support multiple backends. However, Bedrock’s specialized models (e.g., Titan for embeddings) may not have direct equivalents elsewhere.
- How do I list available Bedrock models in Laravel, and can I refresh the cache automatically?
- Use the `ListFoundationModels` command (exposed as an Artisan command in Laravel) to fetch and cache the model catalog. Schedule a Laravel scheduler job (e.g., `php artisan bedrock:models --refresh`) to update the cache hourly or daily, avoiding API throttling while keeping data fresh.
- Are there security best practices for handling sensitive prompts/responses with Bedrock?
- Encrypt sensitive prompts using Laravel’s encryption (e.g., `Str::of($prompt)->encrypt()`) and validate inputs to block PII. Use AWS KMS for additional protection. Log usage patterns to detect anomalies, and implement middleware to sanitize outputs before rendering them in templates or APIs.