Skip to content
Open
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,19 @@ weather API":
vapi mcp install <claude-code|claude-desktop|cursor|codex>
```

Call the same client from TypeScript:
Call the same client from TypeScript (needs a local wallet first — run
`vapi setup`, or `vapi init` for a non-interactive setup; with no
`account`, the client uses your default account):

```ts
import { createVapiClient } from "vapi-network";

const vapi = await createVapiClient({ account: "researcher" });
const listings = await vapi.call.search("Base DEX volume");
const result = await vapi.call.pay({ id: "base-dex-volume", maxPriceUsd: 0.05 });
const vapi = await createVapiClient();
const [listing] = (await vapi.call.search("Base DEX volume")) as Array<{
ref: string;
}>;
await vapi.call.inspect(listing.ref);
const result = await vapi.call.pay({ id: listing.ref, maxPriceUsd: 0.05 });
console.log(result.body);
```

Expand Down
6 changes: 6 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ The `device` field in `config.json` names the device sent with link requests, us

`allowPrivateNetwork` applies to every request the CLI makes to vAPI, including sign-in, Router, Tasks and cloud backup, as well as to discovery. A machine whose DNS answers with proxy addresses such as `198.18.0.0/15`, as behind a local proxy or a container egress gateway, needs it too; it turns the address check off for every destination, so only set it on a machine you trust.

Edit the `config.json` the client generated — it already contains
every field above, including `"allowPrivateNetwork": false`. A new
file containing only some fields fails validation: `discoveryUrl`,
`networks` and `spendCaps` are required in the file, even though the
defaults in the table apply when no file exists.

`BASE_RPC_URL` overrides the Base RPC. `ARC_RPC_URL` overrides the Arc mainnet RPC. `ARC_TESTNET_RPC_URL` and
`SOLANA_RPC_URL` point those two networks at an endpoint you trust. On first
use of the default home, the client copies an existing `~/.vapi/agent-cash/`
Expand Down
24 changes: 19 additions & 5 deletions docs/sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,32 @@ local agents behind one API:
npm i vapi-network
```

The wallet-backed methods below need a local wallet: run `vapi setup`
first (or `vapi init` for a non-interactive setup). With no `account`,
the client uses your default account; pass `{ account: "researcher" }`
only for an agent account you created, as in the
[agents guide](./agents.md). The `docs` namespace further down needs
no wallet.

```ts
import { createVapiClient } from "vapi-network";

const vapi = await createVapiClient({ account: "researcher" });
const vapi = await createVapiClient();
const reply = await vapi.router.chat({
model: "venice/claude-sonnet-5",
messages: [{ role: "user", content: "Summarise Base DEX activity." }],
});
console.log(reply.content);

const listings = await vapi.call.search("Base DEX volume");
console.log(listings);
const result = await vapi.call.pay({ id: "base-dex-volume", maxPriceUsd: 0.05 });
const [listing] = (await vapi.call.search("Base DEX volume")) as Array<{
ref: string;
}>;
console.log(listing);
await vapi.call.inspect(listing.ref);
const result = await vapi.call.pay({ id: listing.ref, maxPriceUsd: 0.05 });
console.log(result.body);

// This buys $5 of Router balance; skip it until you mean to spend.
const purchase = await vapi.router.buy(5);
const receipt = purchase.receipt; // Keep the proof of payment.
console.log(receipt, purchase.balance);
Expand Down Expand Up @@ -129,7 +140,10 @@ payments use the class imported directly from `@vapi-network/core`.
import { core } from "vapi-network";

try {
await vapi.call.pay({ id: "weather", maxPriceUsd: 0.05 });
const [listing] = (await vapi.call.search("weather")) as Array<{
ref: string;
}>;
await vapi.call.pay({ id: listing.ref, maxPriceUsd: 0.05 });
} catch (error) {
if (!(error instanceof core.SpendCapExceededError)) throw error;
console.error(error.cap, error.amountUsd, error.limitUsd, error.command);
Expand Down
2 changes: 2 additions & 0 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Some agent sandboxes send traffic through an egress proxy that refuses OAuth tok

Inspecting or paying a Solana listing returns `unsupported_network`. Solana listings stay searchable; vault payments on Solana arrive in a later release.

`URL hostname "<host>" is not allowed; private or internal destinations require allowPrivateNetwork true in the vAPI config.` DNS answers with private or proxy addresses (for example `198.18.0.0/15`) behind a local proxy or container egress gateway, so the public-URL guard blocks even vAPI's own hosts (`api.vapinetwork.ai`, `docs.vapinetwork.ai`, `mainnet.base.org`). Fix DNS so the host resolves to its public addresses, or — only on a machine you trust — set `"allowPrivateNetwork": true` in the existing `~/.vapi/config.json`. See [Configuration](./configuration.md).

If you sent ETH to an agent account by mistake, the account still holds it on Base. Send it back minus the Base network fee:

```sh
Expand Down
11 changes: 8 additions & 3 deletions examples/pay-with-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
*
* Run it with `pnpm example:pay -- weather`. It uses the wallet `vapi init`
* created: `VAPI_WALLET` or the machine default, unless you pass a name as the
* second argument. The passphrase comes from `VAPI_KEYSTORE_PASSWORD`, then
* from the OS secret store `vapi unlock` writes to, then from a prompt.
* second argument. Vault accounts need no passphrase; for a legacy keystore
* account the passphrase comes from `VAPI_KEYSTORE_PASSWORD`, then from the
* OS secret store, then from a prompt.
*/
import { randomUUID } from "node:crypto";

