Coinbase AgentKit
agentsvc tools for AgentKit agents
AgentKit already ships an x402 action provider. With it, an agent that has a wallet can call any of our 127 services and pay per call ($0.0015 to $0.6, USDC on Base). No API key, no account, no extra package. Give the agent the endpoint of the service it needs, as shown below.
Setup
npm install @coinbase/agentkit viem@2.38.3
import { AgentKit, ViemWalletProvider, x402ActionProvider } from "@coinbase/agentkit";
import { createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { base } from "viem/chains";
const walletClient = createWalletClient({
account: privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`),
chain: base,
transport: http(),
});
const agentkit = await AgentKit.from({
walletProvider: new ViemWalletProvider(walletClient),
actionProviders: [x402ActionProvider()],
});Use the same viem version as AgentKit (2.38.3 for AgentKit 0.10.4), otherwise the wallet client types do not match. The wallet needs a little USDC on Base; it pays no gas.
Call a service
Give the agent the endpoint and the input, or call the action yourself. The provider sends the request, gets our 402 price, signs the USDC payment and retries:
const action = agentkit.getActions().find(a => a.name.endsWith("make_http_request_with_x402"))!;
const result = await action.invoke({
url: "https://agentsvc.io/api/v1/proxy/email-verify",
method: "POST",
body: { email: "support@microsoft.com" },
});With an LLM, hand agentkit to the framework extension (@coinbase/agentkit-langchain, -vercel-ai-sdk or -model-context-protocol) and tell the agent which endpoint to use, for example: "Verify emails with POST https://agentsvc.io/api/v1/proxy/email-verify". Each service page lists its input: /services.
Let the agent find services
The action discover_x402_services searches the Coinbase x402 Bazaar, where all agentsvc services are listed. In AgentKit 0.10.4 it finds almost nothing: it reads descriptions of current (x402 v2) entries from a field the Bazaar no longer fills, so every v2 service is filtered out (issue #1400, fix in PR #1460). Until that is released, give the agent the endpoint directly, or let it search our catalog: GET https://agentsvc.io/api/v1/services.
Good to know
- Inputs are checked before payment: a missing field gets a 400 and nothing is charged. Failed calls are never charged.
- AgentKit 0.10.4 sends usage statistics to Coinbase in the background. When that request fails, Node can stop with an unhandled rejection. A
process.on("unhandledRejection", ...)handler keeps the agent running. - Many calls in a loop: buy prepaid credit at /credits and call with
Authorization: Bearer asvc_cr_...instead of paying each call on chain. - Other frameworks: LangChain, Vercel AI SDK, all clients in the docs.