Web search in Vercel AI SDK with x402serps
The AI SDK's MCP client (createMCPClient from @ai-sdk/mcp in AI SDK 6; experimental_createMCPClient from ai in AI SDK 5) connects over HTTP with headers and turns x402serps tools into AI SDK tools.
AI SDK 6
import { createMCPClient } from "@ai-sdk/mcp";
import { generateText, stepCountIs } from "ai";
const mcp = await createMCPClient({
transport: {
type: "http",
url: "https://x402serps.com/api/mcp",
headers: { Authorization: `Bearer ${process.env.X402SERPS_KEY}` }, // or { "X-Trial": "1" }
},
});
try {
const { text } = await generateText({
model: "openai/gpt-4.1",
tools: await mcp.tools(),
stopWhen: stepCountIs(5),
prompt: "Find this week's news about the x402 protocol",
});
console.log(text);
} finally {
await mcp.close();
}AI SDK 5
Same config, but import experimental_createMCPClient from ai and use transport: { type: "http", url, headers } (or the MCP SDK's StreamableHTTPClientTransport).
Pay per call with x402 instead: tool calls without a trial header or key return the x402 payment requirements, which an x402-aware client can pay in USDC on Base or Solana. Search is $0.004 a call. Buy a credit key on the pricing page.
Pricing · Docs · MCP · Integrations · Help