Vercel AI SDK

agent402-ai-sdk · npm · MIT

Gives a Vercel AI SDK agent four meta tools that reach the whole catalog: the model describes a task, agent402_find or agent402_route picks the tool, and agent402_call runs and pays for it. Works with generateText and streamText on any provider the SDK supports.

Install

npm install agent402-ai-sdk ai zod

Example

import { agent402Tools } from "agent402-ai-sdk";
import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";

const tools = await agent402Tools();   // free tier: proof-of-work, no wallet

const { text } = await generateText({
  model: openai("gpt-4o"),
  tools,
  prompt: "Hash 'hello world' with sha256",
});

What it exposes

  • agent402_find: a plain-language task in, the best-matching tools out (slug, route, price, input schema, a ready example).
  • agent402_route: ranks tools across every indexed x402 seller; include: "external" leaves this server out.
  • agent402_call: calls a tool by slug and pays for it.
  • agent402_about: the service manifest (payment options, capability map, MCP connector).
  • agent402ToolSpecs() returns the same four as framework-agnostic specs (name, description, JSON Schema, execute) with no framework dependency.

How payment works

  • Pure-CPU tools: agent402_call fetches a proof-of-work challenge and solves it in-process, so no wallet is needed.
  • Wallet-only tools: pass fetch, a payment-wrapped fetch. @x402/fetch pays in USDC over x402 on whichever chain your wallet is funded for; a stock mppx fetch pays over MPP.
  • Unpaid lookups (find, route, about) use fetchImpl and never spend anything.
const tools = await agent402Tools({ fetch: payFetch }); // an x402- or MPP-wrapped fetch

A call that fails is not charged: settlement runs after the tool and only on a successful response. Background: What x402 is · MPP (Machine Payments Protocol).

Tools to try first

Hash$0.001
hash
Web search$0.02
search
Extract article$0.010
extract
Browser render$0.02
render
Route and execute$0.01
route-execute

Every tool, price and input schema: the catalog.

Links

agent402-ai-sdk on npm · source on GitHub · configuration reference
Guides: One payment, any proven seller: the x402 Smart Order Router · Make your AI agent pay for what it needs: x402 in 5 minutes
All integrations