Skip to main content
Attesta integrates with the Vercel AI SDK (ai package) through two mechanisms:
  1. gatedVercelTool — wraps a single tool definition with Attesta approval before execute runs.
  2. createAttestaMiddleware — returns middleware that intercepts all tool calls in generateText / streamText pipelines.
Both are TypeScript-only and ship with @kyberon/attesta.

Installation


Tool Wrapper: gatedVercelTool

Wraps a Vercel AI SDK tool() definition. The wrapped tool runs the full Attesta evaluation pipeline before delegating to the original execute function.

API

GatedVercelToolOptions:

Full Example

Behavior on Denial

By default, gatedVercelTool throws an AttestaDenied error when a tool call is denied:
You can customize this with the onDenied callback:
gatedVercelTool creates a shallow copy of the original tool with the wrapped execute function. The original tool object is not mutated. If the tool has no execute function, the original tool is returned unchanged.

Middleware: createAttestaMiddleware

Returns an object with experimental_onToolCall that can be spread into generateText or streamText options. This intercepts all tool calls in the pipeline, not just individually wrapped tools.

API

AttestaMiddlewareOptions:

Full Example

Behavior on Denial

The middleware throws AttestaDenied when a tool call is denied. Unlike gatedVercelTool, there is no onDenied callback — the error propagates to the caller:

Streaming with streamText

The middleware works with streamText as well:
When using streamText, the experimental_onToolCall hook fires before the tool executes. If the tool call is denied, the AttestaDenied error interrupts the stream. Make sure your error handling accounts for stream interruption.

Custom Action Names

Use getActionName to derive meaningful action names from tool calls:
This is useful when tool names are generic (e.g., query, execute) but the risk depends on the context.

Tool Wrapper vs. Middleware

Do not combine gatedVercelTool and createAttestaMiddleware on the same tool. This would evaluate the tool call twice — once by the wrapper and once by the middleware. Use one or the other.

LangChain (TS)

TypeScript LangChain integration

Integrations Overview

Compare all framework integrations