Every SDK does the same three things — detect AI agents, price & gate them by purpose, and verify payment over HTTP 402 (AP2 / x402 / Bedrock). Same policies, same dashboard, same events. Pick your language and copy the snippet.
Node / Express is available today. The other languages are fully implemented, tested, and ready to publish.
The reference implementation. Express middleware, framework-agnostic core.
@agentrails/sdk
App Router middleware + route handler wrapper. Edge-ready.
@agentrails/nextjs
Runs at the edge, in front of your origin or your Worker app.
@agentrails/cloudflare
ASGI/WSGI middleware for FastAPI, Flask, and Django.
agentrail
PSR-15 middleware for Laravel, Symfony, and Slim.
agentrail/agentrail
net/http middleware. Wraps any http.Handler.
github.com/agentrail/agentrail-go
Hono middleware for the edge — Cloudflare, Deno, Bun, or Node.
@agentrails/hono
Rack middleware that drops into Rails or any Rack app.
agentrail
Servlet filter with a Spring Boot auto-registration helper.
com.agentrail:agentrail
Middleware for the ASP.NET Core request pipeline.
Agentrail
Tower layer that registers onto any Axum Router.
agentrail
A Plug for Phoenix router pipelines or any Plug stack.
agentrail
Gate & meter MCP tool calls — Node & Python, x402-style 402 over the protocol.
@agentrails/mcp · agentrail.mcp
Snippets below show install + the minimal middleware wiring. Click any code block to copy it.
See /demos for 10 working sites — Daybreak in Node, plus
Hono, FastAPI, Gin, Laravel, Rails, Spring, ASP.NET, Axum, and Phoenix — and a
Model Context Protocol server (agentrail-mcp-demo). Clone the repo,
run any demo, and watch agents get detected, priced, and paid in real time.
@agentrails/sdk
✅ Available now — powers the Daybreak demo, with real x402 payments + hosted control-plane mode.
The canonical AgentRail middleware. One app.use(...); your existing routes are unchanged. Detects agents, returns 402 with price headers, and verifies the payment receipt.
Self-hosting the payment rails? Pass validators: { ap2, x402, bedrock } instead of apiKey. See the Agent API docs.
@agentrails/nextjs
✅ Implemented & tested — real AP2/Bedrock signature verification, full test suite, and a PUBLISHING.md with exact registry steps. Ready to publish (not yet published).
App Router native. Use it in middleware.ts for edge-wide gating, or wrap an individual route handler. Same policy object as the core SDK.
@agentrails/cloudflare
✅ Implemented & tested — real AP2/Bedrock signature verification, full test suite, and a PUBLISHING.md with exact registry steps. Ready to publish (not yet published).
Runs at the edge — in front of your origin, or inside your own Worker. Uses the Workers runtime, no Node APIs. Bind your API key as a secret.
Set the secret: npx wrangler secret put AGENTRAIL_API_KEY
agentrail
✅ Implemented & tested — real AP2/Bedrock signature verification, full test suite, and a PUBLISHING.md with exact registry steps. Ready to publish (not yet published).
ASGI middleware for FastAPI / Starlette, plus WSGI for Flask & Django. Same policy semantics as the JS SDK.
agentrail/agentrail
✅ Implemented & tested — real AP2/Bedrock signature verification, full test suite, and a PUBLISHING.md with exact registry steps. Ready to publish (not yet published).
PSR-15 middleware — drops into Laravel, Symfony, Slim, or any PSR-15 pipeline.
github.com/agentrail/agentrail-go
✅ Implemented & tested — real AP2/Bedrock signature verification, full test suite, and a PUBLISHING.md with exact registry steps. Ready to publish (not yet published).
Standard net/http middleware. Wraps any http.Handler — works with chi, gorilla/mux, Echo, Gin (via its http.Handler bridge), or the stdlib mux.
@agentrails/hono
✅ Implemented & tested — real AP2/Bedrock signature verification, full test suite, and a PUBLISHING.md with exact registry steps. Ready to publish (not yet published).
A Hono MiddlewareHandler — runs anywhere Hono does (Cloudflare Workers, Deno, Bun, Node). Same policy object as the core SDK.
agentrail
✅ Implemented & tested — real AP2/Bedrock signature verification, full test suite, and a PUBLISHING.md with exact registry steps. Ready to publish (not yet published).
Rack middleware — add it to a Rails app via the middleware stack, or to any Rack-based app (Sinatra, Hanami, plain Rack).
com.agentrail:agentrail
✅ Implemented & tested — real AP2/Bedrock signature verification, full test suite, and a PUBLISHING.md with exact registry steps. Ready to publish (not yet published).
A servlet Filter with a Spring Boot helper. Register it as a FilterRegistrationBean and your controllers stay unchanged.
Agentrail
✅ Implemented & tested — real AP2/Bedrock signature verification, full test suite, and a PUBLISHING.md with exact registry steps. Ready to publish (not yet published).
Middleware for the ASP.NET Core pipeline. One app.UseAgentrail(...) in front of your endpoints.
agentrail
✅ Implemented & tested — real AP2/Bedrock signature verification, full test suite, and a PUBLISHING.md with exact registry steps. Ready to publish (not yet published).
A Tower layer for Axum. Build a rail from agentrail::Config, then register it onto your Router.
agentrail
✅ Implemented & tested — real AP2/Bedrock signature verification, full test suite, and a PUBLISHING.md with exact registry steps. Ready to publish (not yet published).
A Plug — add it to a Phoenix router pipeline, or to any Plug stack. Same policy semantics as every other SDK.
@agentrails/mcp · agentrail.mcp
🧪 Preview — gate & meter MCP tool calls with the same control plane as the HTTP SDKs. Node & Python, 100% test coverage, runnable demo.
MCP standardizes how an agent reaches your tools — but not whether a call is allowed, what it costs, or whether it was paid. Wrap your tool handlers and agent calls are detected, gated by purpose, metered, and charged via an x402-style "payment required" tool result. Works with the official MCP SDK (no hard dependency); MCP servers show up as their own surface on the dashboard.
Agents pass identity + payment in the tool call's _meta (agentrail/purpose, agentrail/payment). Try it: demos/agentrail-mcp-demo → npm run demo.
The wire protocol is identical across languages, so you can mix stacks behind one AgentRail project and one dashboard.
Known-agent fingerprinting, self-declared X-Agent-Identity / X-Agent-Purpose headers, and heuristics. Every request gets an identity, confidence, and purpose.
Per-resource, per-purpose policies. Free for browsing, metered for answers, blocked for training — your call. Returns HTTP 402 with X-Price-Cents and X-Payment-Methods.
Reads the X-Payment-Receipt header and verifies it against AP2 (signed mandates), x402 (on-chain USDC), or AWS Bedrock — hosted, or self-hosted with your own validators.
Emits a visit / payment / blocked / extraction event for every request — to your own callback and to the dashboard.
Ready to publish your own fork or contribute an adapter? Read the
Agent API docs and the SDK publishing guide in docs/sdk-publishing.md.