<!--
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)
-->

# PlatformClient

The HTTP client for the hosted platform API. Use it to manage agents and their signing sessions, read vault data, set policy, and run the card rail — all with an operator API key, no local private key required.

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

const platform = new PlatformClient({
  baseUrl: "https://api.example.com",
  apiKey: "nab_sk_...", // operator API key
});
```

You can also get a pre-configured instance from a managed vault with `vault.getPlatformClient()`.

## Agents

```typescript
const { address, sessionExpiresAt } = await platform.createAgent("research-bot");
const agents = await platform.listAgents();
const agent = await platform.getAgent(address);
await platform.refreshSession(address); // extend the signing session
await platform.deactivateAgent(address);
```

`createAgent(name)` provisions a managed key and an initial signing session. `refreshSession(address)` extends a session before it expires; `getAgent`/`listAgents` return the agent's `name`, `hdIndex`, `status`, and `sessionExpiresAt`.

### Signing

```typescript
const { signature } = await platform.sign(address, "message", "hello");
```

`sign(address, type, payload)` signs with the agent's managed key. `type` is `"transaction"`, `"message"`, or `"typed_data"`.

## Vault reads

```typescript
const vaults = await platform.listVaults();
const balance = await platform.getVaultBalance(vaultAddress, [tokenAddress]);
const fleet = await platform.getVaultAgents(vaultAddress);
const history = await platform.getVaultHistory(vaultAddress);
const spending = await platform.getVaultSpending(vaultAddress, "day");
const token = await platform.getTokenMetadata(tokenAddress); // symbol, decimals
```

## Policy

Policy is per-agent. Set up an agent's policy module, then update its params.

```typescript
const policy = await platform.getAgentPolicy(vaultAddress, agentAddress);
await platform.setupPolicy(vaultAddress, agentAddress, "token");
await platform.updatePolicyParams(vaultAddress, agentAddress, params);
```

Build `params` with [buildPolicyParams](/reference/sdk/build-policy-params). `setupPolicy` requires the agent's module to already be installed on the vault.

## Admin transactions

These return an unsigned transaction for you to sign and submit — the platform never holds the operator key.

```typescript
const tx = await platform.withdrawTx(vaultAddress, tokenAddress, "500000", recipient);
await platform.shutdownTx(vaultAddress);
await platform.unpauseTx(vaultAddress);
```

## Card rail

Each method takes the vault address and a body object; `simulateCardAuth` also takes the card token.

```typescript
await platform.linkCardProgram(vaultAddress, {
  program_id: "...",
  api_key: "...",
});

const card = await platform.createCard(vaultAddress, {
  agent_address: agentAddress, // optional — bind the card to an agent
});

await platform.setCardPolicy(vaultAddress, {
  card_policy_params: policy,
});

// Sandbox only — simulate an authorization against an issued card.
const auth = await platform.simulateCardAuth(vaultAddress, cardToken, {
  amount: 1000,
  descriptor: "Coffee Shop",
});
```

See [Issue a Card](/guides/issue-a-card) for the full flow.

## See also

* [ModularVault](/reference/sdk/modular-vault) — connect to a vault and read balances.
* [FacilitatorClient](/reference/sdk/facilitator-client) — charge agents to call your API.
