Docs menu

Money

Paying for other APIs

Let your apps and agents pay for APIs that charge per call, from your project's credit and within caps you set.

Explain it

More and more APIs charge a small amount per call, paid in USDC. Your apps can pay for them from the project's credit without ever holding a wallet, and your AI agent can pay from its own wallet within a limit you set.

How to do it: open an app's Settings, find Paying for APIs, and turn it on with a cap per call and per day. The app then sends its paid requests through CLI, which pays from the project's balance.

"Let my app pay for the weather API, at most $1 a day."

More and more APIs charge per call over x402, including paid APIs hosted on CLI. Your apps can pay for them from the project's credit without ever holding a wallet or a key, and your agents can pay from their own wallet within a limit you set.

Let an app pay for APIs

An app should never hold a wallet. Instead, you turn on outbound payments for the service, with caps, and the app sends paid requests through CLI. CLI pays from the project's balance.

Turn it on

Only a signed-in project admin can turn this on, because it lets the app spend. Agents will ask you to do it.

In the dashboard:

  1. Open the service and go to its Payments tab.
  2. Find Paying for APIs.
  3. Set the most one request may cost and the most per day, in dollars.
  4. Press Turn on, then redeploy the service.

With the API:

API
PUT /v1/services/:id/outbound
JSON
{ "enabled": true, "perCallMax": 50000, "dailyCap": 5000000 }

That allows up to $0.05 a request and $5 per rolling 24 hours, CLI's fee included. After the next deploy the app has two variables: CLI_PAY_URL and CLI_PAY_TOKEN.

To change the caps, send the same call again. Add "rotate": true to issue a new pay token. The old one stops working at once, so redeploy to give the app the new one.

Send a paid request from your app

The app sends the request it wants made to CLI_PAY_URL:

API
POST $CLI_PAY_URL
Authorization: Bearer $CLI_PAY_TOKEN
JSON
{
  "url": "https://weather-ab12.clicloud.app/v1/forecast?lat=43.59&lon=-79.64",
  "method": "GET",
  "maxPrice": 20000
}
JavaScript
const r = await fetch(process.env.CLI_PAY_URL, {
  method: "POST",
  headers: {
    authorization: `Bearer ${process.env.CLI_PAY_TOKEN}`,
    "content-type": "application/json",
  },
  body: JSON.stringify({ url: "https://weather-ab12.clicloud.app/v1/forecast?lat=43.59&lon=-79.64", maxPrice: 20000 }),
});
const { status, body, paid } = await r.json();

You can also pass headers, and a body (text, or base64 with "bodyEncoding": "base64"). maxPrice is the most this one request may cost; it defaults to the service's per-request cap.

What happens

  1. CLI makes the request.

  2. If the API answers 402, CLI checks the price against maxPrice and your caps, pays from the project's balance, and repeats the request.

  3. CLI returns the API's answer to your app:

    JSON
    { "status": 200, "headers": { "content-type": "application/json" }, "body": "{\"temp\":4.2}", "bodyEncoding": "utf8", "paid": 20000 }
  4. The payment raises an outbound_payment event and shows under Paid APIs you called in the project's money flow. GET /v1/projects/:id/outbound-payments lists them.

A request that would go over a cap is refused with SPEND_CAP_EXCEEDED, and nothing is paid.

How each kind of API is paid

  • A paid route on another CLI app: the project is charged and the request carries a single-use pass for exactly that service, route and price. The seller is credited only when its paywall accepts the pass; if it never does, you get the money back. No chain and no extra fee.
  • Any other x402 API: CLI signs a USDC payment from its own outbound wallet, valid for at most two minutes, after charging your project (plus CLI's fee). If the API refuses or never answers, the money comes back once that payment has expired unused on chain, so an API can't both take the payment and leave you refunded.

Let an agent pay

Agents pay through the MCP server's own wallet, not your project's credit. You set the ceiling in the MCP server's settings:

VariableMeaning
CLI_AGENT_PRIVATE_KEYAn EVM wallet that pays on Base
CLI_AGENT_SOLANA_KEYA Solana wallet that pays on Solana
CLI_PAY_NETWORKbase or solana, when both are set
CLI_SPEND_LIMIT_USDCThe most this MCP process may pay over x402, in total

CLI_SPEND_LIMIT_USDC defaults to 0: the agent never pays, and asks you instead. Set it to the most you're happy for it to spend:

JSON
{
  "mcpServers": {
    "cli": {
      "command": "npx",
      "args": ["-y", "@clicloud-app/mcp"],
      "env": {
        "CLI_API_URL": "https://api.clicloud.app",
        "CLI_AGENT_PRIVATE_KEY": "0x…",
        "CLI_SPEND_LIMIT_USDC": "10"
      }
    }
  }
}

To call one paid API many times, an agent can open a prepaid stream once and send X-CLI-Stream on each call instead of paying every time (see /docs/selling-apis). Agents are told to confirm subscriptions with you first, since they're recurring spending.

See Connect your AI agent for the rest of the MCP server's settings.

Find an API

Before building something, check whether someone already sells it. The directory lists paid APIs and MCP tools hosted on CLI, with the price per call, uptime, real paid traffic, whether failed calls are refunded, and how to pay.

In the dashboard: Paid APIs. Each listing has a console to try a call, paid from a project you choose.

From your terminal:

Terminal
cli find weather --tag geo

Ask your agent:

"Find a paid API that geocodes addresses for under $0.01 a call, and show me its uptime."

With the API:

API
GET /v1/directory?q=weather

The MCP tool is cli_find_api, which also takes maxPrice (micro-USDC) to leave out anything dearer. Results are ranked by relevance, real paid traffic and uptime, never by paid placement.

If the API you pick promises refunds for failed calls, failures are refunded to you on their own. See Refunding failed calls.