What it does
This example demonstrates the @grantex/vercel-ai integration by building scope-enforced tools with the Vercel AI SDK:
- Register an agent and obtain a grant token via the sandbox flow
- Create scoped tools using
createGrantexTool with Zod schemas for typed parameters (calendar:read, email:send)
- Wrap tools with
withAuditLogging to automatically log every execution to the Grantex audit trail
- Invoke tools via
generateText (if OPENAI_API_KEY is set) or directly
- Demonstrate
GrantexScopeError — attempting to create a tool with storage:delete (a scope not in the grant) throws a GrantexScopeError with requiredScope and grantedScopes properties
- Inspect the audit trail to see the logged actions
Prerequisites
- Node.js 18+
- Docker (Docker Desktop or Docker Engine with Compose)
Run
Start the local Grantex stack from the repository root:
In a separate terminal, run the example:
To use a real LLM with generateText instead of direct tool invocation, set OPENAI_API_KEY:
Expected output
Without OPENAI_API_KEY (direct invocation):
Environment variables
Source code
The full source is in examples/vercel-ai-chatbot/src/index.ts.Last modified on February 28, 2026