> For the complete documentation index, see [llms.txt](https://docs.yo.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.yo.xyz/integrations/integration-guides/sdk/core/api-client.md).

# API client

The `ApiClient` provides access to off-chain data from the Yo REST API (`https://api.yo.xyz`).

## Usage via YoClient

The `YoClient` creates an `ApiClient` internally:

```ts
const client = createYoClient({ chainId: 8453 })

const snapshot = await client.getVaultSnapshot(vaultAddress)
const yieldHistory = await client.getVaultYieldHistory(vaultAddress)
const tvlHistory = await client.getVaultTvlHistory(vaultAddress)
const userHistory = await client.getUserHistory(vaultAddress, userAddress, 50)
const points = await client.getUserPoints(userAddress)
```

## Standalone Usage

```ts
import { createApiClient } from '@yo-protocol/core'

const api = createApiClient()
// or with custom base URL:
const api = createApiClient({ baseUrl: 'https://custom-api.example.com' })
```

## Pending Redemptions

Query pending async redemptions for a user or an entire vault.

```ts
// User-specific pending redemptions
const pending = await client.getPendingRedemptions(vaultAddress, userAddress)
console.log(pending.assets?.formatted)  // e.g. "100.50"
console.log(pending.shares?.formatted)  // e.g. "95.20"

// Vault-level pending redeems
const vaultPending = await client.getVaultPendingRedeems(vaultAddress)
```

### PendingRedeem

| Field    | Type                          | Description          |
| -------- | ----------------------------- | -------------------- |
| `assets` | `FormattedValue \| undefined` | Pending asset amount |
| `shares` | `FormattedValue \| undefined` | Pending share amount |

## Response Types

### VaultSnapshot

| Field        | Type             | Description               |
| ------------ | ---------------- | ------------------------- |
| `address`    | `string`         | Vault address             |
| `name`       | `string`         | Vault name                |
| `symbol`     | `string`         | Vault symbol              |
| `tvl`        | `FormattedValue` | Total value locked        |
| `apy`        | `number`         | Current APY percentage    |
| `underlying` | `object`         | Underlying token info     |
| `pools`      | `Pool[]`         | Optional pool allocations |

### TimeseriesPoint

| Field       | Type     | Description      |
| ----------- | -------- | ---------------- |
| `timestamp` | `number` | Unix timestamp   |
| `value`     | `number` | APY or TVL value |

### UserHistoryItem

| Field       | Type                                  | Description      |
| ----------- | ------------------------------------- | ---------------- |
| `type`      | `'deposit' \| 'withdraw' \| 'redeem'` | Transaction type |
| `timestamp` | `number`                              | Unix timestamp   |
| `assets`    | `FormattedValue`                      | Asset amount     |
| `shares`    | `FormattedValue`                      | Share amount     |
| `txHash`    | `string`                              | Transaction hash |

### Error Handling

API errors throw `ApiError` with a `statusCode` property:

```ts
import { ApiError } from '@yo-protocol/core'

try {
  await client.getVaultSnapshot(address)
} catch (err) {
  if (err instanceof ApiError) {
    console.error(err.statusCode, err.message)
  }
}
```


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.yo.xyz/integrations/integration-guides/sdk/core/api-client.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
