---
title: "It's an MPP service · Tempo AI Platform docs"
description: "How every paid route answers 402, takes a session voucher from any wallet, and makes the wallet that paid its owner."
url: "https://gateway.tempo-dev.workers.dev/docs/guides/mpp"
---

> Every page of the Tempo AI Platform is Markdown at its URL with .md, or with Accept: text/markdown. The index of every page is https://gateway.tempo-dev.workers.dev/llms.txt, the API https://gateway.tempo-dev.workers.dev/openapi.json and the MCP server https://gateway.tempo-dev.workers.dev/mcp.

# It's an MPP service

Underneath the Tempo Key, every paid route is an MPP service. It answers 402 Payment Required with a session challenge, and any client holding a Tempo wallet pays it with a voucher, with no account and no key. The wallet that paid is who the caller is, and it owns what it stores.

[Get your Tempo Key](https://gateway.tempo-dev.workers.dev/key.md) · [How a key pays](https://gateway.tempo-dev.workers.dev/docs/keys.md#paying)

## Architecture

```text
client                                  gateway
POST /v1/kv/get ---------------------->  validate: a bad body is 400
                                           and costs nothing
                <----------------------  402 WWW-Authenticate: Payment
                                           tempo/session, MACH then OUSD
open a channel on Tempo, once
POST /v1/kv/get ---------------------->  verify the voucher: one
  Authorization: Payment <voucher>         compare-and-swap in Channels
                                         owner = the channel's payer
                <----------------------  200 with Payment-Receipt
```

The handshake: a 402 with the challenge, one channel opened on Tempo, then a voucher with each request.

## The challenge

An unpaid request to a paid route is validated first, so a malformed one answers 400 and is never charged, and then answers 402 with a `WWW-Authenticate: Payment` header holding two `tempo/session` challenges, MACH first and OUSD second:

- **Amount**\
  The route's price, or for a model call the most it may cost.
- **Recipient and chain**\
  The platform's recipient, `0x40def0Cf3B5d28B6e9a7976BA10591e515AfECFE`, on Tempo mainnet, chain 4217.
- **Operator**\
  The gateway's own address, so it may settle and close the channel for the payer.
- **Fee payer**\
  The gateway sponsors the network fee of opening and topping up the channel.

A wallet that holds MACH pays MACH directly. One that holds another stablecoin swaps it to OUSD on Tempo's DEX, which mppx's client does by itself.

## Paying with a voucher

1. The client opens a channel once: a deposit in Tempo's channel escrow, one transaction.
2. For each request it signs a voucher for its running total and sends it as `Authorization: Payment`. The challenge can be reused, so a client that has seen a route's 402 sends the voucher with its first request.
3. The gateway checks the voucher against the channel's state, which it keeps in a Durable Object and trusts for up to 300 s before reading the chain again, and charges it in the same compare-and-swap. A paid request's payment takes tens of milliseconds.
4. The route runs, and the answer carries a `Payment-Receipt`. A model call's unused hold is credited back to the channel once its usage is known.

## The wallet is the identity

- **Who paid**\
  The owner of a request is the payer of the channel that paid it, read after the voucher verified. A voucher signed by anyone but the channel's payer or its authorized signer is refused, so an access key reaches its wallet's data and a forged or replayed voucher gets a 402.
- **No header names it**\
  Nothing a caller sends says whose data it is. Every value, file, repository and sandbox is stored under the chain, the paying wallet and the `Gateway-App`, and another wallet's calls on its ids answer `not_found`.
- **Shared on purpose**\
  Another wallet reaches your items only through a grant you set, naming you with `Gateway-Owner` while paying for its own calls. [Sharing](https://gateway.tempo-dev.workers.dev/docs/memory.md#sharing)

## Settlement and closing

Every hour the gateway settles each channel's highest voucher within what it spent, as the channel's operator, and every minute it answers close requests: a close sends what was spent to the platform and the rest of the deposit back to the payer. A client can also close at once with a close credential on any paid route.

## Being a good client

- **Keep the channel**\
  Persist the channel between runs, with mppx's channel store. A client that forgets it opens a new channel, with a new deposit, every time it starts.
- **Name the app**\
  Routes that keep data act on the app Gateway-App names, default without it; the model routes do not use it.
- **From a browser**\
  Every route answers CORS for any origin and exposes `WWW-Authenticate` and `Payment-Receipt`, so a page can pay with its own fetch.

## Try it

**tempo request**

```sh
tempo request --mach -X POST \
  -H gateway-app:default \
  --json '{"key":"results/codecs"}' \
  https://gateway.tempo-dev.workers.dev/v1/kv/get
```

**mppx**

```ts
import { Mppx, tempo } from "mppx/client";
import { createSqliteChannelStore } from "mppx/client/node";
import { privateKeyToAccount } from "viem/accounts";

const account = privateKeyToAccount(process.env.PRIVATE_KEY);
const channelStore = createSqliteChannelStore({ namespace: "https://gateway.tempo-dev.workers.dev" });
const mppx = Mppx.create({ methods: [tempo({ account, channelStore, maxDeposit: "1" })], polyfill: false });

const response = await mppx.fetch("https://gateway.tempo-dev.workers.dev/v1/kv/get", {
  body: JSON.stringify({ key: "results/codecs" }),
  headers: { "content-type": "application/json", "gateway-app": "default" },
  method: "POST",
});
```

**The 402**

```sh
curl -i https://gateway.tempo-dev.workers.dev/v1/kv/get \
  -H gateway-app:default \
  -H content-type:application/json \
  -d '{"key":"results/codecs"}'
```

## Go deeper

- [Every tool](https://gateway.tempo-dev.workers.dev/docs/guides/tools.md#sessions): what one session pays for.
- [mpp.dev](https://mpp.dev): the protocol, its clients and its services.
- [OpenAPI](https://gateway.tempo-dev.workers.dev/openapi.json): every route.

[<- It's an MCP](https://gateway.tempo-dev.workers.dev/docs/guides/mcp.md) · [It speaks SSH ->](https://gateway.tempo-dev.workers.dev/docs/guides/ssh.md)
