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

# MPP Get subscription status

> GET /agent/mpp/subscription — Plan stats, credits, and API keys for the payer wallet (MPP / Tempo / mppx).

<Note>
  **Beta.** Same response shape as [x402 subscription status](/guides/x402-agent-subscription); only the path and payment rail differ. Overview: [Agentic payments](/guides/agentic-payments).
</Note>

## Endpoint

```
GET https://mpp.mobula.io/agent/mpp/subscription
```

No query parameters. Payer identity comes from the **MPP** payment credential after you satisfy the **402** challenge (use **mppx** on Tempo per your environment).

## Payment

Discovery lists a small fixed USD fee for this check (see [`openapi.json`](https://api.mobula.io/openapi.json) → `x-payment-info` on this path).

## Flow

1. Request without payment → **402** with challenge.
2. Pay with **mppx**, retry with credential → **200** with plan stats, or **404** if no agent exists for that wallet.

## Response (success)

Same fields as the x402 guide: `user_id`, `api_keys`, `plan`, `last_payment`, `payment_frequency`, `left_days`, `credits_left`, `plan_active`. Full field reference: [x402 Get subscription status](/guides/x402-agent-subscription) — structure matches; use **this** path for MPP.

***

## Reference script

**Prerequisites:** `MPPX_PRIVATE_KEY`, optional **`API_URL`**, [`mppx`](https://docs.tempo.xyz/mpp), **bun**, **viem**. Run from the **monorepo root**.

**Source:** `agent-subscription.ts`

```typescript theme={null}
/**
 * MPP agent subscription — check plan stats (plan, credits, API keys, etc.).
 *
 * Usage:
 *   MPPX_PRIVATE_KEY=0x<key> bun run scripts/src/mpp/agent-subscription.ts
 *
 * Optional: API_URL (default: https://api.mobula.io)
 */

import { createPublicClient, formatUnits, http } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';

const API_URL = process.env.API_URL ?? 'https://mpp.mobula.io';

const PATHUSD = '0x20c0000000000000000000000000000000000000' as const;
const PATHUSD_DECIMALS = 6;
const PRIVATE_KEY = process.env.MPPX_PRIVATE_KEY as `0x${string}` | undefined;
if (!PRIVATE_KEY) {
  console.error('ERROR: Set MPPX_PRIVATE_KEY=0x<your_private_key>');
  process.exit(1);
}

const payer = privateKeyToAccount(PRIVATE_KEY as `0x${string}`);

const client = createPublicClient({
  chain: {
    id: 42431,
    name: 'Tempo Testnet',
    nativeCurrency: { name: 'ETH', symbol: 'ETH', decimals: 18 },
    rpcUrls: { default: { http: ['https://rpc.moderato.tempo.xyz'] } },
  },
  transport: http(),
});

const balanceOfAbi = [
  {
    type: 'function',
    name: 'balanceOf',
    inputs: [{ name: 'account', type: 'address' }],
    outputs: [{ name: '', type: 'uint256' }],
    stateMutability: 'view',
  },
] as const;

async function getPathUsdBalance(address: `0x${string}`): Promise<bigint> {
  return client.readContract({
    address: PATHUSD,
    abi: balanceOfAbi,
    functionName: 'balanceOf',
    args: [address],
  });
}

function fmtBalance(raw: bigint): string {
  return `${formatUnits(raw, PATHUSD_DECIMALS)} PathUSD`;
}

async function getRecipientFromChallenge(url: string): Promise<`0x${string}`> {
  const res = await fetch(url);
  const wwwAuth = res.headers.get('www-authenticate') || '';
  const requestMatch = wwwAuth.match(/request="([^"]*)"/);
  if (requestMatch) {
    const decoded = JSON.parse(Buffer.from(requestMatch[1], 'base64').toString());
    return decoded.recipient;
  }
  throw new Error('Could not parse recipient from challenge');
}

function mppxRequest(endpoint: string): string {
  const { execSync } = require('child_process');
  const result = execSync(`MPPX_PRIVATE_KEY=${PRIVATE_KEY} bunx mppx "${endpoint}" -v`, {
    encoding: 'utf-8',
    cwd: process.cwd(),
    timeout: 60_000,
  });
  return result;
}

const endpointUrl = `${API_URL}/agent/mpp/subscription`;
const recipient = await getRecipientFromChallenge(endpointUrl);

console.log('\n--- Addresses ---');
console.log(`  Payer:     ${payer.address}`);
console.log(`  Recipient: ${recipient}`);

console.log('\n--- Step 1: Balances BEFORE payment ---\n');
const payerBefore = await getPathUsdBalance(payer.address);
const recipientBefore = await getPathUsdBalance(recipient);
console.log(`  Payer:     ${fmtBalance(payerBefore)}`);
console.log(`  Recipient: ${fmtBalance(recipientBefore)}`);

console.log('\n--- Step 2: Check subscription — $0.001 ---\n');
try {
  const result = mppxRequest(endpointUrl);
  console.log(result);
} catch (err: unknown) {
  const execErr = err as { stdout?: string; stderr?: string };
  console.error('mppx CLI failed:');
  if (execErr.stdout) console.log(execErr.stdout);
  if (execErr.stderr) console.error(execErr.stderr);
  process.exit(1);
}

console.log('--- Step 3: Balances AFTER payment ---\n');
const payerAfter = await getPathUsdBalance(payer.address);
const recipientAfter = await getPathUsdBalance(recipient);
console.log(`  Payer:     ${fmtBalance(payerAfter)}`);
console.log(`  Recipient: ${fmtBalance(recipientAfter)}`);

console.log('\n--- Balance changes ---\n');
console.log(
  `  Payer:     ${fmtBalance(payerBefore)} → ${fmtBalance(payerAfter)} (${fmtBalance(payerAfter - payerBefore)})`,
);
console.log(
  `  Recipient: ${fmtBalance(recipientBefore)} → ${fmtBalance(recipientAfter)} (+${fmtBalance(recipientAfter - recipientBefore)})`,
);

process.exit(0);
```

```bash theme={null}
MPPX_PRIVATE_KEY=0x<key> API_URL=https://mpp.mobula.io bun run agent-subscription.ts
```

## See also

* [MPP Agent endpoints](/guides/mpp-agent-endpoints)
* [MPP Subscribe to a plan](/guides/mpp-agent-subscribe)
