Add scoped authorization to configured Vercel AI SDK tools with JWT verification, optional audit wrappers, and centrally managed grant state.
Your Vercel AI tools run with full access. Users can't see or control what the AI does on their behalf. No audit trail, no revocation.
Each configured protected tool call can require a scoped JWT. The host obtains grants, wrapped tools enforce them, and optional callbacks can record selected actions.
npm install @grantex/vercel-ai — TypeScript-native integration for Vercel AI SDK.
Wrap your AI SDK tools with Grantex scope requirements.
Request specific scopes through the application's configured authorization flow before protected tools run.
Each configured tool wrapper verifies the grant and required scope before execution.
Wrap authorized tools with withAuditLogging when tool-level audit records are required.
import { createGrantexTool } from '@grantex/vercel-ai';
import { z } from 'zod';
const search = createGrantexTool({
name: 'search_flights',
description: 'Search available flights',
parameters: z.object({ destination: z.string() }),
grantToken: token,
requiredScope: 'flights:read',
execute: async ({ destination }) => searchFlights(destination),
});
const result = await generateText({
model: openai('gpt-4o'),
tools: { search },
prompt: 'Search for flights to Bengaluru',
});
Returns a standard tool for the documented generateText and streamText integrations. Validate other AI SDK versions and tool patterns in your application.
TypeScript types validate adapter configuration; authorization is enforced at runtime.
Returns a standard AI SDK tool and verifies the grant token before each execution.
The wrapped tool checks authorization before its execution. Streaming lifecycle and backpressure remain the host application's responsibility.
Authorize multi-step AI workflows where each step requires different scopes.
Integrate with a trusted Next.js server boundary and keep grant tokens out of client-side code.
This integration enforces authorization only where its wrapper or middleware is installed. Local JWT verification checks signatures and claims after JWKS retrieval; it does not prove current revocation unless the verifier performs an online state check or synchronizes revocation data.
Token verification does not create a consent record or prove that a tool executed. Use the configured authorization flow for grant decisions and add an audit integration at the execution boundary when action records are required.
Follow the integration guide and verify the package version before deployment. Apache 2.0.