> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dzap.io/llms.txt
> Use this file to discover all available pages before exploring further.

# SDK-AI

> Use DZapSDK from @dzapio/ai to run chat, tools, sessions, and scheduler utilities.

`DZapSDK` is the main orchestrator in `@dzapio/ai`.

<Note>
  * `@dzapio/sdk`: direct chain primitives.
  * `@dzapio/ai` (`DZapSDK`): agent runtime, tool orchestration, sessions, scheduler hooks.
</Note>

## Install

```bash theme={null}
npm install @dzapio/ai
```

## Constructor

```ts theme={null}
import { DZapSDK } from "@dzapio/ai";

const sdk = new DZapSDK({
  baseUrl: "https://nlp-ai-439689868940.europe-north1.run.app", // optional
  systemPrompt: "You are a DeFi assistant.", // optional
  // systemPromptPath: "./prompt.txt", // optional
});
```

## Initialize runtime

```ts theme={null}
await sdk.initialize({
  syncProviders: false,
  initializeRetrieval: true,
});
```

## Ask (main entry point)

```ts theme={null}
const result = await sdk.ask({
  userQuery: "Show my balances and current ETH price",
  metadata: {
    accountInfo: [
      { blockchain: "evm", chain: "1", user_account: "0xabc..." },
    ],
  },
  transactionConfirmationMode: "on",
  onStep: (step) => {
    console.log(step.toolName ?? step.type);
  },
});

console.log(result.sessionId);
console.log(result.finalText);
console.log(result.chainId);
```

Return payload includes:

* `sessionId`
* `finalText`
* `chainId`
* optional `balanceData`
* `steps[]`

## Call tools directly

```ts theme={null}
const output = await sdk.executeTool("PriceTool", {
  tokenAddresses: "0xA0b86991c6218b36c1d19d4a2e9eb0ce3606eB48",
  chainId: 1,
});

console.log(output);
```

Direct calls are useful for deterministic backend flows.

## Session and schedule APIs

```ts theme={null}
const tools = sdk.listTools();
const history = sdk.getChatHistory(result.sessionId);
const sessionSnapshot = sdk.getSessionHistory(result.sessionId);

const schedules = sdk.getSchedulesByUserId("user-123");
await sdk.runSchedulerOnce();
await sdk.startSchedulerLoop(60000);
```

## Interactive confirmations (when needed)

```ts theme={null}
await sdk.confirmZap("session-id", "yes");
await sdk.confirmChainChange("session-id", "approve");
```

These resolve pending interactive flows created by execution-sensitive tools.

## See also

* [Tool Categories](/ai/tools/overview)
* [CLI](/ai/cli/overview)
* [MCP Server](/ai/mcp/overview)
