# OpenAPI document

The Maxy HTTP API describes itself as OpenAPI 3.1 at `GET /openapi.json`. Use it to generate a typed client in your language, or to check your own code against each answer's shape. It needs no key.

## Get it

```sh
curl -s "$BASE/openapi.json" -o maxy-openapi.json
jq '{openapi, title: .info.title, version: .info.version, paths: (.paths | length), webhooks: (.webhooks | keys)}' maxy-openapi.json
```

```json
{
  "openapi": "3.1.0",
  "title": "Maxy API",
  "version": "1.8.0",
  "paths": 61,
  "webhooks": ["order.payment_replaced","order.updated"]
}
```

The document is served from the API itself, so it always matches the routes that answer. It holds:

| Part | What is in it |
| --- | --- |
| `paths` | Every route (65 operations): an `operationId` and `tags` on each, every parameter and body described, and its own answers, errors included. Each error answer lists its codes in `x-error-codes` |
| `tags` | The route groups: Prices and quotes, Orders, Chains and tokens, Webhooks, Keys and account, Sandbox, System and Checkout and feedback |
| `components.schemas` | The shared shapes, referenced from the paths by `$ref`: `ErrorCode`, `TypedData`, `Asset`, `Error`, `Chain`, `Token`, `Pair`, `AddressCheck`, `Health`, `Limits`, `Key`, `Price`, `Quote`, `Signing`, `Status`, `OrderRow` and `OrderEvent`. `ErrorCode` lists every error code |
| `components.securitySchemes` | `apiKey`, the `x-maxy-key` header, and `streamTicket`, the `ticket` query value the two streams take from a browser |
| `webhooks` | `order.payment_replaced` and `order.updated`: the signed events Maxy posts to your endpoint |
| `servers` | The base URL |
| `info` | The title, `version` (`1.8.0`) and the licence (MIT) |

`GET /` lists the same routes in a shorter form, each with whether it takes a key.

## Versions

The version sits in the base URL, `https://openapi.maxy.co/v1`, and routes under it carry none: `$BASE/price`, `$BASE/orders/{id}`. The API is generally available (v1). `info.version` is the document's own version, `1.8.0`: its major is the API's (1, the `/v1` in the URL), its minor goes up when the document gains a route, field, parameter, enum value or error code, and its patch when only text or examples change. Any change to the document raises it, so a client generated from one version matches every answer of that version. The API only gains fields and routes, so ignore any field you do not know. Since general availability, a breaking change comes as `/v2`, announced to every key holder at least 90 days ahead; releases before it are pre-GA ([Stability](https://maxy.co/docs/stability)), and every change is in the [changelog](https://maxy.co/docs/changelog).

## Headers on every answer

| Header | What it says |
| --- | --- |
| `x-request-id` | The id of this call, also `requestId` in an error body. Send your own, 8 to 64 letters, digits, `.`, `_` or `-`, and the answer keeps it |
| `Server-Timing` | `total;dur=<ms>`: how long Maxy took |
| `RateLimit-Limit`, `RateLimit-Remaining`, `RateLimit-Reset` | Your limit a minute, what is left, and seconds until the window has room |
| `Retry-After` | On a `429`: seconds to wait |
| `X-Maxy-Sandbox` | `true` on every answer to a test key |
| `Idempotent-Replayed` | `true` when an `Idempotency-Key` you sent before answered again: see [Order routes](https://maxy.co/docs/order-routes#post-orders) |

A browser can read all of them: the API lists them in `Access-Control-Expose-Headers`.

```sh
curl -s -D - -o /dev/null -H "x-maxy-key: $MAXY_API_KEY" -H "x-request-id: order-1042.try-1" "$BASE/key" \
  | grep -iE '^(x-request-id|server-timing|ratelimit|x-maxy-sandbox)'
```

```text
ratelimit-limit: 120
ratelimit-remaining: 117
ratelimit-reset: 60
server-timing: total;dur=47
x-maxy-sandbox: true
x-request-id: order-1042.try-1
```

Log `x-request-id` with every call, and quote it when you write to Maxy.

## Generate a client

Any OpenAPI 3.1 generator reads the document. Two that run as shown, with a test key in `MAXY_API_KEY`:

**TypeScript**, with `openapi-typescript` and `openapi-fetch` (both MIT). The generator needs TypeScript 5.

```sh
npm install openapi-fetch && npm install -D openapi-typescript typescript@5
npx openapi-typescript "$BASE/openapi.json" -o maxy-api.d.ts
```

```ts
import createClient from 'openapi-fetch';
import type { paths } from './maxy-api.d.ts';

const maxy = createClient<paths>({
  baseUrl: 'https://openapi.maxy.co/v1',
  headers: { 'x-maxy-key': process.env.MAXY_API_KEY! },
});
const { data, error } = await maxy.GET('/price', { params: { query: { from: 'ETH on base', to: 'BTC', amount: '0.01' } } });
console.log(error ?? data?.formatted?.receive); // 0.00027809 BTC
```

**Python**, with `openapi-python-client` (MIT). `--meta none` writes the module alone, next to your code. Each tag is a module and each `operationId` a function in it. The generator skips one route, `GET /system/feed.xml`, whose answer is XML; every other route is generated.

```sh
pip install openapi-python-client httpx attrs python-dateutil
openapi-python-client generate --url "$BASE/openapi.json" --meta none --output-path maxy_api_client
```

```python
import os
from maxy_api_client import AuthenticatedClient
from maxy_api_client.api.prices_and_quotes import get_price

client = AuthenticatedClient(
    base_url="https://openapi.maxy.co/v1",
    token=os.environ["MAXY_API_KEY"], prefix="", auth_header_name="x-maxy-key",
)
price = get_price.sync(client=client, from_="ETH on base", to="BTC", amount="0.01")
print(price.formatted.receive)  # 0.00027808 BTC
```

A generated client gives you types and nothing else. The [TypeScript SDK](https://maxy.co/docs/install-and-signers) also checks what the wallet signs, retries safely and runs whole orders: use it where it fits. Every route, grouped, starts at [API routes](https://maxy.co/docs/api-routes).

---
Source: https://maxy.co/docs/openapi-document (Maxy Docs › API reference › About the API)
