tetrixdev/laravel-ai-bridge
laravel-ai-bridge is a lightweight Laravel package for connecting your application to AI services through a simple, unified bridge. It helps you organize AI provider configuration and keep prompt/response integrations clean and maintainable.
effort (Claude's thinking level) can back a user-facing control — "Fast / Balanced / Deep" — that trades latency and token spend against answer quality. This is a pricing-tier and UX decision, not just an engineering one.effort_levels. Render the selector only when the backend supports it, and degrade gracefully on older bridges (empty list before ai-bridge 0.32). Decide "show, hide, or grey out" from live capability data rather than a deploy-time guess.model wins over the conversation's stored model, unlocking mid-conversation escalation (cheap model for triage, stronger model for the hard follow-up), A/B testing of models within a single thread, and per-request fallback, without forking the conversation.SameSite=Lax session cookie. Adopting the release is the cheapest way to make that claim true; hand-rolling it is now duplicated work.tool_call_id becoming required on the MCP route means every relayed request is tied to a card that was actually shown. That converts "the model could have called anything" into a per-render provenance trail — useful for support, incident review, and any enterprise security questionnaire.^[a-z]{1,16}; the MCP route now returns 422 tool_call_id_required; CSRF mismatch returns 419 csrf_token_mismatch. These are documented, testable client contracts — validate in the UI before the request, and map each code to a specific user message rather than a generic failure.ai-bridge.csrf.routes lands off in 0.21.0 and becomes the default in the next major. That is a scheduled migration we can plan for now rather than discover later. Docs standard v1 (AGENTS.md, docs map, architecture page, decision records) further lowers onboarding cost and makes the package a safer long-term bet.Consider it when:
allowSameSite() and the app's CSRF except list — is exactly the protection you would otherwise have to build and defend yourself.tool_call_id ties each relayed call to a rendered card, giving you a per-call audit trail for free.Look elsewhere when:
ai-bridge.csrf.upstreams / AI_BRIDGE_CSRF_UPSTREAMS=false) is only defensible if the app already protects those routes itself — otherwise you are re-opening the subdomain hole.For executives: v0.21.0 is primarily a security release. It closes a real hole: another site on a same-site subdomain could previously ride a signed-in user's session cookie and make that user's bridge call tools on their connected servers. Those routes now require a CSRF token, and — separately — every relayed tool call must now carry a tool_call_id, so a call can always be traced back to something the user actually saw. There is one breaking change on that browser-facing MCP route, and it does not touch billing, pricing, or the BYOK/managed split. The previous release's cost-and-quality dial is unchanged and still requires ai-bridge 0.32.0. Worth flagging: a second CSRF flag (ai-bridge.csrf.routes) ships off but becomes the default in the next major, so there is a known migration on the horizon. Still a 0.x package — treat the API as settling.
For engineering: Two things to action. First, the bridge-mutating routes (POST /ai-bridge/connections/{id}/mcp, POST/DELETE .../upstreams/{server}/sign-in) now enforce CSRF via Laravel's own middleware whenever the request is session/cookie-authenticated — X-CSRF-TOKEN, _token, or X-XSRF-TOKEN. The check deliberately ignores allowSameSite() and the CSRF except list, and fires even without a started session. Only token-authenticated requests (bearer, Sanctum PATs) pass without a token. Mismatch is 419 csrf_token_mismatch. The bundled <x-ai-bridge::chat /> sends the token itself; any custom client we wrote does not, and will break. Only disable via AI_BRIDGE_CSRF_UPSTREAMS=false if the app independently protects those routes — and note the requirement on laravel/framework for the supported setup. Second, tool_call_id is now required on the MCP route (422 tool_call_id_required), so relay code must thread it through from the rendered card; the PHP API still treats it as optional for trusted server code, so this is a transport-layer change, not a breaking change to our server-side calls. Also carry forward from 0.20.0: read effort_levels from connection status, validate effort against ^[a-z]{1,16}, confirm bridge ≥ 0.32.0, and audit any assumption that a conversation's stored model wins. Track ai-bridge.csrf.routes for the next major. Add tests for the 419 and 422 paths alongside the existing precedence and capability-empty cases.
Ask: Confirm bridge 0.32.0 availability per environment and audit our relay clients for CSRF token handling before we take 0.21.0. Then decide whether the effort control ships as a user-facing setting or an internal routing lever before we commit UI.
How can I help you explore Laravel packages today?