ai.guard.token.consumed) for extensibility. Custom logic (e.g., alerts, analytics) can be attached without modifying the package.App\Http\Kernel) or per-route for granular control.| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| Version Lock-in | Tied to Laravel AI SDK v12.x. Future SDK changes may break compatibility. | Monitor Laravel AI SDK releases; test against beta versions early. |
| Performance Overhead | Token counting adds minor latency (~1–5ms per AI call). | Benchmark in staging; optimize by batching analytics or using async event listeners. |
| Budget Logic Errors | Incorrect budget calculations could block legitimate requests. | Unit test budget middleware with edge cases (e.g., fractional tokens, concurrent users). |
| LLM Provider Support | Primarily designed for OpenAI. Multi-provider support is extensible but undocumented. | Validate with target LLM providers (e.g., Anthropic, Mistral) via custom pricing configs. |
| Data Retention | No built-in cleanup for historical token data. | Implement a ai_guard_usage table cleanup job (e.g., via Laravel Scheduler). |
ai_guard_usage table (provided). Works with MySQL, PostgreSQL, SQLite.| Phase | Tasks | Effort Estimate | Dependencies |
|---|---|---|---|
| Prep | Review AI SDK usage; identify token-heavy endpoints. | 2hr | Dev team |
| Installation | Composer install; publish config/migrations. | 1hr | Laravel AI SDK v12.x |
| Core Setup | Configure budgets (global/per-user); set up token tracking. | 4hr | Database access |
| Middleware | Apply budget middleware to critical routes. | 3hr | Route definitions |
| Testing | Unit tests for budget logic; integration tests for token counting. | 10hr | Test environment |
| Monitoring | Set up alerts (e.g., Laravel Horizon for queues, Slack webhooks). | 5hr | Alerting infrastructure |
| Optimization | Benchmark performance; optimize async event listeners if needed. | 3hr | Load testing tools |
ai_guard_usage table (e.g., retain 12 months of data).ai_guard_usage table on user_id, tenant_id, and created_at for fast queries.How can I help you explore Laravel packages today?