# Machine Payments Protocol (MPP) on Tempo

The [Machine Payments Protocol](https://mpp.dev/) lets a wallet pay for an API call when the server quotes a price. Paid REST endpoints and MCP tools on glim.sh accept USDC.e on Tempo through MPP, alongside x402 and account keys, at the same per-call prices.

## Make your first paid request

Use [x402-proxy](https://github.com/cascade-protocol/x402-proxy) 0.12.3 or newer. Run setup if you need a wallet, then send USDC.e on Tempo mainnet to the Tempo address shown by the wallet command.

**Set up and check your wallet**

```
npx x402-proxy setup
npx x402-proxy wallet
```

Web search costs $0.01 per call. Select MPP to have the proxy sign the challenge and retry automatically.

**Search the web with a Tempo wallet**

```
npx x402-proxy --protocol mpp --method POST \
  --header "Content-Type: application/json" \
  --body '{"query":"Machine Payments Protocol"}' https://glim.sh/api/v1/web/search
```

## Sign a charge with the mppx CLI

An unpaid REST request returns HTTP 402 with both `PAYMENT-REQUIRED` (x402) and `WWW-Authenticate: Payment ...` (MPP). Sign the `intent="charge"` challenge. Retry the same request with the credential in `Authorization`. A successful charge returns the data and a `Payment-Receipt` header confirming settlement.

Use a funded account from `npx mppx account list`. To set one up, run `npx mppx account create -a main --network mainnet` and fund its address with USDC.e on Tempo. The example uses the account named `main`.

**Run with Node.js and the mppx CLI**

```
node --input-type=module <<'JS'
import { execFileSync } from "node:child_process";

const url = "https://glim.sh/api/v1/web/search";
const headers = { "Content-Type": "application/json" };
const request = { method: "POST", body: JSON.stringify({ query: "Machine Payments Protocol" }) };
const unpaid = await fetch(url, { ...request, headers });
const charge = unpaid.headers.get("WWW-Authenticate")?.split(/,\s*(?=Payment )/)
  .find(value => value.includes('intent="charge"'));
if (unpaid.status !== 402 || !charge) throw Error("Expected an MPP charge challenge");

const credential = execFileSync("npx", ["-y", "mppx", "sign", "-a", "main", "--challenge", charge],
  { encoding: "utf8" }).trim();
const paid = await fetch(url, { ...request, headers: { ...headers, Authorization: credential } });
if (!paid.ok || !paid.headers.has("Payment-Receipt")) throw Error("No settled charge");
console.log(await paid.json());
JS
```

## Pay from JavaScript

Install the [mppx SDK](https://mpp.dev/sdk/typescript) and viem with `npm install mppx viem`. In a server-side Node.js module, supply your funded Tempo wallet's hex private key through the `TEMPO_PRIVATE_KEY` environment variable.

**Fetch with a one-time charge**

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

const account = privateKeyToAccount(process.env.TEMPO_PRIVATE_KEY);
const client = Mppx.create({ methods: [tempo.charge({ account })], polyfill: false });
const res = await client.fetch("https://glim.sh/api/v1/web/search", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ query: "Machine Payments Protocol" }),
});
if (!res.ok || !res.headers.has("Payment-Receipt")) throw Error("No settled charge");
console.log(await res.json());
```

## Streaming inference

For streaming inference, send `stream: true` to `POST /api/v1/inference/v1/chat/completions`. Pay the quoted maximum price once before the stream starts. The response carries the charge receipt in the `Payment-Receipt` header.

## MPP over MCP

At `https://glim.sh/mcp`, a wallet can send an MPP charge credential in `_meta["org.paymentauth/credential"]` on a tool call and read the receipt from `_meta["org.paymentauth/receipt"]`. An initial unpaid tool call returns an HTTP 200 tool error with an x402 challenge. With x402-proxy 0.12.3, `mcp --protocol mpp` returns that error to the client because it has no MPP challenge to sign. Use REST for automatic MPP payments, or follow the [MCP quickstart](https://glim.sh/docs/quickstart.md) for x402 or account access.

## Prices and discovery

Use the amount and currency in the live challenge as your quote. The realm for the public API is `glim.sh`. [MPPscan lists the service and its endpoints](https://mppscan.com/server/043ddab819fabf99c0e2d8b080a044418e85686dfd3e2cbe8279452f568f8aec). For billing from a prepaid balance, see [Payments & auth](https://glim.sh/docs/payments.md).

## Troubleshooting

- `memo is not bound to this challenge` with an older x402-proxy: upgrade to 0.12.3 or newer and request a fresh challenge.
- `Transaction hash has already been used` means that payment was presented before. To make another paid call, request a fresh challenge and sign it.

---

## All docs pages


**Get started**

- [Introduction](https://glim.sh/docs.md)
- [MCP quickstart](https://glim.sh/docs/quickstart.md)
- [REST API quickstart](https://glim.sh/docs/quickstart-rest.md)
- [JavaScript quickstart](https://glim.sh/docs/quickstart-javascript.md)
- [Python quickstart](https://glim.sh/docs/quickstart-python.md)
- [Payments & auth](https://glim.sh/docs/payments.md)
- [MPP (Tempo)](https://glim.sh/docs/mpp.md)

**Tools**

- [Twitter / X](https://glim.sh/docs/twitter.md)
- [Reddit](https://glim.sh/docs/reddit.md)
- [Web](https://glim.sh/docs/web.md)
- [GitHub](https://glim.sh/docs/github.md)
- [Amazon](https://glim.sh/docs/amazon.md)
- [YouTube](https://glim.sh/docs/youtube.md)
- [Telegram](https://glim.sh/docs/telegram.md)

**Reference**

- [Changelog](https://glim.sh/docs/changelog.md)
- [API reference](https://glim.sh/docs/api-reference)
- [OpenAPI spec](https://glim.sh/openapi.json)
