Home › Docs › Adapters › OpenAI Agents SDK
OpenAI Agents SDK Adapter
agent402-openai-agentsFour meta tools (find, route, call, about) for the OpenAI Agents SDK (@openai/agents), built from the adapter's framework-agnostic specs. The SDK's run loop executes them.
Install
npm install agent402-openai-agents @openai/agents @x402/fetch @x402/core @x402/evm viem
Quick start
import { agent402Tools } from "agent402-openai-agents";
import { Agent, run } from "@openai/agents";
import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
const payClient = new x402Client();
registerExactEvmScheme(payClient, { signer: privateKeyToAccount(process.env.AGENT_KEY) });
const payFetch = wrapFetchWithPayment(fetch, payClient);
// agent402_call pays search and answer through this fetch
const tools = await agent402Tools({ fetch: payFetch });
const agent = new Agent({
name: "x402-agent",
instructions: "Use agent402 to find and call paid web tools when needed.",
tools,
});
const result = await run(agent, "Search the web for x402 payment protocol adoption, then answer with citations: what is the x402 payment protocol?");
No wallet yet? The pure-CPU tools (hash, uuid, base64, markdown, JSON and more) run free with proof-of-work and no wallet:
// the same four tools with no fetch: agent402_call pays pure-CPU tools with proof-of-work
const tools = await agent402Tools();
Configuration
| Option | Type | Description |
|---|---|---|
fetch |
typeof fetch |
A payment-wrapped fetch (@x402/fetch for x402, mppx for MPP) that agent402_call uses for wallet-only tools. |
fetchImpl |
typeof fetch |
The plain fetch used for the unpaid lookups (find, route, about) and proof-of-work calls. Defaults to the global fetch. |
baseUrl |
string |
Point to a self-hosted Agent402 instance. |
// A payment-wrapped fetch (@x402/fetch for x402, mppx for MPP) that agent402_call uses for wallet-only tools.
agent402Tools({ fetch: payFetch })
// The plain fetch used for the unpaid lookups (find, route, about) and proof-of-work calls. Defaults to the global fetch.
agent402Tools({ fetchImpl: globalThis.fetch })
// Point to a self-hosted Agent402 instance.
agent402Tools({ baseUrl: "https://my-agent402.example.com" })
Works with
@openai/agents
Agent
run()