A web search tool for LangChain and the Vercel AI SDK, paid per call with x402
Disclosure: I build x402serps. Try without a wallet (25-call trial) import { tool } from "ai"; import { z } from "zod"; export const webSearch = tool({ description: "Search the web", parameters: z.obje
Disclosure: I build x402serps.
Try without a wallet (25-call trial)
import { tool } from "ai"; import { z } from "zod";
export const webSearch = tool({
description: "Search the web",
parameters: z.object({ q: z.string() }),
execute: async ({ q }) => (await fetch("https://x402serps.com/api/v1/search", {
method: "POST", headers: { "content-type": "application/json", "X-Trial": "1" },
body: JSON.stringify({ q }) })).json(),
});
Production: pay per call
Wrap fetch with an x402 client (e.g. @x402/fetch) and drop the trial header. The endpoint answers 402 with a price; the client signs $0.004 USDC and retries.
LangChain (Python) and AI SDK guides: https://x402serps.com/docs/langchain?utm_source=devto&utm_medium=article&utm_campaign=100sales and https://x402serps.com/docs/vercel-ai-sdk?utm_source=devto&utm_medium=article&utm_campaign=100sales
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.