Setting Up Payment Capabilities with the OpenAI Agents SDK
Your OpenAI agent can call tools, browse the web, and write code. What it can’t do out of the box is pay for anything. You’re about to fix that.

Quick answer: The OpenAI Agents SDK has no native payment layer. To set up OpenAI agent payments, you register a payment tool that the agent can call mid-task, back it with an account that has isolated credentials and a spending cap, and surface revocation controls so you can cut access without touching the rest of your app. ATXP provides exactly that infrastructure — a per-agent handle, IOU balance, and spending cap wired in via a single tool definition.
What the OpenAI Agents SDK Actually Gives You (and What It Doesn’t)
The SDK handles orchestration, tool-calling, and handoffs between agents. It deliberately does not ship a payment primitive. That’s not an oversight — payment state doesn’t belong in a language model context window. It belongs in dedicated infrastructure with audit logs, spending controls, and revocation.
What the SDK does give you is a clean extension point: tools. Any capability you want an agent to have — including spending money — gets defined as a tool with a JSON schema, and the model decides when to invoke it. That’s the seam where payment infrastructure plugs in.
Step 1 — Provision a Payment Identity for Your Agent
Before writing any code, your agent needs its own payment account. Sharing your personal or company payment credentials with an agent is a blast radius problem — one runaway loop or injected instruction and you’ve handed an attacker access to your entire balance.
With ATXP, each agent gets:
- A unique handle (e.g.,
agent:research-bot-prod) - An IOU balance funded from your account
- A spending cap you set at provisioning time
- A revocable credential scoped only to that agent
Sign up at atxp.ai and create an agent account. Note the agent handle and API key — you’ll need both in the next step.
Step 2 — Define the Payment Tool
The OpenAI Agents SDK uses a @tool decorator pattern. Here’s a minimal payment tool that calls the ATXP API:
import httpx
from agents import tool
ATXP_API_KEY = "atxp_live_..." # agent-scoped key, not your root key
ATXP_HANDLE = "agent:research-bot-prod"
@tool
def pay_for_service(recipient_handle: str, amount_usd: float, memo: str) -> str:
"""
Pay another agent or API endpoint from this agent's ATXP balance.
Use this when a service returns a 402 Payment Required response,
or when an upstream agent requests payment for a subtask.
"""
response = httpx.post(
"https://api.atxp.ai/v1/pay",
headers={"Authorization": f"Bearer {ATXP_API_KEY}"},
json={
"from": ATXP_HANDLE,
"to": recipient_handle,
"amount": amount_usd,
"memo": memo,
},
timeout=10,
)
response.raise_for_status()
data = response.json()
return f"Payment confirmed. Transaction ID: {data['txn_id']}. Remaining balance: ${data['balance_remaining']:.2f}"
A few things worth noting here:
- The
fromfield is hardcoded to this agent’s handle — the agent cannot impersonate another identity - The tool returns remaining balance so the model can reason about whether it can afford the next step
timeout=10is not optional; tool calls that hang will stall your entire agent run
Step 3 — Wire the Tool Into Your Agent
from agents import Agent, Runner
from openai import AsyncOpenAI
client = AsyncOpenAI()
research_agent = Agent(
name="Research Agent",
instructions="""
You are a research assistant. You can pay for API calls and data sources
using the pay_for_service tool. Never spend more than $2.00 on a single
data source without confirming with the user first.
""",
tools=[pay_for_service],
model="gpt-4o",
)
async def run(query: str):
result = await Runner.run(research_agent, query)
return result.final_output
The instruction constraint (“never spend more than $2.00 without confirming”) is a soft guardrail. It’s useful for shaping model behavior, but it is not a security control. The hard cap lives in your ATXP account settings, enforced server-side regardless of what the model decides.
Key takeaway: Set both a prompt-level constraint and a server-side spending cap. Prompt constraints shape normal behavior. Server-side caps catch everything else.
Step 4 — Set Spending Caps and Alerts
Log into atxp.ai and configure three limits for your agent account:
| Limit type | Recommended starting value | Where to set |
|---|---|---|
| Per-transaction cap | $2.00 | Agent settings → Tx limit |
| Per-run cap | $10.00 | Agent settings → Session limit |
| Daily cap | $25.00 | Agent settings → Daily limit |
| Low-balance alert | 20% of funded amount | Notifications |
These caps are enforced at the API level. If the agent’s tool call would breach any limit, the API returns a 402 Limit Exceeded error with a structured body your tool can surface back to the model gracefully.
Step 5 — Handle 402 Responses from External APIs
If your agent calls APIs that implement the x402 protocol, it will sometimes receive a 402 Payment Required response before it can access data. ATXP agents handle x402 challenges automatically — the IOU credit is deducted, the challenge response is constructed, and the original request retries, all within the tool call.
You don’t need extra code for this. The ATXP SDK middleware intercepts 402s from any httpx request made with your agent credential. To enable it:
import atxp
# Patch httpx client used by your tools
http_client = atxp.instrument_client(
httpx.AsyncClient(),
agent_handle=ATXP_HANDLE,
api_key=ATXP_API_KEY,
)
Now any tool that uses http_client will pay-and-retry 402 responses automatically, within the agent’s spending cap.
Revocation: The Part Most Tutorials Skip
When something goes wrong — and with agentic systems, something will go wrong — you need to be able to cut an agent’s payment access in under 10 seconds without redeploying your application.
In your ATXP dashboard, every agent handle has a single-click revoke button. After revocation, any tool call using that agent’s credential returns 401 Revoked. The model receives the error, surfaces it in output, and stops spending. Your other agents and your application keep running.
This is the core argument for isolated per-agent credentials. If research-bot-prod starts behaving badly, you revoke research-bot-prod — not your entire payment account.
Setting up OpenAI agent payments correctly takes about 30 minutes. Most of that time is deciding on your spending caps, not writing code. The tool definition is ~20 lines. The blast-radius protection is a config change.
Get started on atxp.ai — provision your first agent account and have a payment-capable agent running before end of day.