# Speed and latency

Partners can build on Maxy's API with confidence. The HTTP API is stable: it only gains fields and routes, and any breaking change is announced at least 90 days ahead. Quotes answer with a median under a second, 95th percentile 2.5 seconds, and stay valid for 60 seconds, long enough for a user to review and sign. Every response carries a timing header and a request id, so partners can measure Maxy's latency for themselves. A sandbox can force every failure scenario, so partners can test each outcome before launch, and a nightly end-to-end run checks every failure branch. Uptime and response times: [Stability](https://maxy.co/docs/stability).

How to measure Maxy's response times and keep your screens fast: timing headers, a price stream, many quotes in one call, and when to poll. It is for teams building a quote screen, a price list or a router.

## Measure every answer

Every answer carries `Server-Timing: total;dur=…`, the milliseconds Maxy spent on it, and an `x-request-id`. A browser can read both. Log them, and quote the request id to Maxy when something is slow. The samples use the setup from [Get a quote](https://maxy.co/docs/buy-btc#get-a-quote).

```sh
curl -s -o /dev/null -D - -H "x-maxy-key: $MAXY_API_KEY" "$BASE/price?from=ETH%20on%20base&to=BTC&amount=0.01" \
  | grep -i -E '^(server-timing|x-request-id):'
```

```ts
const res = await fetch(`${BASE}/price?from=ETH%20on%20base&to=BTC&amount=0.01`, { headers: { 'x-maxy-key': KEY } });
console.log(res.headers.get('server-timing'), res.headers.get('x-request-id')); // total;dur=… <uuid>
```

Measured response times, uptime and the target, in one table: [Stability](https://maxy.co/docs/stability#how-it-has-run).

The SDK adds the time your side saw: each answer's `meta` has `latencyMs` for the attempt that answered, `requestId`, and how many `retries` came before it, and `onResponse` hears about every attempt ([Configure the SDK](https://maxy.co/docs/configure-the-sdk)). [Status](https://maxy.co/status) shows the current time for prices and quotes.

## Prices: ask freely

`GET /price` reserves nothing, so call it while the user types. The same question within 3 seconds is one read of the solver, and price reads have a rate limit of their own, ten times your key's, counted apart from every other call.

For a price that stays current on screen, open `GET /prices/stream` instead of polling. It sends the same answer as `GET /price` every 5 seconds or more (`intervalSeconds`). A connection counts as one request and lasts at most 2 minutes; its last event says to reconnect.

```sh
curl -sN -H "x-maxy-key: $MAXY_API_KEY" "$BASE/prices/stream?from=ETH%20on%20base&to=BTC&amount=0.01"
```

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

const maxy = createMaxyClient(); // reads MAXY_API_KEY
const stop = maxy.prices.stream({ from: 'ETH on base', to: 'BTC', amount: '0.01' }, (price) => console.log(price.formatted?.receive));
setTimeout(stop, 30_000); // reconnects by itself, and polls if streams are blocked
```

A browser's `EventSource` cannot send a key, so a page first asks `POST /prices/stream-ticket` with its publishable key and opens the stream with the ticket. The SDK does this for you.

## Many quotes in one call

`POST /quotes/batch` takes up to 20 requests and answers each with its own `status`, `requestId`, and `quote` or `error`. One failing does not fail the rest. A request naming both addresses is a quote; the others are prices.

```sh
curl -s -X POST "$BASE/quotes/batch" -H "x-maxy-key: $MAXY_API_KEY" -H "content-type: application/json" \
  -d '{"requests":[{"from":"ETH on base","to":"BTC","amount":"0.01"},{"from":"SOL","to":"BTC","amount":"1"},{"from":"AVAX","to":"BTC","amount":"5"}]}' \
  | jq -c '.results[] | {index, status, receive: .quote.formatted.receive}'
```

## Quotes: ask at the click

A quote is valid for 60 seconds: that is how long it can be used, not how long it takes to arrive. Ask for it when the user moves to confirm, count down from `expiresAt` by the clock in Maxy's `Date` header, and renew about 5 seconds before it closes. `quotes.msUntilExpiry` and `quotes.refresh` in the SDK do both: [Request quotes](https://maxy.co/docs/request-quotes).

With the full SDK, `swap.prepareOrder` does every read an ETH, BNB or AVAX order needs while the user reviews the quote, without signing anything. Confirming then only signs, sends and tells the solver.

## Tracking: stream, then webhooks

| Need | Use |
| --- | --- |
| The user is watching | `GET /orders/{id}/events/stream`, or poll `GET /status` every 2 seconds. `orders.watch` in the SDK streams, and falls back to polling from 1 second, backing off to 5 |
| Your records | [Webhooks](https://maxy.co/docs/webhooks): one signed event per change, also when nobody is watching |
| The list of pairs | `GET /pairs`, built fresh on every request in about 40 ms. The response may be cached for up to 60 seconds (`private, max-age=60`); the SDK re-reads it every 60 seconds. Read it again whenever you need the latest list |

The user does not wait for Bitcoin confirmations on a buy: the order reads `completed` as soon as the BTC payment exists. What each step waits for: [How a swap works](https://maxy.co/docs/how-a-swap-works).

## Stay inside the limits

The SDK reads `RateLimit-Remaining` from each answer, and a burst waits for the minute to turn over instead of collecting `429`s. Identical reads in flight share one request. Over HTTP, honour `Retry-After`. The limits: [Keys and limits](https://maxy.co/docs/keys-and-limits#rate-limits).

---
Source: https://maxy.co/docs/speed-and-latency (Maxy Docs › Maxy architecture › Performance)
