Find something... ⌘K

SDK / Getting started

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

KeyWhat the client does
mxk_test_…Runs in the 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.

Options

OptionDefaultWhat it does
apiKeyMAXY_API_KEY in NodeYour secret, test or publishable key
apiUrlhttps://openapi.maxy.co/v1Where the client sends its calls (the earlier addresses keep answering)
baseUrlnonemaxy-labs/core only: replaces the whole base, such as your own proxy
timeoutMs30 000Per attempt, in milliseconds
maxRetries2Retries after a 429, 502, 503, 504 or a dropped connection, with backoff, honouring Retry-After
fetchglobalThis.fetchYour own fetch, for a proxy, a test double or an older runtime
onRequest, onResponse, onRetrynoneTold about every call. They never receive a key, a signature or typed data
loggernoneAny object with debug, info, warn, error. Without one the SDK logs nothing; with one, keys, signatures and typed data are redacted
dangerouslyAllowBrowserfalseLets a secret key run in a browser page

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

OptionWhat it does
rpcUrlsYour 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
getAccessTokenThe wallet session for calls that act for a wallet, such as selling BTC with swap.createOrder and listing a wallet's orders
solanaWeb3The @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, jupiterApiUrlYour 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 429s.

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.

TypeScript Copy
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. Test the rest of your integration: Test your integration.