Setting the file. One moment.
Subchapter 7.6
references/playbooks/ai-application.mdMarkdown4 KBView on GitHub
LLM-backed apps, agents, code-sandbox tools, RAG pipelines. Cost shape is dominated by per-token AI Gateway spend and Sandbox active-compute time, not edge requests or function duration. Many AI customers also have a SaaS surface (auth, dashboards), but the cost lever lives upstream of the dashboard.
AI Gateway > Sandbox Active Compute > Function Duration > Function Invocations. Edge Requests usually quiet; ISR rarely applies. Observability Events can climb fast if every tool-call span is captured at full fidelity.
vercel env run -- <cmd> rotates OIDC each run. An explicit AI_GATEWAY_API_KEY in repo env vars is a regression — it bypasses keyless and creates a long-lived secret.Sandbox.create. Each fresh sandbox costs at least 1 minute of billed compute (boot + teardown rounded up). When isolation isn’t required (single-tenant agents, shared workspaces), pool sandboxes by name (sandbox.get(name)) — auto-snapshot on death + auto-resume on next get is the persistence model.after() / waitUntil() for tool logging. Tool-call telemetry, audit writes, and analytics should never block the user response. Use after() (Next 15+) or waitUntil() from @vercel/functions for any write that doesn’t affect the streamed response.new Sandbox(...) inside a per-request handler with no id argument creates a fresh microVM each time. Cheaper to pool when isolation allows.after() for post-response tool logginghttps://vercel.com/docs/ai-gateway — provider configuration, failover chainhttps://vercel.com/docs/vercel-sandbox — sandbox.get(name) and active-compute billing