Skip to main content
The Vercel AI SDK is a TypeScript library for building AI-powered applications with React and JavaScript. When combined with AgentKit, your agents can interact with Base onchain while streaming responses to a chat UI — all deployable on Vercel.

Prerequisites

Quickstart

1

Install dependencies

Terminal
npm install @coinbase/agentkit-vercel-ai-sdk @coinbase/agentkit ai @ai-sdk/openai
2

Clone the example

Terminal
git clone https://github.com/coinbase/agentkit.git
cd agentkit/typescript
npm install && npm run build
cd examples/vercel-ai-sdk-cdp-chatbot
3

Configure environment variables

Terminal
cp .env-local .env
.env
CDP_API_KEY_NAME=your_cdp_key_name
CDP_API_KEY_PRIVATE_KEY=your_cdp_private_key
OPENAI_API_KEY=your_openai_key
4

Run the agent

Terminal
npm start

How it works

getVercelAITools converts an AgentKit instance into a tools object compatible with the Vercel AI SDK’s generateText and streamText functions.
chatbot.ts
import { AgentKit } from "@coinbase/agentkit";
import { getVercelAITools } from "@coinbase/agentkit-vercel-ai-sdk";
import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";

// Initialize AgentKit — reads CDP_API_KEY_NAME and CDP_API_KEY_PRIVATE_KEY from env
const agentKit = await AgentKit.from({
  cdpApiKeyName: process.env.CDP_API_KEY_NAME,
  cdpApiKeyPrivateKey: process.env.CDP_API_KEY_PRIVATE_KEY,
});

const tools = await getVercelAITools(agentKit);

const { text } = await generateText({
  model: openai("gpt-4o-mini"),
  system: "You are an onchain AI assistant with access to a wallet.",
  prompt: "What is my wallet address?",
  tools,
  maxSteps: 10,
});

console.log(text);
The maxSteps parameter allows multi-step tool usage — the model can call multiple tools in sequence to fulfill a single request.

Using different model providers

The Vercel AI SDK supports many model providers. Swap openai for any supported provider:
import { anthropic } from "@ai-sdk/anthropic";

const { text } = await generateText({
  model: anthropic("claude-3-7-sonnet-20250219"),
  system: "You are an onchain AI assistant with access to a wallet.",
  prompt: "What is my wallet address?",
  tools,
  maxSteps: 10,
});
See all supported providers in the Vercel AI SDK docs.

Next steps

Wallet setup

Configure a production-ready CDP wallet for your agent.

x402 payments

Add per-request stablecoin payments to your agent.