<!--
Sitemap:
- [Newton Agent NeoBank](/index)
- [Getting Started](/getting-started)
- [Onboard an Agent](/guides/onboard-an-agent)
- [Give an Agent a Budget](/guides/agent-budget)
- [Pay for an API](/guides/pay-for-an-api)
- [Issue a Card](/guides/issue-a-card)
- [Meter Your API](/guides/meter-your-api)
- [SDK Essentials](/reference/sdk)
- [ModularVault](/reference/sdk/modular-vault)
- [PlatformClient](/reference/sdk/platform-client)
- [FacilitatorClient](/reference/sdk/facilitator-client)
- [createX402Fetch](/reference/sdk/create-x402-fetch)
- [buildPolicyParams](/reference/sdk/build-policy-params)
- [Networks & Addresses](/reference/networks)
-->

# Pay for an API

When an agent calls an endpoint that charges for access, the SDK handles the payment for you. The agent gets its data; you set the limit.

## How it works

1. Your agent requests a paid endpoint.
2. The server replies "payment required," with a price.
3. The SDK pays — if it's within the agent's budget — and retries the request.
4. The agent gets the response.

If the price is over your per-call ceiling or the agent's daily limit, nothing is paid.

## Code

```typescript
import { createX402Fetch } from "@newton-xyz/isaac";

const fetch402 = createX402Fetch({
  agentKey: process.env.AGENT_KEY!,
  rpcUrl: process.env.RPC_URL!,
});

const result = await fetch402("https://api.example.com/data", {
  method: "GET",
  maxPayment: "1000000", // 1 USDC ceiling for this call
});

if (result.success) {
  const data = await result.response.json();
  console.log("got data — paid in tx", result.txHash);
} else {
  console.log("not paid:", result); // over budget, or denied by policy
}
```

The agent needs a funded vault and a budget first — see [Give an Agent a Budget](/guides/agent-budget).

## Next

* **[Issue a Card](/guides/issue-a-card)** — give an agent a virtual card.
* **[Meter Your API](/guides/meter-your-api)** — charge agents to call your own API.