Expand Down Expand Up @@ -41,7 +42,11 @@ if (!listing) throw new Error(`No payable listing found for ${JSON.stringify(que
// caps that belong to that wallet rather than to the machine.
const store = await WalletStore.open(paths.directory);
const selected = store.resolve(requestedWallet === undefined ? {} : { name: requestedWallet });
const { passphrase } = await resolvePassphrase(selected.name);
// Vault accounts unlock with the device key; only legacy keystores
// need a passphrase (same pattern as docs/sdk.md and the SDK client).
const passphrase = (await store.hasVaultAccount(selected.name))
? ""
: (await resolvePassphrase(selected.name)).passphrase;
const account = await store.unlock(selected.name, passphrase);
console.error(`Wallet: ${selected.name} (${account.address})`);

Expand Down
4 changes: 2 additions & 2 deletions examples/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ if (store.has(name)) {
spendCaps: { perCallAtomic: String(usdToAtomic(0.05)), perDayAtomic: String(usdToAtomic(1)) },
});
console.log(`Created ${created.name} at ${created.account.address}.`);
console.log(`Write its recovery phrase down with: vapi backup --wallet ${created.name}`);
console.log(`Write its recovery phrase down with: vapi backup --account ${created.name}`);
}

// Caps belong to the wallet, so an agent's allowance is independent of yours.
Expand All @@ -60,4 +60,4 @@ console.log(
BigInt(capped.spendCaps.perDayAtomic),
)} per day.`,
);
console.log(`Unlock it for an agent with: vapi unlock --wallet ${name}`);
console.log(`Unlock the vault for an agent with: vapi vault unlock`);
4 changes: 2 additions & 2 deletions packages/core/src/passphrase.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe("resolvePassphrase", () => {
expect(resolved).toEqual({ passphrase: "typed-passphrase", source: "prompt" });
expect(prompt).toHaveBeenCalledWith(
"Passphrase for main: ",
expect.stringContaining("vapi unlock --wallet main"),
expect.stringContaining("vapi unlock --account main"),
);
});

Expand Down Expand Up @@ -119,7 +119,7 @@ describe("resolvePassphrase", () => {
await expect(
resolvePassphrase("agent-claude", { env: {}, store, prompt, interactive: false }),
).rejects.toThrow(
"No interactive terminal is available for the keystore prompt. Set VAPI_KEYSTORE_PASSWORD, or store this wallet's passphrase once with vapi unlock --wallet agent-claude.",
"No interactive terminal is available for the keystore prompt. Set VAPI_KEYSTORE_PASSWORD, or store this wallet's passphrase once with vapi unlock --account agent-claude.",
);
expect(prompt).not.toHaveBeenCalled();
});
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/passphrase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export type ResolvePassphraseOptions = {

/** The two ways out of a run that cannot prompt, named for the wallet at hand. */
export function noPassphraseHint(walletName: string): string {
return `Set ${PASSPHRASE_ENVIRONMENT_VARIABLE}, or store this wallet's passphrase once with vapi unlock --wallet ${walletName}.`;
return `Set ${PASSPHRASE_ENVIRONMENT_VARIABLE}, or store this wallet's passphrase once with vapi unlock --account ${walletName}.`;
}

/**
Expand All @@ -49,7 +49,7 @@ export function noPassphraseHint(walletName: string): string {
export function staleStoredPassphraseMessage(walletName: string, store: SecretStore): string {
return [
`The passphrase stored in ${store.description} no longer opens wallet ${walletName}.`,
`Store the current one with vapi unlock --wallet ${walletName}, or remove it with vapi lock --wallet ${walletName}.`,
`Store the current one with vapi unlock --account ${walletName}, or remove it with vapi lock --account ${walletName}.`,
].join(" ");
}

Expand Down
Loading