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
createGrantexToolwith Zod schemas for typed parameters (calendar:read,email:send) - Wrap tools with
withAuditLoggingto automatically log every execution to the Grantex audit trail - Invoke tools via
generateText(ifOPENAI_API_KEYis set) or directly - Demonstrate
GrantexScopeError— attempting to create a tool withstorage:delete(a scope not in the grant) throws aGrantexScopeErrorwithrequiredScopeandgrantedScopesproperties - 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:generateText instead of direct tool invocation, set OPENAI_API_KEY:
Expected output
WithoutOPENAI_API_KEY (direct invocation):
Environment variables
| Variable | Default | Description |
|---|---|---|
GRANTEX_URL | http://localhost:3001 | Base URL of the Grantex auth service |
GRANTEX_API_KEY | sandbox-api-key-local | API key. Use a sandbox key for auto-approval |
OPENAI_API_KEY | (none) | Optional. Set to use generateText with a real LLM |
Source code
The full source is inexamples/vercel-ai-chatbot/src/index.ts.