> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xquik.com/llms.txt
> Use this file to discover all available pages before exploring further.

# MPP quickstart

> Make your first pay-per-use API call with the Machine Payments Protocol

<blockquote className="agent-llms-directive">
  For the complete documentation index, see <a href="/llms.txt">llms.txt</a>.
</blockquote>

Call Xquik endpoints without an account or subscription. Pay per request with Tempo (USDC) using the `mppx` SDK.

## Step 1: Install the SDK

```bash theme={null}
npm i mppx viem
```

The `mppx` package provides both client and server utilities. You only need the client. `viem` is required for wallet account management.

## Step 2: Set up a Tempo wallet

You need a Tempo wallet funded with USDC, plus its raw hex private key for the `mppx` client.

**Path A - CLI only (recommended for agents)**

```bash theme={null}
mppx account create             # generates a local keychain-backed account
mppx account export             # prints the hex private key (0x...)
```

Fund the account's address with USDC on Tempo, then copy the exported key into `TEMPO_PRIVATE_KEY`.

**Path B - Web wallet as a USDC source**

Use [wallet.tempo.xyz/welcome](https://wallet.tempo.xyz/welcome) as a hosted UI to buy & send USDC. Run `mppx account create` to mint a local account, copy its address, send USDC from the web wallet to that address, then run `mppx account export` to get the hex key.

The web wallet cannot be imported into `mppx`. It is a funding source, not a key source.

> **Warning:** Store your private key securely. Never commit it to version control. Use environment variables.

## Step 3: Make a charge request

Look up a single tweet. The SDK intercepts 402 responses, pays via Tempo, and retries automatically.

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

// Configure the MPP client - this patches global fetch
// to automatically handle 402 Payment Required challenges
Mppx.create({
  methods: [
    tempo({
      account: privateKeyToAccount(process.env.TEMPO_PRIVATE_KEY as `0x${string}`),
    }),
  ],
});

// Now any fetch to an MPP-enabled endpoint auto-pays
const response = await fetch(
  "https://xquik.com/api/v1/x/tweets/1893456789012345678"
);
const data = await response.json();
console.log(data.tweet.text);
```

`Mppx.create()` patches the global `fetch` function. When a request returns 402 with a `WWW-Authenticate: Payment` header, the SDK pays the requested amount (USD 0.00015) and retransmits the request with an `Authorization: Payment` credential. The response includes a `Payment-Receipt` header confirming settlement.

## Step 4: Make a session request

Search tweets with per-result pricing. You pay USD 0.00015 per tweet returned.

```typescript theme={null}
// Global fetch is already patched by Mppx.create() above
const response = await fetch(
  "https://xquik.com/api/v1/x/tweets/search?q=TypeScript&limit=20"
);
const data = await response.json();
console.log(`Found ${data.tweets.length} tweets`);
// Cost: USD 0.00015 times number of tweets returned
```

Session payments deposit funds upfront and deduct per result. The SDK manages the deposit and voucher exchange automatically. Your maximum cost = price times limit parameter (e.g., searching with `limit=20` at USD 0.00015 per tweet costs at most USD 0.003).

## Step 5: Raw HTTP flow (without SDK)

If you are not using the `mppx` SDK, you can implement the protocol manually.

**Step 1: Request the endpoint**

```bash theme={null}
curl -i https://xquik.com/api/v1/x/tweets/1893456789012345678
```

**Step 2: Receive the 402 challenge**

```text theme={null}
HTTP/2 402
WWW-Authenticate: Payment id="abc...", realm="xquik.com", method="tempo", intent="charge", request="eyJhbW91bnQiOi..."
```

The `request` parameter is a base64url-encoded JSON object containing the amount, currency, and recipient address.

**Step 3: Pay and retry**

After completing the Tempo payment, retry the request with the payment credential:

```bash theme={null}
curl -i https://xquik.com/api/v1/x/tweets/1893456789012345678 \
  -H "Authorization: Payment eyJjaGFsbGVuZ2UiOnsi..."
```

The `Authorization: Payment` value is a base64url-encoded JSON object containing the original challenge and your payment proof.

**Step 4: Receive the response + receipt**

```text theme={null}
HTTP/2 200
Payment-Receipt: eyJzdGF0dXMiOiJzdWNjZXNzIiwi...
Content-Type: application/json

{"tweet": {"id": "1893456789012345678", "text": "..."}}
```

The `Payment-Receipt` header confirms the payment was settled.

## Next steps

* [MPP overview](/mpp/overview): Eligible endpoints, pricing, and protocol details.
* [Get tweet](/api-reference/x/get-tweet): Full endpoint reference for tweet lookups.
* [Search tweets](/api-reference/x/search-tweets): Full endpoint reference for tweet search.
