@webmcp-agents/vercel-api
The examples' /api/chat as Vercel web handlers.
The examples’ /api/chat as Vercel web handlers. It puts @webmcp-agents/chat’s server handler behind an origin
check, per-IP rate limits and a global daily budget on model calls.
The package is private ("private": true). It is not published to npm. The example apps (examples/playground,
examples/ecommerce, examples/flights) use it as a workspace dependency.
import { createVercelChatRoute } from "@webmcp-agents/vercel-api";
export const { GET, POST, OPTIONS } = createVercelChatRoute({ app: "playground" });
Env is read when the route is created (at the function’s cold start), never at import time.
Deployment
Project settings, environment variables, Upstash Redis and the smoke test are in Deploy.
How a request flows
OPTIONSanswers 204. Other methods thanGETandPOSTanswer 405.- Cross-site browser requests are refused by the chat handler (403).
guard:originGuard()(403forbidden_origin), thenrateLimitGuardwith a per-minute and a per-day limiter per IP (429rate_limited). OnlyPOSTis checked.GETanswers{ enabled, model }.- The chat handler validates the body.
beforeModel:budgetGuardcounts the call against the global daily budget (503unavailable).- The model runs.
API reference
| API | What it is |
|---|---|
createVercelChatRoute |
The /api/chat handlers for a Vercel Function, with every limit as an environment variable. Includes VercelChatRouteOptions. |
| Guards | Guard, composeGuards, originGuard, rateLimitGuard, budgetGuard, clientIp: what runs before the model. |
createLimiter |
Sliding-window counters, on Upstash Redis or in memory. Includes createMemoryLimiter, redisCredentials, Env, Limiter, LimiterOptions, LimitResult. |