# Conventions (v2)

> Base URL, amounts, addresses, request ids and error bodies, shared by every endpoint.

> API v2 is deprecated. It stays supported, but new integrations should use the [Khalani API](/) (v3). See [Migrate to v3](/v2/migrate/).

## Base URL and paths

Every endpoint is under `https://api.hyperstream.dev/v2/`. The rest of these docs write paths as `/v2/…`.

## Requests and responses

- Bodies are JSON. Send `Content-Type: application/json` on `POST` requests.
- Quote shortly before you build. A quote's `build` expires at `build.terms.expiresAt`.
- Every response carries an `x-request-id` header (a UUID). Log it, and include it with the `orderId` and the time of the call when you contact Khalani about a request.

## Amounts

Every amount is a decimal string of integer base units. On a 6-decimal token, `"10000000"` is 10. Request amounts must match `^[1-9]\d*$`.

An amount is in the base units of one token on one chain. The same token can have different decimals on different chains, so read `decimals` from `GET /v2/params`.

| Fields | Denominated in |
|---|---|
| `spend.amount`, `amount`, `srcAmount`, `minSrcAmount`, `maxSrcAmount`, `srcAmountSpoke`, `protocolFee`, `fullFee`, `refundSource`, `accruedFee` | The **source** token |
| `receive.amount`, `receive.minAmount`, `minOutcome`, `settledOutcome` | The **destination** token |
| `depositFee`, `withdrawFee` (in `GET /v2/params`) | The listed token itself. Both are relayer gas costs |

A few fields are JSON numbers: chain ids, `decimals`, `seq`, `operatorBps`, `commissionBps`, `orderTtl`, and response timestamps (`at`, `deadline`). `build.terms.expiresAt` in a quote is a string of Unix seconds.

## Addresses

- Tokens are identified by chain id and contract address.
- EVM addresses come back checksummed from `/v2/params` and `/v2/quote`, and lowercase in orders. Compare them case-insensitively.
- Non-EVM addresses come back in the chain's native form. On TRON that is base58, and the API accepts base58 or hex41.
- `depositor` is an EVM address. Send it lowercase or EIP-55 checksummed. An order from a non-EVM chain has no depositor: leave it out of the build, and the order shows `depositor: null`.

## Error bodies

Errors come in four JSON shapes. Only the first has an `error` key, so log `error ?? message`.

| Source | Body |
|---|---|
| The route itself (most `4xx`/`5xx`) | `{ "error": string, "detail"?: object }` |
| Request validation | `{ "message": "Validation failed", "name": "ValidationException", "details": [{ "field", "message", "code" }] }` |
| Malformed JSON, maintenance, unhandled `500` | `{ "message": string, "name": string }` |
| Rate limit | `{ "errorCode": "RATE_LIMITED", "message": string }` |

[Errors and retries](/v2/guides/errors/) covers what each status means and whether to retry.
