# Configure the SDK

Every option `createMaxyClient` takes: the key, the base URL, timeouts, retries, your own `fetch`, and hooks for logging. It is for developers wiring the SDK into a server or an app. With no options at all, the client reads `MAXY_API_KEY` from the environment in Node and uses production defaults.

## The key decides the environment

| Key | What the client does |
| --- | --- |
| `mxk_test_…` | Runs in the [sandbox](https://maxy.co/docs/sandbox): same calls, nothing real. `maxy.sandbox` is `true`, and the client can reach only the sandbox API |
| `mxk_live_…` | Live orders. Keep it on your server |
| `mxk_pk_live_…`, `mxk_pk_test_…` | A publishable key for a browser page: prices, quotes, status, address checks and the user's own signed order, from the origins it was issued for |

A secret key in a browser page throws when the client is created, with a message saying why. `dangerouslyAllowBrowser: true` overrides that, and anyone who opens the page can then read the key. A key that is not whole throws `TypeError` at once, before any call. Which key goes where: [Keys and limits](https://maxy.co/docs/keys-and-limits).

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `apiKey` | `MAXY_API_KEY` in Node | Your secret, test or publishable key |
| `apiUrl` | `https://openapi.maxy.co/v1` | Where the client sends its calls (the earlier addresses keep answering) |
| `baseUrl` | none | `maxy-labs/core` only: replaces the whole base, such as your own proxy |
| `timeoutMs` | 30 000 | Per attempt, in milliseconds |
| `maxRetries` | 2 | Retries after a `429`, `502`, `503`, `504` or a dropped connection, with backoff, honouring `Retry-After` |
| `fetch` | `globalThis.fetch` | Your own `fetch`, for a proxy, a test double or an older runtime |
| `onRequest`, `onResponse`, `onRetry` | none | Told about every call. They never receive a key, a signature or typed data |
| `logger` | none | Any object with `debug`, `info`, `warn`, `error`. Without one the SDK logs nothing; with one, keys, signatures and typed data are redacted |
| `dangerouslyAllowBrowser` | `false` | Lets a secret key run in a browser page |

The full client from `maxy-labs` takes these too, apart from `baseUrl`, and adds:

| Option | What it does |
| --- | --- |
| `rpcUrls` | Your own JSON-RPC URLs per EVM chain id, tried first for the SDK's own chain reads (nonces, escrows). Then Maxy's read-only proxy, then public endpoints |
| `getAccessToken` | The wallet session for calls that act for a wallet, such as selling BTC with `swap.createOrder` and listing a wallet's orders |
| `solanaWeb3` | The `@solana/web3.js` module, for Solana orders in a browser bundle. Node loads it by itself when it is installed |
| `attestSigners` (or `MAXY_ATTEST_SIGNERS`, comma-separated, in Node) | The keys whose signed per-order deposit addresses a sell accepts; unset, only the compiled Maxy addresses pass |
| `lifiApiUrl`, `tronApiUrl`, `suiGraphqlUrl`, `jupiterApiUrl` | Your own hosts for the legs that go through LI.FI, Tron, Sui and the Solana swap (default: through `openapi.maxy.co`) |

`MAXY_API_BASE` in the environment replaces the default of `apiUrl` (and of `baseUrl` in `maxy-labs/core`), for a test server of your own. An `apiUrl` or `baseUrl` you pass wins over it; with both, `baseUrl` wins in `maxy-labs/core`.

## Retries are safe

Reads, and calls that carry an idempotency key, are retried. `orders.create` sets its key from the order id, so a dropped connection never places two orders: the same signed order returns the same `orderId`. Any other POST is sent once unless you pass `idempotencyKey`. A burst waits for the rate-limit minute to turn over instead of collecting `429`s.

Every method also takes, as its last argument, `{ signal, idempotencyKey, requestId, timeoutMs }`. Your `requestId` becomes the answer's `x-request-id`; `signal` stops the call at once and sends nothing further.

## A configured client

With a test key, this runs as it is. The `rate_limited` scenario makes the sandbox answer `429`, so you see the retries and the error the SDK throws after them.

```ts
import { createMaxyClient, isMaxyError } from 'maxy-labs/core';

const maxy = createMaxyClient({
  apiKey: process.env.MAXY_API_KEY, // mxk_test_… in the sandbox, mxk_live_… live
  timeoutMs: 10_000,                // per attempt; the default is 30 000
  maxRetries: 2,                    // the default
  onResponse: ({ method, path, status, latencyMs, requestId }) => console.log(method, path, status, `${latencyMs} ms`, requestId),
  onRetry: ({ path, attempt, delayMs }) => console.log('retry', path, attempt, delayMs),
});

const limits = await maxy.limits.get();
console.log(limits.orderCapUsd, limits.quoteTtlSeconds, limits.meta.rateLimit); // 100 60 { limit: 120, remaining: …, resetSeconds: 60 }

try {
  await maxy.prices.get({ from: 'ETH on base', to: 'BTC', amount: '0.01', scenario: 'rate_limited' });
} catch (e) {
  if (isMaxyError(e)) console.log(e.code, e.status, e.retryable, e.requestId); // rate_limited 429 true <request id>
}
```

It prints one line per attempt: the `429`, a retry after the `Retry-After` wait, a second, then the error. Quote the `requestId` to Maxy when you ask about a call.

Errors by class, and what to show the user: [Error codes](https://maxy.co/docs/error-codes). Test the rest of your integration: [Test your integration](https://maxy.co/docs/test-your-integration).

---
Source: https://maxy.co/docs/configure-the-sdk (Maxy Docs › SDK › Getting started)
