createGateway() returns a Gateway object whose handler is a plain (request: Request) => Response | Promise<Response> function — the WinterCG fetch signature every modern runtime accepts.
Node, via Hono
app.mount and direct /v1/... calls both resolve.
Next.js route handler
Bun and Deno
Cloudflare Workers
Seed hook context from a request
The handler’s second argument seeds the mutablecontext bag every hook receives — useful for passing an already-authenticated user into beforeOperation without re-deriving it from headers.
Selective route mounting
Mount individual routes instead of the full handler, keyed by bare HTTP path.In-process model calls
Skip HTTP entirely and resolve a model for direct AI SDK calls — useful when you already have agenerateText/streamText call site and just want the gateway’s provider resolution and hooks.
gw.operation({ operation, ... }) exposes the full lifecycle (model resolution, hooks, usage aggregation) for building custom in-process call sites — see Hooks.
gw.operation accepts:
The returned operation has one
requestId and context for the whole lifecycle:
gw.operation runs only the hooks in your config. The gateway’s built-in logging, tracing, and metrics hooks run on HTTP requests, not on in-process operations.