---
id: SI0003
title: "Agent kit RPC setup"
url: https://carbium.sh/library/si/agent-kit-rpc-setup
collection: AI and blockchain
category: Solana agent kits
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Agent kit RPC setup

Point an agent kit's Solana tools at Carbium: one shared client with the key in a header, a URL form for kits that take only a string, the commitment each call uses, and what the common tools cost.

## What an agent kit needs from the RPC

An agent kit is a library that gives a model a set of Solana tools. Most read tools are one JSON-RPC call to an endpoint you configure, so pointing a kit at Carbium comes down to two settings: the endpoint, and where the key travels.

RPC is `https://services.carbium.sh` and WebSocket is `wss://services.carbium.sh`. One domain serves every plane, so a kit needs no second host for subscriptions.

The file below is read only. It builds one RPC client with @solana/kit 8.6.0, reads two things from the chain and prints them. It holds no private key and sends nothing. If your kit also ships signing and sending tools, keep them out of the model's tool list until you have designed a separate path for them; [Read-only model tools](https://carbium.sh/library/si/read-only-model-tools) shows an allowlist that does this.

## Two ways to pass the key

| What the kit's settings accept | What you give it | Where the key goes |
|---|---|---|
| An RPC client or a transport object | `rpc` from the setup file | `x-api-key` request header |
| One endpoint string, such as an `RPC_URL` setting | `rpcUrl` from the setup file | `?api-key=` in the URL |
| A WebSocket URL for subscriptions | `wsUrl` from the setup file | `?api-key=` in the URL |

Prefer the header when the kit allows it. A key inside a URL turns up wherever the URL is logged: a startup line, an error message that echoes the request, a config dump the model can read. A key that reaches the model's context has leaked, so when a kit forces the URL form, check what it prints at startup and what its errors contain.

RPC also accepts `authorization: Bearer <key>`, and a WebSocket can carry the key as the subprotocol `api-key.<key>`. They suit kits whose HTTP layer exposes only those, and the file uses neither.

## The setup file

One file. Node 24 runs the TypeScript directly and @solana/kit 8.6.0 is the only dependency. `CARBIUM_KEY` must be set; the file exits with a message when it is not. `CARBIUM_RPC_URL` and `CARBIUM_WS_URL` override the two endpoints, which default to the addresses above.

`main.ts` (run: `node main.ts`)

```ts
// SI0003 · Agent kit RPC setup
// https://carbium.sh/library/si/agent-kit-rpc-setup
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

// Carbium RPC for an agent kit. Run: CARBIUM_KEY=... node main.ts [address]
import { address, createDefaultRpcTransport, createSolanaRpcFromTransport } from "@solana/kit";

const key: string = process.env.CARBIUM_KEY ?? "";
if (!key) {
  console.error("Set CARBIUM_KEY to your Carbium API key.");
  process.exit(1);
}
const rpcBase = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";
const wsBase = process.env.CARBIUM_WS_URL ?? "wss://services.carbium.sh";

// Kits that take one URL string get the key as ?api-key=. Keep that URL out of logs.
const withKey = (base: string): string => {
  const url = new URL(base);
  url.searchParams.set("api-key", key);
  return url.toString();
};
export const rpcUrl = withKey(rpcBase);
export const wsUrl = withKey(wsBase);

// Kits that take a client or a transport get the key as a header, which no URL log shows.
export const rpc = createSolanaRpcFromTransport(
  createDefaultRpcTransport({ url: rpcBase, headers: { "x-api-key": key } }),
);

// The kit client throws on HTTP 429: wait the hinted seconds once, then pass the error on.
export async function call<T>(send: () => Promise<T>, retried = false): Promise<T> {
  try {
    return await send();
  } catch (e) {
    const ctx = (e as { context?: { statusCode?: number; headers?: Headers } }).context;
    if (ctx?.statusCode !== 429 || retried) throw e;
    const seconds = Math.min(Number(ctx.headers?.get("retry-after")) || 1, 10);
    await new Promise((done) => setTimeout(done, seconds * 1000));
    return call(send, true);
  }
}

if (import.meta.main) {
  const target = address(process.argv[2] ?? "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
  // No commitment named: kit sends confirmed. The second call names finalized.
  const confirmed = await call(() => rpc.getSlot().send());
  const finalized = await call(() => rpc.getSlot({ commitment: "finalized" }).send());
  const { value } = await call(() =>
    rpc.getAccountInfo(target, { commitment: "confirmed", encoding: "base64" }).send(),
  );
  console.log(`slot confirmed ${confirmed}, finalized ${finalized}`);
  console.log(
    value
      ? JSON.stringify({ lamports: String(value.lamports), owner: value.owner, executable: value.executable })
      : "account not found",
  );
}
```

Pass a public address as the first argument; the default is the Token program. The first output line is the confirmed and finalized slot. The second is the account's lamports, owner and executable flag. For the Token program `executable` is `true` and the owner is a loader program. Lamports print as a string because they arrive as a bigint and JSON cannot hold one.

`call` adds the one behaviour a kit leaves to you. On an HTTP 429 the kit client throws an error with the status in `context.statusCode`. The wrapper waits the `retry-after` seconds (1 when the header is missing, 10 at most) and tries once more. A second 429 reaches your loop.

## Which commitment a call uses

The JSON-RPC server answers at `finalized` when a request names no commitment. @solana/kit 8.6.0 changes that: it fills in `confirmed` (`defaultCommitment: "confirmed"` in @solana/rpc) when a call leaves commitment out. The first `getSlot` in the file therefore runs at confirmed, and the second names finalized. A kit that wraps its own client may set another default, so check what its read tools send before you compare numbers between tools.

