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

> ## Agent Instructions
> If you are an agent buying services: start with these steps. Every page has a .md version.
> 1. Install the Catalog MCP (live server https://mcp.live.nevermined.app/mcp, sandbox server https://mcp.sandbox.nevermined.app/mcp; rehearse on sandbox with a sandbox API key before live, as keys work only in their own environment; Claude Code and Cursor commands, Codex config.toml entry): https://nevermined.ai/docs/products/catalog/mcp.md
> 2. Get an API key: https://nevermined.ai/docs/agents-guide/get-api-key.md
> 3. Enroll a card and create a delegation (a payment method plus a spend mandate: an amount, an expiry and a number of purchases): https://nevermined.ai/docs/agents-guide/enroll-card.md
> 4. Buy and call a paid agent over x402: https://nevermined.ai/docs/getting-started/ai-agent-purchase.md
> SDK quickstart: https://nevermined.ai/docs/integrate/quickstart/typescript.md. Pricing: https://nevermined.ai/pricing/

# pay_service

> Catalog MCP tool: pay for a catalog service from your spend-capped delegation and return the vendor's response. Charges real funds.

Pay for a service from your spend-capped delegation and return the vendor's response. **This charges real funds.** Needs a credential (API key or OAuth `commerce` grant). Always read [`get_service`](https://nevermined.ai/docs/mcp/catalog-mcp/get-service) first and **pass its `requestShape.endpoints[].payServiceArgs` through as-is** — it carries `slug` / `path` / `method`, and for a verified endpoint a pre-filled `body` (and sometimes `search` / `headers`); don't drop those and rebuild your own. Where an example filled a path parameter, `path` already holds **that example's** entity (not a `{placeholder}`) — swap in the entity you want rather than looking for a placeholder to replace.

**Auth:** key / grant · **Charges:** real funds

## Arguments

| Argument | Required | Type | Description |
| - | - | - | - |
| `slug` | yes | string | The service slug to pay for. |
| `path` | no | string | Router suffix appended to the service base (from `get_service`'s `payServiceArgs.path`). Where an example filled `pathParams`, it already holds that example's entity — swap in the one you want. A checked `invokePath` may be empty even when the display path is not. Query params go in `search`, never here. |
| `search` | no | string | Query string without `?`, for a slug-routed `GET`. |
| `method` | no | string | HTTP method. Omit to use the catalog method for the matching endpoint (`POST` when none). Echoed back under `request.methodSource` as `caller`, `catalog`, or `default`. |
| `body` | no | any | Request payload sent to the vendor. |
| `maxTotalCents` | no | integer | Maximum whole cents this call may cost, fee included (compared exactly, so rounding alone never exceeds it). The 402 price can differ from the catalog label. |
| `quoteId` | no | string | An opaque quote id from [`quote_service`](https://nevermined.ai/docs/mcp/catalog-mcp/quote-service). Pass only with the exact same call before its `expiresAt`; the Router then uses that cached challenge and exact total. |
| `headers` | no | object | Extra headers for the vendor call. |
| `delegationId` | no | string | Delegation to charge (API key only); defaults to your active one. An OAuth caller always spends from its grant. Feeds the derived idempotency key when `requestId` is omitted, so keep it the same across retries. |
| `fresh` | no | boolean | Set `true` on **every poll** of an async status endpoint, **including the first**, so each poll mints a fresh idempotency key and advances. With `fresh` a retry is **not** de-duplicated and **is** charged again. Ignored when `requestId` is set. |
| `requestId` | no | string | Idempotency key. Leave unset — a retry of the same call is de-duplicated automatically. Set a **new** value only for a genuinely separate, additional charge. |
| `requireProtocol` | no | string | Pay only on `x402` or `mpp`; never fall back to another rail. If unavailable, returns `payment_failed` with `BCK.ROUTER.0045`, nothing charged. Omit to auto-select (MPP first). With `quoteId`, keep the quoted rail; a different rail returns `quote_mismatch`. |
| `funding` | no | string | `"subscription"` or `"delegation"`: what pays this call. Omit it to pay with your [Nevermined credits](#pay-with-subscription-credits) when they can pay this call, and from your delegation otherwise. |

> [!NOTE]
>
> **A bare slug reaches the service's base URL.** For a multi-endpoint API that is a 404, not a purchase — pass the endpoint's `path`. Only a single-endpoint service is callable by slug alone.

## Returns

The vendor's response plus the payment record. A paid result also carries `delegationId` and `budget` (the spending budget after this call):

```json theme={null}
{
  "paid": true,
  "upstreamStatus": 200,
  "priceLabel": "$0.02",
  "payment": { "paymentId": "b1f9c2e4-…", "txHash": "0xfc8af37b…" },
  "request": { "method": "POST", "path": "/quote", "methodSource": "catalog", "catalogEndpoint": "/quote" },
  "delegationId": "121b880a-…",
  "budget": { "capCents": "500", "spentCents": "8.04", "remainingCents": "491.96" },
  "response": { "…": "the vendor's body, unchanged" }
}
```

* `paid: true` with a **non-2xx** `upstreamStatus` may still have cost the merchant price.
* The `request` block rides on every result that resolved the endpoint (`already_paid`, `payment_failed`, …), not only the paid one.
* `budget: null` means it couldn't be read this time — **not** that it's zero; call [`get_budget`](https://nevermined.ai/docs/mcp/catalog-mcp/get-budget).
* `payable: false` (with `protocol`, `priceLabel`, `network`, `note`; never the upstream URL) means the service isn't on a payable rail — nothing charged.

## Outcomes and refusals

| Result | Meaning | What to do |
| - | - | - |
| `{ "status": "pending", "paymentId": "…", "nextTool": "get_payment_result" }` | **Paid** — the service took longer than the Router waits. | Call [`get_payment_result`](https://nevermined.ai/docs/mcp/catalog-mcp/get-payment-result) with the `paymentId`. Don't call `pay_service` again — it returns the same `pending`. |
| `{ "status": "already_paid", "paymentId": "…" }` | This idempotency key already carries a payment; the result isn't replayed here. Nothing new charged — and it doesn't by itself say the original succeeded. | Read the original with `get_payment_result` or `list_payments`. A **new** `requestId` starts a separate charge. |
| `{ "error": "payment_indeterminate" }` | The charge may or may not have landed (e.g. the connection dropped). | Check `list_payments` first; to retry, reuse the returned `requestId` **verbatim** without `fresh`. |
| `{ "error": "payment_failed", "code": "BCK.ROUTER.0003" }` | The spend would exceed your delegation cap, or it expired. | Widening the cap is almost always wrong — see [Guardrails](https://nevermined.ai/docs/products/catalog/router/guardrails.md). |
| `{ "error": "payment_failed", "code": "BCK.ROUTER.0009" }` | The funding source couldn't cover the charge; nothing signed. | On **MPP** the wallet is short (call [`wallet_balance`](https://nevermined.ai/docs/mcp/catalog-mcp/wallet-balance); a human funds it). On **card** the issuer declined — use another card. **x402** never raises this. |
| `{ "error": "per_call_max_exceeded" }` | The price exceeds `maxTotalCents`; no charge. | Raise `maxTotalCents` only deliberately, then retry with the **same** `requestId`. |
| `BCK.ROUTER.0027` — request exceeds `maxRequestBytes` | The request body is larger than the endpoint's `maxRequestBytes` cap. Raised **before** the unpaid probe, so nothing is minted and **no charge**. | Shrink the request below the cap that [`get_service`](https://nevermined.ai/docs/mcp/catalog-mcp/get-service) reports for the endpoint. |
| `{ "error": "quote_not_found" }` / `"quote_expired"` / `"quote_mismatch"` | Named no-charge quote refusals. | Quote again rather than paying unpinned. |
| `{ "error": "service_not_found" }` | Wrong slug; no charge. | Check with `search_services`. |
| `{ "error": "catalog_unavailable" }` / `"delegation_lookup_failed"` | Transient read failure; no charge. | Retry later. |
| `{ "error": "no_delegation", "nextTool": "setup_delegation" }` | No delegation on the account; no charge. | Call [`setup_delegation`](https://nevermined.ai/docs/mcp/catalog-mcp/setup-delegation). |
| `{ "error": "router_controls_unavailable" }` | The API behind this server is too old to enforce `search`, `quoteId` or `maxTotalCents`. | Tell the human; don't retry without them. |
| `{ "error": "credential_refused" }` / HTTP `401` | Credential missing or refused. | Re-authorize, or set your API key. |

> [!WARNING]
>
> **Async services: set `fresh: true` on every poll, including the first.** An async service returns a `taskId`, then you poll a status endpoint with the same id. Without `fresh`, every later poll reuses the first poll's idempotency key and gets the first poll's stored answer (or `already_paid`) back, so the status never advances. `fresh` makes each poll a distinct, separately-billed call. Leave `fresh` **off** the submit and off any retry of a call whose outcome is unsure.

## Pay with subscription credits

With [Nevermined credits](https://nevermined.ai/docs/products/catalog/router/subscription.md) — free credits from sign-up, top-up packs, or a Nevermined Subscription's monthly allowance — `pay_service` can pay with **credits** instead of your delegation: Nevermined pays the merchant, the call costs the endpoint's rate from Nevermined's rate card, and the credits come back if the service doesn't answer with a `2xx`. Credits are spent with a personal **API key**, or through an OAuth connection you [allowed to spend them](https://nevermined.ai/docs/products/catalog/router/subscription.md#who-can-spend-your-credits); any other OAuth connection pays from its grant.

The `funding` argument decides what pays:

| `funding` | What pays |
| - | - |
| omitted | Your credits, when a credits quote for this call succeeds: the endpoint has a rate, and you hold a subscription that can spend or enough other credits for this call (or automatic top-ups that would cover it). Otherwise your delegation, exactly as before. Passing `delegationId`, `quoteId` or `maxTotalCents` selects the delegation. |
| `"subscription"` | Your credits — refused, never switched to the delegation, if they can't pay this call. |
| `"delegation"` | Your delegation. |

`delegationId`, `quoteId` and `maxTotalCents` only mean something to a delegation, so passing one with `funding: "subscription"` is refused (`invalid_arguments`, with the offending `fields`).

For a subscriber in good standing, the default doesn't look at how many credits are left or at the merchant's live price — those are checked when the call is made, and a refusal for them is **not** moved to your delegation (see the note below). Without a subscription in good standing, the quote also checks that your credits cover this call, unless an automatic top-up would cover it. When your credits were refused for this call up front (no rate, nothing that can pay it, credits frozen by a card dispute or an overdue renewal), the delegation-funded result says so: `funding: "delegation"`, `fundingReason: "subscription_refused"`, the API's `fundingCode` and a `fundingNote` (or `fundingReason: "delegation_arguments"` when you passed a delegation-only argument). If credits aren't available to you at all — an OAuth connection you didn't allow to spend them, for example — the result carries no funding fields. And if the subscription's answer couldn't be read, the call is refused with `funding_undetermined` rather than paid from your delegation.

A credits call answers with `funding: "subscription"`, the credits it cost and where they stand — and no `budget` or `delegationId`, since no delegation was charged:

```json theme={null}
{
  "funding": "subscription",
  "paid": true,
  "upstreamStatus": 200,
  "creditsLeft": "11497",
  "creditsCharged": 3,
  "creditsStatus": "Committed",
  "payment": { "paymentId": "b1f9c2e4-…", "status": "Settled", "txHash": "0xfc8af37b…", "creditsCharged": 3, "creditsStatus": "Committed" },
  "request": { "method": "POST", "path": "/scrape", "methodSource": "catalog", "catalogEndpoint": "/scrape" },
  "response": { "…": "the vendor's body, unchanged" }
}
```

* `creditsStatus` is `Committed` (spent), `Reserved` (still running, or marked for refund) or `Refunded` (returned). The top-level `creditsCharged` and `creditsStatus` are `null` when `paid` is `false`, or when the ledger couldn't be read at answer time (`payment` then omits them) — read the payment with [`list_payments`](https://nevermined.ai/docs/mcp/catalog-mcp/list-payments) later.
* `creditsLeft` is your credits after the call, as a digit string. `null` means it couldn't be read, not zero.
* A `pending` answer works as for any paid call: poll [`get_payment_result`](https://nevermined.ai/docs/mcp/catalog-mcp/get-payment-result). The credits stay reserved until the service answers.

### When a call charges a top-up pack

With [top-ups](https://nevermined.ai/docs/products/catalog/router/subscription.md#top-ups) on **and a personal API key**, a credits call that runs out of credits charges one pack to the human's saved card and goes ahead (a call made through an OAuth connection never charges a pack on its own — an OAuth-connected agent uses [`top_up_credits`](https://nevermined.ai/docs/mcp/catalog-mcp/top-up-credits) instead). Its result then also carries `topUp` — the credits the pack added and its price in US dollars, before tax — and `topUpMessage`, a sentence to relay:

```json theme={null}
{
  "funding": "subscription",
  "paid": true,
  "upstreamStatus": 200,
  "creditsLeft": "10497",
  "creditsCharged": 3,
  "creditsStatus": "Committed",
  "topUp": { "credits": 10000, "amountUsd": 10 },
  "topUpMessage": "Your credits ran out, so this call charged a credit pack to your saved card: 10,000 credits for $10.00 plus any tax. Tell the user. Top-up credits never expire; the pack and its receipt are on the Nevermined dashboard, where the monthly top-up limit is managed."
}
```

* **Relay `topUpMessage` to the human.** Their card was charged, and they should hear it from you, not only from the receipt email.
* A `pending` answer carries them too.
* When the pack the Router reported can't be read, `topUpMessage` comes alone, without `topUp`, saying the call **may** have charged a pack. Relay that as well.
* Only a call that goes ahead carries `topUp`. A call refused after its pack was charged says so as `insufficient_credits` or `credits_frozen` with `topUps: "bought"`, the pack's `purchaseId` and a `topUpMessage` to relay; any other refusal then says nothing about the pack. The human's **Packs** list in the Nevermined App and the receipt email are the record.

### Refusals when paying with credits

These spend and reserve no credits. They charge nothing either — except that with top-ups on, an `insufficient_credits` with `topUps: "pending"`, or any refusal with `topUps: "bought"`, can follow a pack charged to the human's card: tell them. A refusal with `topUps: "bought"` carries a `topUpMessage` saying so — relay it. Each carries `funding: "subscription"`, the API's `code`, `retryable` and `message`, and an `alternative` saying how to pay the same call from your delegation instead.

| `error` | What happened |
| - | - |
| `no_active_subscription` | Nothing to pay with: no subscription in good standing, and no credits — or not enough for this call — that can be spent. Also a call made with the API key of an organization you're a member of. Without a subscription in good standing, top-ups that are paused, at their monthly limit or still charging a pack land here too, with no `topUps`: with `funding` omitted, such a call is paid from the delegation instead, so tell the human their top-ups need attention in the Nevermined App. |
| `subscription_not_eligible` | This endpoint can't be paid with credits — see `reason`. With `reason: "wallet_bound"` the service sells only to the payer's own crypto wallet, so the `alternative` asks for the `delegationId` of a personal crypto-wallet delegation: a card or organization delegation can't pay it either. (With `code: null` and no `alternative`, it's the HTTP method: credits price only `GET`, `POST`, `PUT`, `PATCH` and `DELETE`.) |
| `insufficient_credits` | Not enough credits left for this call (`credits` is its cost). When the call tried a pack, `topUps` says why none covered it: `paused` (a pack was declined, needed authentication, or its card can no longer pay; the human resumes top-ups in the Nevermined App), `limitReached` (the monthly top-up limit), `pending` (a pack is being charged and may already be; retry in a moment), `unavailable` (no pack was charged; retry later) or `bought` (this call charged a pack, but other calls spent it first; retry). Also an allowance an overdue renewal froze (`BCK.SUBSCRIPTION_ROUTER.0016`): the human updates the card in the Nevermined App so the open invoice is paid — a retry is refused again until then, even with `topUps: "bought"`. See [When no top-up covers the call](https://nevermined.ai/docs/products/catalog/router/subscription.md#when-no-top-up-covers-the-call). |
| `credits_frozen` | Every credit is frozen by a card dispute (`BCK.SUBSCRIPTION_ROUTER.0015`), resolved with the card issuer or Nevermined support — never by buying credits, which would be frozen too. With `topUps: "bought"`, this call charged a pack before the dispute froze it: the pack's credits are frozen with the rest. With no delegation to name as the `alternative`, it carries `nextTool: "setup_delegation"`. |
| `subscription_ceiling_exceeded` | The merchant's live price is outside what the rate allows right now: above its bound, in another asset or network, or unreadable (`reason`). |
| `subscription_rail_unsupported` | The merchant asked for a rail credits don't pay (`rail`). |
| `subscription_payment_refused` | Nevermined's treasury couldn't make this payment; `code` and `retryable` say why and whether to retry. |
| `subscription_unavailable` | Credits can't be spent from this connection or deployment — for example an OAuth connection that isn't a commerce connection. |
| `subscription_credits_not_granted` | An OAuth commerce connection you didn't allow to spend your credits (`BCK.OAUTH.0037`). Reconnect and tick **Let this assistant spend my Nevermined credits**. No `alternative`. |
| `personal_grant_org_refused` | An OAuth connection allowed to spend your credits, used in an organization (`BCK.OAUTH.0038`): it spends only your personal credits. No `alternative`, and a delegation-only argument doesn't avoid it: pass `funding: "delegation"` to pay from the delegation. |
| `subscription_cap_reached` | Not returned today: the subscription has no spending limit beyond your credits. Retry later if you see it. |

With `funding` omitted, a call whose credits a dispute or an overdue renewal froze before it was quoted is paid from your delegation instead, with `fundingCode` saying why.

With `funding` omitted, `{ "error": "funding_undetermined", "retryable": true }` means what would pay this call couldn't be decided — nothing was charged; retry.

Other failures of a credits call use the usual outcomes above — `payment_failed`, `payment_indeterminate`, `already_paid`, `pending` — with `funding: "subscription"`: read `code` and `retryable`.

> [!NOTE]
>
> A credits call refused at the call because too few credits are left (`insufficient_credits`) is **not** moved to your delegation on its own — starting to spend money when your credits run out is your decision. Retry with `funding: "delegation"` if you want the delegation to pay. To have a pack of credits charged automatically instead, the human turns on [top-ups](https://nevermined.ai/docs/products/catalog/router/subscription.md#turn-on-top-ups) in the Nevermined App; an assistant can't turn them on.

## Try it

**Ask your assistant:**

> Pay `openweather-mpp` for the current weather in Lisbon and show me the response.

**Call it directly** (⚠️ **charges real funds** — rehearse on `https://mcp.sandbox.nevermined.app/mcp` first):

```bash theme={null}
curl -X POST https://mcp.live.nevermined.app/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "Authorization: Bearer $NVM_API_KEY" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"pay_service","arguments":{"slug":"openweather-mpp","path":"/openweather/current-weather","body":{"lat":38.72,"lon":-9.14}}}}'
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.