> For the complete documentation index, see [llms.txt](https://docs.zert.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zert.com/routing-engine-sdk/installation-and-configuration.md).

# Installation and Configuration

Install and configure the Routing Engine SDK for Zert's routing API.

> TypeScript/JavaScript client for Zert's routing API — tokens, chains, pairs, quotes, swaps, execution, and limit orders.

The Routing Engine SDK calls **Zert's backend only**. The base URL is fixed in the package as **`DEFAULT_API_BASE_URL`** (see `routing-engine-sdk` exports); you cannot override it via config.

**All API requests require an API key.** Pass `api.apiKey` when creating the SDK; it is sent as the **`x-api-key`** header on every request (header name is also available as **`API_KEY_HEADER`**).

## How to integrate the SDK

**Step 1 — Install the SDK**

```bash
npm install routing-engine-sdk
```

Or with yarn, pnpm, or bun:

```bash
yarn add routing-engine-sdk
# or: pnpm add routing-engine-sdk
# or: bun add routing-engine-sdk
```

**Step 2 — Create and configure the SDK**

```typescript
import { RoutingEngineSDK, DEFAULT_API_BASE_URL, API_KEY_HEADER } from 'routing-engine-sdk';

const sdk = new RoutingEngineSDK({
  api: {
    apiKey: 'your-api-key',
  },
});
```

Optional: timeout and headers:

```typescript
const sdk = new RoutingEngineSDK({
  api: {
    apiKey: 'your-api-key',
    timeout: 15000,
    baseHeaders: {
      headers: { 'X-Custom': 'value' },
    },
  },
});
```

**Step 3 — Call the API**

Use layers (e.g. `sdk.tokens`, `sdk.quote`) or flat methods (`getTokens`, `requestQuote`, `createLimit`):

```typescript
const tokens = await sdk.getTokens();
const quote = await sdk.requestQuote({
  fromChain: 'arbitrum',
  toChain: 'avax',
  tokenIn: 'TBTC',
  tokenOut: 'WETH',
  network: 'mainnet',
  amount: '100.00',
  slippageBps: 75,
  recipient: '0x1234567890123456789012345678901234567890',
});
const build = await sdk.buildSwap({
  quoteId: quote.data.quoteId,
  routeId: quote.data.routes[0].routeId,
  recipient: '0x1234567890123456789012345678901234567890',
});
const signing = await sdk.getSwapSigning(build.data.swapId);
await sdk.submitSwapSigning(build.data.swapId, { rawTx: '0xsigned_raw_tx' });

const order = await sdk.createLimit({
  timeInForce: 'GTC',
  minAmountOut: '1',
  fromChain: 'arbitrum',
  toChain: 'avax',
  tokenIn: 'TBTC',
  tokenOut: 'WETH',
  network: 'mainnet',
  amount: '100.00',
  slippageBps: 75,
  recipient: '0x1234567890123456789012345678901234567890',
});
const status = await sdk.getTransactionStatus('0xhash', { chainRef: 'eth-mainnet' });
const health = await sdk.getHealth();
```

**Step 4 — Handle errors**

See Error Handling. API failures throw `RoutingEngineAPIError`. Invalid or unsupported config (e.g. wrong types, or passing `baseURL`) can throw `ConfigTypeError` in development.

### API surface

| Layer / access | Doc              |
| -------------- | ---------------- |
| `sdk.tokens`   | Token Management |
| `sdk.chains`   | Chains           |
| `sdk.pairs`    | Pairs            |
| `sdk.quote`    | Quote            |
| `sdk.swap`     | Swap             |
| `sdk.limit`    | Limit orders     |
| `sdk.status`   | Status           |
| `sdk.health`   | Health           |

`sdk.api` exposes the same layers for backward compatibility.

### Flat API

| Flat method                                                                    | Delegates to                                                |
| ------------------------------------------------------------------------------ | ----------------------------------------------------------- |
| `getTokens(params?)`, `getChains()`, `getPairs(params?)`                       | `tokens.get(params?)`, `chains.get()`, `pairs.get(params?)` |
| `requestQuote(body)`                                                           | `quote.request(body)`                                       |
| `buildSwap(body)`, `getSwapSigning(swapId)`, `submitSwapSigning(swapId, body)` | matching `swap.*` methods                                   |
| `createLimit`, `getLimit`, `cancelLimit`, `replaceLimit`, `listLimits`         | matching `limit.*` methods                                  |
| `getTransactionStatus(txHash, params)`, `getHealth()`                          | `status.getTransaction(...)`, `health.get()`                |

## Configuration reference (`api` option)

| Field         | Description                                                                                     |
| ------------- | ----------------------------------------------------------------------------------------------- |
| `apiKey`      | Required for authenticated Zert API calls; sent as `x-api-key`.                                 |
| `timeout`     | Request timeout in ms (default `10000`).                                                        |
| `baseHeaders` | Optional `{ known?, headers?, only? }` maps merged into default headers (after `Content-Type`). |
| `onError`     | Optional callback invoked before throwing `RoutingEngineAPIError`.                              |

Unsupported: **`baseURL`** — the SDK always uses `DEFAULT_API_BASE_URL`.


---

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.zert.com/routing-engine-sdk/installation-and-configuration.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
