<!-- tempo-docs-context -->
> Source: [/docs/agents](https://tempo.xyz/developers/docs/agents.md)
> Section: [Machine Payments](https://tempo.xyz/developers/docs/agents.md). Pay for APIs, accept API payments, find services, and use Machine Payments Protocol (MPP).
> [Documentation index](https://tempo.xyz/developers/llms.txt) · [Docs skill](https://tempo.xyz/developers/SKILL.md)

> Tempo MCP: Use `search`, `find_pages`, `read_page`, and `code` at `https://mcp.tempo.xyz` for Tempo and related documentation.
> If an indexed page is missing or reflects an older site, read this site’s [documentation index](https://tempo.xyz/developers/llms.txt) and Markdown pages directly.

<span id="agents" />

<span id="choose-your-agent-integration" />

<span id="choose-a-machine-payment-integration" />

# Machine payments

Pay for an API as part of the HTTP request, or charge for your own service. The Machine Payments Protocol (MPP) lets a server request payment and a client retry with payment authorization.

[Pay for an API →](#pay-for-an-api) · [Accept API payments →](#accept-api-payments)

An agent pays for a service through a machine payment on Tempo.

<span id="pay-for-services" />

## Pay for an API

Install `mppx` and `viem`, then [configure the payer account](https://tempo.xyz/developers/docs/guide/machine-payments/client#define-the-mpp-payer-account). For the CLI, [connect Tempo Wallet](https://tempo.xyz/developers/docs/cli/wallet#download-the-tempo-wallet-cli). Set `PAID_API_URL` in the CLI or `paidUrl` in TypeScript to the service's endpoint. The [MPP client setup](https://tempo.xyz/developers/docs/network/examples#machine-payment-clients) supplies `Mppx`, `tempo`, and a mainnet Wagmi configuration. These clients pay with real funds unless both client and service use testnet.

:::code-group
```ts [Viem]
  const mppx = Mppx.create({
    polyfill: false,
    methods: [tempo({ account })],
  })
  const response = await mppx.fetch(paidUrl)
  console.log(await response.text())
```

```bash [CLI]
tempo request --max-spend 0.10 "$PAID_API_URL"
```

```ts [Wagmi]
  const paymentMethod = tempo({
    getClient: ({ chainId }) => {
      if (chainId !== undefined && chainId !== tempoMainnet.id)
        throw new Error('This wallet configuration supports Tempo Mainnet only')
      return getConnectorClient(mppConfig, { chainId: tempoMainnet.id })
    },
  })
  const mppx = Mppx.create({ polyfill: false, methods: [paymentMethod] })
  const response = await mppx.fetch(paidUrl)
  console.log(await response.text())
```
:::

The example calls a GET endpoint. Use the method and request body from the service's documentation for other requests. Preview payment terms with `tempo request --dry-run "$PAID_API_URL"` before paying.

Choose the complete integration for your application:

* [Pay from your application](https://tempo.xyz/developers/docs/guide/machine-payments/client) — Handle payment challenges with an MPP client.
* [Pay from a terminal](https://tempo.xyz/developers/docs/guide/machine-payments/agent) — Find services and make paid requests with the Tempo CLI.
* [Use Mercator](https://tempo.xyz/developers/docs/guide/mercator) — Give an agent service discovery, quotes, and paid execution.

Account access is separate from an API payment. Use [access keys](https://tempo.xyz/developers/docs/accounts/agents) to give an agent defined spending permissions and an expiry; use the client guides above to make requests.

<span id="accept-payments-for-an-api" />

## Accept API payments

Configure `mppx` with your payment token, recipient address, and server secret using the [server quickstart](https://tempo.xyz/developers/docs/guide/machine-payments/server). Then protect a route with a fixed price per request:

:::code-group
```ts [Next.js]
export const GET = mppx.charge({ amount: '0.10' })(
  () => Response.json({ data: 'Your paid resource' }),
)
```

```ts [Hono]
app.get('/resource',
  mppx.charge({ amount: '0.10' }),
  (c) => c.json({ data: 'Your paid resource' }),
)
```
:::

Each tab uses the framework-specific `mppx` instance from the server quickstart. `amount` is in the configured token's decimal units. Follow [One-time payments](https://tempo.xyz/developers/docs/guide/machine-payments/one-time-payments) for a complete service.

The server returns a `402 Payment Required` challenge. The client authorizes payment and retries; the server verifies it before returning the resource and receipt. Inspect an endpoint's HTTP challenge without paying:

```bash [API (HTTP)]
curl -i "$PAID_API_URL"
```

The [`WWW-Authenticate` challenge](https://tempo.xyz/developers/docs/guide/machine-payments#mpp-payment-flow) describes the payment terms. A plain cURL request does not sign or pay the challenge. The [payment flow demo](https://tempo.xyz/developers/docs/guide/machine-payments#mpp-payment-flow) shows the complete exchange.

## Payment sessions

Use a session when charges accumulate during service usage. The client funds a payment channel and signs vouchers as it consumes the service, without sending an onchain transaction for every request. With the [Next.js session configuration](https://tempo.xyz/developers/docs/guide/machine-payments/pay-as-you-go), charge per resource:

```ts [Next.js]
export const GET = mppx.session({ amount: '0.01', unitType: 'photo' })(
  () => Response.json({ url: 'https://your-service.example/photo.jpg' }),
)
```

* [Pay-as-you-go payments](https://tempo.xyz/developers/docs/guide/machine-payments/pay-as-you-go) for metered API usage.
* [Streamed payments](https://tempo.xyz/developers/docs/guide/machine-payments/streamed-payments) for charges during a streaming response.

<span id="build-with-the-machine-payments-protocol" />

<span id="understand-the-mpp-payment-flow" />

<span id="give-your-coding-agent-tempo-documentation" />

<span id="build-the-integration-with-your-coding-agent" />

Use [How MPP works](https://tempo.xyz/developers/docs/guide/machine-payments) for payment intents and the request lifecycle, and the [MPP documentation](https://mpp.dev) for protocol and SDK references. [Build with AI](https://tempo.xyz/developers/docs/guide/using-tempo-with-ai) connects your coding agent to Tempo documentation.
