# Installation and Configuration

> 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: 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.zert.com/routing-engine-sdk/installation-and-configuration.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.
