---
title: Agentic Payments
description:
  Enable AI agents to pay for services, APIs, and resources autonomously using
  the x402 protocol.
---

AI agents are increasingly autonomous in their workflows: writing code, fetching
data, provisioning resources, and more. To operate fully independently, they
need a way to make "micropayments" for services programmatically, in real-time,
at minimal cost. Traditional payment rails don't work for micropayments.
Solana's sub-cent fees and sub-second finality make this technically and
economically viable.

## Why is this important?

For example, imagine a developer using an LLM to build an application needs data
from a paid API. To fetch some important data, a developer would need to stop
their workflow, research APIs, select a provider, create an account, add a
payment method, generate an API key, copy the key into their environment, and
then resume their workflow. This friction breaks flow state. For AI-assisted
workflows, it's a blocker.

Instead, with agentic payments, the agent can make the request, pay for it, and
continue with their workflow. No accounts. No API keys. No manual intervention.

### Pay for APIs with pay.sh

[pay.sh](https://pay.sh) is a payment layer for HTTP agents and command-line
tools. Refer to the [pay.sh docs](https://pay.sh/docs) to install `pay`. The
`pay` CLI wraps tools like `curl`, `codex`, and `claude` so they can call paid
APIs without provider accounts or API keys. When an API returns an MPP or x402
`402 Payment Required` challenge, `pay` asks your local wallet to approve
signing.

You can install Pay with:

```bash
brew install pay
```

or

```bash
npm install -g @solana/pay
```

Verify the installation with:

```bash
pay --version
```

The toolchain will set up your address for you. Run the following to setup and
topup your wallet:

```bash
pay setup
```

## The x402 Protocol

Agentic payments need a way for clients and servers to negotiate payment terms
over standard web infrastructure without disrupting traditional web interfaces.
The micropayment space is still nascent and new tools and standards will likely
emerge as the space evolves. The [x402 protocol](https://www.x402.org/),
however, has emerged as an early standard with strong ecosystem support. x402
uses
[HTTP's 402 "Payment Required"](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/402)
status code—a standard since HTTP/1.1 that only became practical with blockchain
settlement.

### How it works

The client makes a request, receives a 402 with payment terms, then retries with
a signed payment. The server delegates verification and settlement to a
facilitator, an optional intermediary that handles the onchain transaction
submission. Once the facilitator confirms settlement, the server returns the
requested content. This separation lets API providers accept payments without
managing any onchain infrastructure directly.

![x402 Flow Diagram](/assets/guides/x402/x402-flow-solana.png)

The protocol is stateless (no sessions or API keys), works with standard HTTP
infrastructure, and supports any SPL token the server accepts. Here's a snippet
of how to set up an Express server using x402 middleware:

```ts
app.use(
  paymentMiddleware(
    {
      "GET /costly-data": {
        accepts: [
          {
            scheme: "exact",
            price: "$0.001",
            network: "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",
            payTo: svmAddress
          }
        ],
        description: "Costly data",
        mimeType: "application/json"
      }
    },
    new x402ResourceServer(facilitatorClient).register(
      "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",
      new ExactSvmScheme()
    )
  )
);

app.get("/costly-data", (req, res) => {
  res.send({
    report: {
      data: "costly data"
    }
  });
});
```

To learn more on x402, check out our guides:

<Cards>
  <Card
    title="Introduction to x402"
    href="/docs/payments/agentic-payments/intro-to-x402"
    description="Protocol fundamentals and SDK options for building payment-enabled APIs."
  />
  <Card
    title="Build with Kora"
    href="/docs/payments/agentic-payments/x402-facilitator"
    description="Implement gasless x402 payments using Kora's signing infrastructure."
  />
</Cards>

### x402 Tooling

| SDK                                                             | Description                          |
| --------------------------------------------------------------- | ------------------------------------ |
| [Corbits](https://corbits.dev/)                                 | Solana-first x402 implementation     |
| [MCPay.tech](https://mcpay.tech/)                               | Pay-per-request for MCP servers      |
| [PayAI](https://payai.network/)                                 | x402 facilitator with Solana support |
| [x402 GitHub](https://github.com/coinbase/x402)                 | Reference implementation             |
| [ACK](https://github.com/agentcommercekit/ack)                  | Agent Commerce Kit                   |
| [A2A x402](https://github.com/google-agentic-commerce/a2a-x402) | Google's agent-to-agent payments     |
