> For the complete documentation index, see [llms.txt](https://fourohtwo.gitbook.io/fourohtwo-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://fourohtwo.gitbook.io/fourohtwo-docs/agents/sdk.md). Agents can also search and read this documentation through its [MCP server](https://fourohtwo.gitbook.io/fourohtwo-docs/~gitbook/mcp).

# SDK

The `fourohtwo` package pays x402 APIs with one agent key: USDG on Robinhood Chain or USDC on Base, on Fourohtwo or anywhere else in the x402 directory.

```sh
npm install fourohtwo
```

## createPayer

```ts
import { createPayer } from "fourohtwo";

const pay = createPayer({
  privateKey: process.env.AGENT_KEY, // required: the agent's own wallet
  maxPerCallUsd: "0.05",             // refuse any single call above this
  maxDailyUsd: "2",                  // refuse once this much was spent in 24h
  networks: ["base", "robinhood"],   // optional: where it may pay, in order of preference
  payWith: "ETH",                    // optional: swap into USDG when low
  useRemotePolicy: true,             // apply rules set on fourohtwo.xyz/agents
  onBeforePay: ({ url, amountUsd }) => amountUsd < 0.1, // optional final check
});

const res = await pay(url, { method: "POST", body: JSON.stringify({ q: "…" }) });
```

| Option            | Default                 | Description                                                                                                                                    |
| ----------------- | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| `privateKey`      |                         | The agent wallet's private key.                                                                                                                |
| `rpcUrl`          | public RPC              | Robinhood Chain RPC used for balances and swaps.                                                                                               |
| `baseRpcUrl`      | public RPC              | Base RPC used for USDC balances.                                                                                                               |
| `networks`        | `["robinhood", "base"]` | Chains it may pay on, in order of preference.                                                                                                  |
| `baseUrl`         | `https://fourohtwo.xyz` | Used for policies, swaps and search.                                                                                                           |
| `maxPerCallUsd`   | none                    | Per-call cap, checked before signing.                                                                                                          |
| `maxDailyUsd`     | none                    | Rolling 24-hour cap for this payer instance.                                                                                                   |
| `payWith`         | none                    | `"ETH"` or a token address to swap from.                                                                                                       |
| `useRemotePolicy` | `true`                  | Reads the owner's spending rules.                                                                                                              |
| `onBeforePay`     | none                    | Return `false` to refuse a payment.                                                                                                            |
| `reportReceipts`  | `true`                  | After paying an API outside Fourohtwo, send its URL and the public transaction hash to the directory, which counts it as a verified paid call. |

The returned function also exposes `pay.address`, `pay.balances()` (USDG and USDC), `pay.usdgBalance()`, `pay.lastPayment()` and `pay.spentTodayUsd()`.

## Which coin pays

When an API offers several ways to pay, the payer takes the first chain in `networks` where the wallet already holds enough. Fourohtwo APIs accept both coins. Most other x402 APIs take USDC on Base. The limits and the owner's spending rules count both coins together, in dollars.

A refused payment throws `PaymentRefusedError` before anything is signed.

## Search and lookup

```ts
import { searchApis, getApi } from "fourohtwo";

const { fourohtwo, x402 } = await searchApis("token risk");
const onBase = await searchApis("weather", { network: "base", alive: true, maxPriceUsd: 0.01 });
const api = await getApi("rug-check");
```

## Link an agent to your account

```sh
AGENT_KEY=0x… npx fourohtwo delegate --owner <your wallet>
```

Paste the printed address and signature on [fourohtwo.xyz/agents](https://fourohtwo.xyz/agents).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://fourohtwo.gitbook.io/fourohtwo-docs/agents/sdk.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