Two reads one after the other can show confirmed and finalized equal, or briefly out of order, because they are two requests at two moments. Treat a gap of one slot in either direction as noise, and name the level in each tool description so the model can say which one it reported.

## What a kit's tools cost

Carbium charges each call in cells, and each plan has a [requests-per-second ceiling](https://carbium.sh/docs#limits) per call class. Cached reads such as `getHealth`, `getVersion` and `getSlot` cost 1 cell. Account reads such as `getAccountInfo`, `getMultipleAccounts` and `getTokenAccountBalance` cost 10. `getTransaction` and `getSignaturesForAddress` cost 50. `sendTransaction` costs 20 without preflight and 70 with it.

| Call class | Cells | Free (req/s) | Dev (req/s) | Business (req/s) | Pro (req/s) |
|---|---|---|---|---|---|
| Cached reads, such as `getSlot` | 1 | 5 | 30 | 100 | 500 |
| Account reads, such as `getAccountInfo` | 10 | 0.5 | 15 | 50 | 400 |
| `getSignaturesForAddress` | 50 | 0.24 | 1.2 | 100 | 500 |

On Free, an agent that reads accounts gets one call every two seconds, so size the tool loop to the plan. A tool that checks ten accounts one at a time costs 100 cells. `getMultipleAccounts` takes up to 300 pubkeys (100 below Pro) and charges 10 cells per pubkey, so it saves round trips and charges the same cells as separate calls. A JSON-RPC batch holds up to 100 calls.

Limits are per account, and an account's keys share one budget, so a second key for a second agent adds no capacity.

Some methods are not served and answer -32601, method not served. `getTokenLargestAccounts` and `getProgramAccountsV2` are two of them. A kit tool built on one fails every time. Do not retry a -32601; remove the tool from the list the model sees.

## One client and the WebSocket

Build the client once at startup and import it in every tool. A client created inside a tool function starts cold on every call.

Subscriptions use `wsUrl`, which carries the key as `?api-key=`. Each plan caps connections and subscriptions per account, and Free carries 5 sockets. Share one socket across the agent's subscriptions.

A subscription opens at 5, 25 or 200 credits by filter weight and then costs 20 credits per MiB sent; a refused subscription is free. Slot, root and signature filters open at 5. Account, logs-mentions and slot-update filters open at 25. Program, all-logs, block and transaction-firehose filters open at 200. Open the narrowest filter the tool needs.

Two behaviours matter to a kit. `accountSubscribe` stays silent for a plain SOL wallet; use `logsSubscribe` with mentions plus `getBalance`. `signatureSubscribe` sends one confirmation for a signature and then the subscription ends, which suits a tool that waits on a single transaction.

## Where it ends

- The file reads. `sendTransaction` is served, so the endpoint will accept a send the model asks for. Refusing it is your code's job, in the tool list or an allowlist.
- `rpcUrl` and `wsUrl` carry the key in the URL. Anything that logs the URL logs the key. The header form on `rpc` has no such trail.
- `getSignaturesForAddress` pages come from Carbium's own address index, which keeps up to 30 days. A tool that lists an address's whole history gets a partial answer, and an empty page past 30 days is the index's age limit and says nothing about the address's first transaction.
- The wrapper retries a 429 once. It does not budget cells across a task, so cap tool calls per task in your loop.
- Kits differ in how they take an endpoint, and no single setting fits all of them. A kit that builds its own client inside may ignore both exports; look for a transport or URL option in its settings.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The key shows up in the kit's startup log or in an error message. | Pass the `rpc` client so the key goes in the header. When the kit needs a URL string, turn off its request logging and keep its error text away from the model. |
| A kit tool fails with -32601 on every call. | The method is not served. Do not retry it, and remove the tool from the model's list. |
| Reads start returning 429 inside a short tool loop. | Limits are per account and an account's keys share one budget. Cap tool calls per task, and on Free remember that account reads run at 0.5 req/s. |
| Two tools report a balance one slot apart. | One call used the kit's default `confirmed` and the other asked for `finalized`, or two reads landed at different moments. Name the commitment in each call and in each tool description. |
| A tool that lists an address's history stops after 30 days. | That is the address index's age limit. Tell the model in the tool description that history reaches back 30 days at most. |
| `accountSubscribe` on a wallet never fires. | A plain SOL wallet stays silent on it. Subscribe with `logsSubscribe` mentions and read the balance with `getBalance` when a log arrives. |

## Questions

### Which package does the setup file use?

Only @solana/kit 8.6.0, and Node 24 runs the TypeScript as it is. The global `fetch` and `WebSocket` need nothing installed.

### Can a kit that takes only a URL use the header?

No. A URL-only setting cannot add a header, so use `rpcUrl` with `?api-key=` and keep that URL out of logs. When the kit exposes a transport or client option, the header form is the better choice.

### Which endpoint do subscriptions use?

`wss://services.carbium.sh` with `?api-key=` on the URL. It is the same domain as RPC.

### How many reads can the agent make on Free?

Cached reads cost 1 cell at 5 req/s and account reads cost 10 cells at 0.5 req/s. Dev, Business and Pro run higher on both.

## Related

- [Read-only model tools](https://carbium.sh/library/si/read-only-model-tools) (AI and blockchain, SI0001)
- [RPC rate-limit alerts](https://carbium.sh/library/usecase/rpc-rate-limit-alerts) (Use cases, UC0001)
- [carbium.sh/docs#rpc](https://carbium.sh/docs#rpc)
- [carbium.sh/docs#auth](https://carbium.sh/docs#auth)
- [carbium.sh/docs#endpoints](https://carbium.sh/docs#endpoints)
- [carbium.sh/docs#limits](https://carbium.sh/docs#limits)
- [carbium.sh/docs#websocket](https://carbium.sh/docs#websocket)
