Menu

How an AI agent pays for an API with x402 (HTTP 402, USDC, no API key)
📰

How an AI agent pays for an API with x402 (HTTP 402, USDC, no API key)

DEV Community: api·FastAF·1 day ago
#xQhDa85c
#devtoapi#devto#dev#payment#fastaf
Reading 0:00
15s threshold

Most APIs assume a human is somewhere in the loop: someone signs up, verifies an email, adds a card, copies an API key into an environment variable and keeps an eye on the monthly invoice. That works for applications. It works less well for autonomous AI agents, which may need a single piece of data from a service they have never used before, at 3 a.m., with nobody around to fill in a signup form.

x402 is an attempt to fix that by using a status code that has been sitting in the HTTP spec for decades: 402 Payment Required . This article explains how the flow works, shows a real 402 response from a live API ( api.fastaf.co ), walks through a minimal TypeScript client, and discusses when per-call payment makes sense and when it does not.

HTTP 402, briefly

HTTP 402 was reserved early on "for future use" and, for most of the web's history, nobody used it in a standard way.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.