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

# Agent Payments

> Let AI agents buy API access with a crypto wallet, no signup or human required

## Overview

Agent Payments lets an AI agent with a crypto wallet and **no account** buy access to
ScrapeGraphAI on its own. The agent pays an [MPP](https://mpp.dev) payment challenge and
receives a real API key plus credits, the same key any customer uses. Payment replaces
signup. Agents can make a one-time credit purchase or start a recurring monthly subscription.

Unlike single-use prepaid tokens, a payment mints a **durable, refillable account**: a user,
a workspace, and an API key with a credit balance that persists across purchases.

<Note>
  Agent Payments is designed for autonomous agents that hold a wallet and have been authorized
  to spend. Human developers should [sign up](https://scrapegraphai.com/dashboard) for an API
  key the normal way.
</Note>

## How it works

1. The agent calls a product endpoint (e.g. `POST /api/scrape`) with no key and gets a `401`
   whose error body points at the agent-access endpoints.
2. The agent chooses one-time access at `POST /api/agent/mpp/access/{pack}` or recurring
   access at `POST /api/agent/mpp/subscription/{plan}`. An unpaid request returns a `402`
   with a `WWW-Authenticate: Payment` challenge (MPP).
3. The agent's wallet pays the challenge, then retries the request with
   `Authorization: Payment <credential>`. If the wallet requires approval, the owner
   approves the payment in their wallet app.
4. The response contains an **API key and credits**. The agent sends the key as
   `SGAI-APIKEY` on every request thereafter. The key is returned once, so store it.

## Payment method

Payments settle over [InFlow](https://inflowpay.ai), a wallet and payment service for AI
agents. The `402` challenge advertises it in the `WWW-Authenticate: Payment` header; pay it
with the InFlow CLI or SDK. Fund the InFlow wallet by sending USDC over the Base network.

* **Currency:** USDC
* **Network:** Base
* **Method:** `inflow` (balance rail, via InFlow)

## Set up an InFlow wallet

To pay, an agent needs an InFlow account, the CLI (or SDK), and a funded wallet.

<Steps>
  <Step title="Create an InFlow account">
    Sign up at [inflowpay.ai](https://inflowpay.ai). This is the account your agent pays
    from.
  </Step>

  <Step title="Install and authenticate">
    Install the CLI from [inflowcli.ai](https://inflowcli.ai), then log in to your account:

    ```bash theme={null}
    inflow auth login
    ```
  </Step>

  <Step title="Fund the wallet">
    Send USDC over the Base network to your InFlow account, then confirm it's available:

    ```bash theme={null}
    inflow balances list
    ```
  </Step>

  <Step title="Let the agent pay">
    Give your agent the InFlow CLI (or [MCP server](https://inflowpay.ai)) and its
    [agentic-payments skill](https://mpp.dev). The agent handles the payment on its own:
    it hits an `/api/agent/mpp/access/{pack}` endpoint, reads the `402` challenge, pays, and
    retries with the credential. You only approve the spend if your wallet policy requires
    it. The commands below show what that exchange looks like under the hood.
  </Step>
</Steps>

<Frame caption="An MPP payment request awaiting approval in the InFlow app">
  <img src="https://mintcdn.com/scrapegraphaiinc-9e950277/ZFSw-cMz5ZX0L6yb/images/agent-payments/inflow-approval.png?fit=max&auto=format&n=ZFSw-cMz5ZX0L6yb&q=85&s=b79ffee7129cfdc9c18111ba7e6d826e" alt="InFlow MPP payment approval for 5 USDC" width="2000" height="1004" data-path="images/agent-payments/inflow-approval.png" />
</Frame>

<Note>
  InFlow is one MPP-compatible wallet. Any wallet or agent runtime that speaks MPP and holds
  USDC can pay the `inflow` challenge. See [mpp.dev](https://mpp.dev) for the protocol.
</Note>

## Credit packs

| Pack     | Price (USDC) | Credits |
| -------- | ------------ | ------- |
| `small`  | 5            | 1,000   |
| `medium` | 40           | 10,000  |
| `large`  | 150          | 50,000  |

Credits meter product usage the same way a normal account's do. A minted account starts on
the free plan (10 requests/min, 1 concurrent crawl, 1 monitor).

## Monthly subscriptions

MPP also supports recurring payments. A subscription creates a durable account and stable API
key, then grants the plan's credit allowance for each paid monthly period.

| Plan      | Price (USDC/month) | Credits/month |
| --------- | ------------------ | ------------- |
| `starter` | 20                 | 10,000        |
| `growth`  | 100                | 100,000       |
| `pro`     | 500                | 750,000       |

The first period settles when the subscription is activated. The MPP challenge binds the amount,
currency, billing period, plan, and subscription expiration into immutable terms that the wallet
shows for approval.

<Warning>
  An MPP subscription is a recurring payment commitment, not a one-time credit pack. Review the
  amount and monthly period in the InFlow approval screen before approving it.
</Warning>

## Endpoints

| Method | Endpoint                             | Auth          | Purpose                                                |
| ------ | ------------------------------------ | ------------- | ------------------------------------------------------ |
| `GET`  | `/api/agent/protocols`               | none          | Discover packs, method, and endpoints                  |
| `POST` | `/api/agent/mpp/access/{pack}`       | none          | Pay → mint account, API key, and credits               |
| `POST` | `/api/agent/mpp/subscription/{plan}` | none          | Subscribe → mint account, API key, and monthly credits |
| `POST` | `/api/credits/purchase/{pack}`       | `SGAI-APIKEY` | Refill credits on your account                         |
| `GET`  | `/api/credits`                       | `SGAI-APIKEY` | Check remaining balance                                |

## Getting Started

### 1. Discover

Free and unauthenticated. Start here to learn the packs, method, and endpoints.

```bash cURL theme={null}
curl https://v2-api.scrapegraphai.com/api/agent/protocols
```

### 2. Pay and mint

```bash InFlow theme={null}
inflow mpp pay \
  https://v2-api.scrapegraphai.com/api/agent/mpp/access/small \
  --method POST
# → { "apiKey": "sgai-…", "pack": "small", "credits": 1000,
#     "remaining": 1000, "account": "created" }
```

### 3. Use the key

```bash cURL theme={null}
curl -X POST https://v2-api.scrapegraphai.com/api/scrape \
  -H "SGAI-APIKEY: sgai-…" \
  -H "content-type: application/json" \
  -d '{"url": "https://example.com"}'
```

## Subscribe with MPP

Use `mpp subscribe`, not `mpp pay`, when the challenge has `intent: subscription`.

### 1. Inspect the recurring terms

Inspection is read-only and does not create a payment:

```bash InFlow theme={null}
inflow inspect \
  https://v2-api.scrapegraphai.com/api/agent/mpp/subscription/starter \
  --method POST
```

The response contains one or more MPP subscription options. Review these fields:

* `amount` and `currency`
* `period_count` and `period_unit`
* `subscription_expires`
* `external_id`
* `option_id`

If multiple options are returned, choose one explicitly. Never assume the first option is the one
the owner wants.

### 2. Start the subscription

Pass the `option_id` returned by inspection:

```bash InFlow theme={null}
inflow mpp subscribe \
  https://v2-api.scrapegraphai.com/api/agent/mpp/subscription/starter \
  --method POST \
  --option-id <option_id>
```

InFlow returns an `approval_url`. Open it in the InFlow app or dashboard and approve the recurring
terms. The approval activates the subscription and settles the first monthly period.

For an agent that can wait for approval inline, poll automatically:

```bash InFlow theme={null}
inflow mpp subscribe \
  https://v2-api.scrapegraphai.com/api/agent/mpp/subscription/starter \
  --method POST \
  --option-id <option_id> \
  --interval 5 \
  --max-attempts 180
```

On success, ScrapeGraphAI returns the stable API key and subscription details:

```json theme={null}
{
  "apiKey": "sgai-…",
  "subscriptionId": "…",
  "plan": "starter",
  "creditsPerMonth": 10000,
  "remaining": 10000,
  "renewed": true
}
```

Store the API key securely. Send it as `SGAI-APIKEY` on normal ScrapeGraphAI API requests.

### 3. Use and manage the subscription

List or inspect subscriptions from the buyer account:

```bash InFlow theme={null}
inflow subscriptions list
inflow subscriptions get <subscription_id>
```

To request the subscription resource again, including after the billing period changes, use:

```bash InFlow theme={null}
inflow subscriptions fetch \
  <subscription_id> \
  https://v2-api.scrapegraphai.com/api/agent/mpp/subscription/starter \
  --method POST
```

InFlow obtains a fresh credential for the current challenge. If the current period is already
paid, access continues without another period charge. If a new period is due, InFlow processes the
next recurring payment before ScrapeGraphAI renews the monthly credits.

### Cancel a subscription

Cancellation is immediate and stops future periods. It does not refund a period that already
settled:

```bash InFlow theme={null}
inflow subscriptions cancel <subscription_id>
```

Always confirm cancellation with the subscription owner before running this command.

## Refilling

When credits run low, pay the keyed purchase route **with your API key** to top up the same
account. Keep your key because it is the only way to refill.

```bash cURL theme={null}
inflow mpp pay \
  https://v2-api.scrapegraphai.com/api/credits/purchase/small \
  --method POST \
  --header "SGAI-APIKEY: sgai-…"
# → { "pack": "small", "credits": 1000, "remaining": 2000 }
```

If you lose the key, pay `POST /api/agent/mpp/access/{pack}` again. Every new payment mints a
fresh account.

## Terms

* **Minimum purchase:** the `small` pack (5 USDC).
* **Idempotency:** replaying the same payment credential re-delivers the same result. You are
  never charged or credited twice for one payment.
* **Refunds:** payments are handled out-of-band. If a payment settles but access is not
  granted (a transient error), retry with the same credential. The flow is idempotent and
  self-heals. For anything unrecoverable, contact [support](mailto:support@scrapegraphai.com)
  with your payment reference (returned in the `Payment-Receipt` header).

## Reference

* OpenAPI: `https://v2-api.scrapegraphai.com/api/openapi.json`
* Machine-readable guide for agents: `GET /api/agent/protocols`
