ai-gateway/ai-gateway-bundle
Symfony bundle that turns your app into an AI gateway: unified /v1 API for chat/models, OpenAI-compatible + Anthropic providers, model fallback chains, per-key auth, budgets/rate limits, caching, cost tracking, SSE streaming, Prometheus metrics, dashboard and CLI.
GatewayInterface).openai/anthropic formats, allowing future-proofing for niche or proprietary LLMs.GatewayInterface into services via dependency injection (Symfony’s native pattern), minimizing invasive changes./ai-gateway/ prefix avoids route collisions in existing Symfony apps.doctrine:schema:update) is mandatory and could fail in constrained environments (e.g., shared hosting).readonly properties, typed constructors).composer require ai-gateway/ai-gateway-bundle).provider:create, model:create, chain:create).GatewayInterface in a non-critical service.GatewayInterface in modules (e.g., chat, search).aigw_* prefix) instead of hardcoded credentials.DASHBOARD_TOKEN)./v1/chat/completions endpoint mirrors OpenAI’s API, easing migration for apps using OpenAI SDKs./v1/* endpoints) as a microservice.GatewayInterface into services and replace SDK calls./v1/health endpoint for uptime./dashboard for real-time request logs and metrics.ai_gateway_requests_total) help diagnose latency or failures.provider:list, model:list) validate configurations.rateLimitPerMinute per team/key.ai_gateway_cost_dollars_total.gateway_request_log table if logging high volumes.| Component | Failure Mode | Mitigation |
|---|---|---|
| Provider API | Outage or throttling | Model chains with fallbacks to alternative providers. |
| Database | Connection loss | Use read replicas; implement retry logic in Doctrine. |
| Caching Layer | Cache invalidation issues | Short TTLs for deterministic requests; monitor cache hit ratios. |
| Dashboard | Token leakage or unauthorized access | Combine with Symfony firewall; rotate tokens regularly. |
| Symfony App | High latency under load | Optimize PHP-FPM worker count; use OPcache. |
| Budget Enforcement | Unexpected cost spikes | Set hard monthly limits; alert on 80% usage. |
GatewayInterface, CLI commands, and dashboard.GatewayInterface in code; manage models/chains via CLI.GatewayBootstrap class for CI/CD provisioning.How can I help you explore Laravel packages today?