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

> ## Agent Instructions
> - Base URLs: models `https://api.aisa.one/v1` (Gemini GenerateContent: `https://api.aisa.one/v1beta`); data APIs `https://api.aisa.one/apis/v1`. The `servers` of each operation in https://aisa.one/openapi.yaml is authoritative.
> - Auth: `Authorization: Bearer $AISA_API_KEY`. Never print, log, or commit the key.
> - MCP (preferred for agents): `https://mcp.aisa.one/mcp`, signed in with OAuth, so there is no key to paste.
> - Agent Skill: `npx skills add AIsa-team/agent-skills --skill aisa`. Fallback with the AIsa CLI: `aisa skills install aisa`.
> - Spending: docs, https://aisa.one/models, https://aisa.one/api, `/v1/models`, and MCP `search`, `list_categories`, `get_details`, `batch_quote`, and the `account` operation are free. Quote the exact calls before running them (MCP `batch_quote`, CLI `aisa quote --json`). If the quote reports `auto_execute_eligible: true`, run it unless the user set a tighter limit or asked only for a quote. Otherwise, tell the user in one message the planned calls, the quoted price, and a total USD budget for the task, then wait for approval. Direct HTTP calls follow the stricter rule at https://aisa.one/docs/get-started/cli.md#direct-http-fallback. Do not make paid calls to test availability. Full rule: https://aisa.one/llms.txt

# Design an Autonomous API Purchasing Workflow

> Let an agent select, quote, authorize, pay for, verify, and audit a paid API call at runtime without open-ended spending or duplicate charges.

## The problem

Agents increasingly need paid capabilities mid-task: an enrichment lookup, a deep-research report, or an unplanned dataset. Without controls, "select a tool" quietly becomes "spend money", and a timeout can turn into a duplicate charge. A good outcome is an agent that quotes before it buys, stays within an approved cap, executes once, verifies both the charge and the delivered result, and leaves an audit record without secrets.

## Prompt

Give this to your agent once AIsa is [connected via MCP](https://aisa.one/docs/agent-quickstart.md):

```txt wrap theme={null}
Task: <what you need done>. Budget for the whole task: <your approved budget>. Ask me before any paid call; above <your threshold>, wait for my explicit yes.
Process for every paid step: (1) find the operation with AIsa `search`; (2) quote the exact call with `batch_quote`; (3) show me the operation, arguments, quoted cost, and remaining budget; (4) after I approve, run that same call once with `batch_use`.
If a quote is missing or failed, or the endpoint has no documented maximum, tell me and do not run it under the fixed budget. Re-quote if the operation or arguments change.
Never retry a paid call automatically after a timeout or unclear result: check usage first and report back.
At the end, give me an audit table: step | operation | quoted | approved cap | settled cost (or "unknown") | result verified?
```

## APIs and Skills used

Through MCP, your agent reaches every operation via a few meta tools at `https://mcp.aisa.one/mcp`: `search`, `list_categories`, `get_details`, and `batch_quote` are free; `batch_use` (up to 20 calls) is billed per call.

| Step | What the agent calls | Reference |
| - | - | - |
| Select | `search` / `list_categories` for the smallest sufficient operation | [Connect via MCP](https://aisa.one/docs/agent-quickstart.md) |
| Estimate | `batch_quote` with the exact calls: returns the estimate without running anything | [Quote, review, then execute](https://aisa.one/docs/guides/pricing.md#quote-review-then-execute) |
| Authorize | Your policy layer and, above a threshold, a person | [Security & Privacy](https://aisa.one/docs/guides/security.md) |
| Execute | `batch_use` with the same calls, after approval | [How It Works](https://aisa.one/docs/how-it-works.md) |
| Same over HTTP | `X-AISA-Cost-Mode: quote`, then `X-AISA-Max-Price-USD` | [Billing & Credits](https://aisa.one/docs/guides/pricing.md) |
| Verify payment | Balance, settled-cost metadata, Usage | [Credit Balance](https://aisa.one/docs/api-reference/credits-balance.md), [Usage](https://aisa.one/docs/guides/dashboard/overview.md#usage) |
| Handle rejections | `402` budget errors, `409` idempotency conflicts, retry rules | [Error Codes](https://aisa.one/docs/api-reference/errors.md) |
| Pay per request without an account | MPP on selected read-only operations | [Machine Payments](https://aisa.one/docs/integrations/machine-payments.md) |

A quote, like `X-AISA-Max-Price-USD` over HTTP, checks the estimate before any provider is called; neither caps the final charge of a metered operation. The key's spending limit in the Console is the hard ceiling.

**Machine payments (MPP).** On operations that accept MPP, a request without credentials returns HTTP `402` with a `WWW-Authenticate: Payment` challenge; the agent pays through Tempo and retries with `Authorization: Payment <credential>`. The live challenge is authoritative for the amount and terms. Not every endpoint accepts MPP, so check the operation first.

## Example output

> [!NOTE]
>
> Illustrative only. Operations and amounts are placeholders, not real prices or account records.

| Step | Operation | Quoted | Approved cap | Settled cost | Result verified |
| - | - | - | - | - | - |
| 1 | `example_company_enrich` | `<quote A>` | `<cap A>` | `<settled A>` | Yes: record for Example Corp returned |
| 2 | `example_deep_report` | `<quote B>` | not approved (over threshold) | none | Skipped, asked user |
| 3 | `example_people_match` | `<quote C>` | `<cap C>` | unknown (timeout) | Not retried; flagged for reconciliation |

## Guardrails

* **Separate the stages:** select, estimate, authorize, execute, verify payment, verify delivery, and audit. Selecting a tool never grants permission to spend, and a successful payment does not prove delivery.
* **Policy lives outside the prompt.** Enforce allowed capabilities, per-call, per-task, and time-based limits, confirmation thresholds, and fallback rules in code or another trusted layer.
* **A quote is not approval, and a missing quote is not free.** Re-quote when the operation, arguments, or scope change. Stop if the quote or documented maximum exceeds the remaining budget.
* **Execute once and keep identifiers.** Preserve request, usage, and transaction IDs. Use idempotency keys only where an endpoint documents them (for example, synchronous Similarweb routes); never change a key to get past a `409`.
* **Reconcile ambiguous outcomes:**
  * Rejected before acceptance: fix the request or pick another operation.
  * No confirmed charge and no result: check status before any retry.
  * Charge recorded, result missing: reconcile or contact support; do not repurchase.
  * Result present, settlement unclear: keep the result and reconcile the charge separately.
  * A network timeout does not prove the request failed before billing.
* **Audit without secrets.** Record the task, decision, operation, approved and settled amounts, reference IDs, and outcome. Never store API keys, wallet secrets, payment credentials, or bearer tokens.
* **When a simpler flow is better:** use normal account funding and application-controlled calls when usage is predictable, purchases do not need to happen at runtime, or you cannot reconcile ambiguous payment states.

## Related

> [card] [Machine Payments](https://aisa.one/docs/integrations/machine-payments.md)
>
> MPP for agents paying per request.

> [card] [Billing & Credits](https://aisa.one/docs/guides/pricing.md)
>
> Quotes, caps, and settled cost.

> [card] [Error Codes](https://aisa.one/docs/api-reference/errors.md)
>
> Safe retry guidance.

> [card] [Security & Privacy](https://aisa.one/docs/guides/security.md)
>
> Agent safety controls.


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