> ## Documentation Index
> Fetch the complete documentation index at: https://sonar-cf3aeac7.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Responses and errors

> The REST success and error envelopes, validation error details, and every error code the API can return.

## Success envelope

Every successful REST response is wrapped in the same envelope. `data` holds the endpoint's payload, which can be an object or an array.

```json theme={null}
{
  "status": "success",
  "data": { "...": "endpoint payload" }
}
```

`POST` endpoints answer with HTTP `200`, not `201`.

> [!WARNING]
>
> **Exception: Pulse views.** [`POST /pulse/views`](https://sonar-cf3aeac7.mintlify.site/pulse/rest-views) and [`POST /pulse/views/pagination`](https://sonar-cf3aeac7.mintlify.site/pulse/rest-views-pagination) return raw JSON with **no** `status`/`data` envelope, for example `{"new":{"data":[...]}}`. Their errors still use the error envelope below. The native [`POST /pulse`](https://sonar-cf3aeac7.mintlify.site/pulse/native-views) endpoint uses the normal envelope.

## Error envelope

Errors return a non-2xx HTTP status and this body:

**status** `string` *required*

Always `"error"`.

**statusCode** `number` *required*

Same value as the HTTP status code.

**code** `string` *required*

Machine-readable error code. One of the values in [Error codes](#error-codes).

**message** `string` *required*

Human-readable description. For validation errors it lists every problem (see below).

**details** `array | object`

Extra information. Present on validation errors (`[{ field, message }]`) and on some `503` responses (a status report). Omitted when there is nothing to add.

```json 404 example theme={null}
{
  "status": "error",
  "statusCode": 404,
  "code": "TOKEN_NOT_FOUND",
  "message": "Token not found"
}
```

Branch on `code`, not on `message`. Messages can change.

## Error codes

The `code` field can hold any of these values:

`INVALID_PARAMETERS`, `INVALID_ADDRESS`, `TOKEN_NOT_FOUND`, `POOL_NOT_FOUND`, `ASSET_NOT_FOUND`, `BAD_REQUEST`, `UNAUTHORIZED`, `FORBIDDEN`, `NOT_FOUND`, `RATE_LIMITED`, `SERVICE_UNAVAILABLE`, `INTERNAL_ERROR`

These are the codes the REST API emits today:

| HTTP | Code | When |
| - | - | - |
| 400 | `INVALID_PARAMETERS` | A query parameter or body failed validation, a chain is unsupported (wallet holdings, Pulse), or a Pulse view is invalid |
| 400 | `INVALID_ADDRESS` | Validation failed and **every** problem is a malformed address |
| 404 | `TOKEN_NOT_FOUND` | The token (or, for `/trades` and `/token/ohlcv`, the token or pool) is not indexed. Messages: `Token not found`, `Token or pool not found`, `Token or asset not found` |
| 404 | `POOL_NOT_FOUND` | `GET /market/details` or `GET /market/ohlcv` for a pool that is not indexed. Message: `Pool not found` |
| 404 | `ASSET_NOT_FOUND` | `/asset/history` or `/asset/ohlcv` for an unknown asset id. Message: `Asset not found` |
| 404 | `NOT_FOUND` | Unknown route |
| 503 | `SERVICE_UNAVAILABLE` | `GET /wallet/holdings` could not read the native balance (`The node is unavailable, try again shortly`), or [`/health/last-swaps`](https://sonar-cf3aeac7.mintlify.site/api-reference/health/get-last-swaps) (host root, not under `/api/v1`) reports stale data (`Swaps are stale`, with the freshness report in `details`) |
| 500 | `INTERNAL_ERROR` | Unexpected server error. Message: `Internal server error` |

> [!NOTE]
>
> `UNAUTHORIZED`, `FORBIDDEN` and `RATE_LIMITED` exist in the enum but are **not emitted** today: the REST API currently has no authentication and no rate limiting. Handle them generically so your client keeps working if they are introduced.

> [!NOTE]
>
> `BAD_REQUEST` is used for other `400` responses that are not parameter validation failures. Any HTTP status without its own code (for example `405`) is returned with code `INTERNAL_ERROR` but keeps its real `statusCode`, so check `statusCode` as well as `code`.

## Validation errors

Query strings and request bodies are validated before anything else runs. A failure returns HTTP `400` with:

* `details`: one `{ field, message }` entry per problem. `field` is the dotted path of the parameter, for example `limit`, `chain` or `0.address` for the first item of a batch body. It is `""` for problems with the whole body.
* `message`: every detail joined with `"; "`, each written as `field: message` (or just `message` when `field` is empty).
* `code`: `INVALID_ADDRESS` only when **every** problem is an address problem. Anything else, including a bad address combined with another bad parameter, gives `INVALID_PARAMETERS`.

### Examples

Bad address only, `GET /token?address=0x123&chain=1`:

```json theme={null}
{"status":"error","statusCode":400,"code":"INVALID_ADDRESS","message":"address: must be a valid token or wallet address","details":[{"field":"address","message":"must be a valid token or wallet address"}]}
```

Bad address and bad chain, `GET /token?address=0x123&chain=abc`:

```json theme={null}
{"status":"error","statusCode":400,"code":"INVALID_PARAMETERS","message":"address: must be a valid token or wallet address; chain: must be a chain id like 1 or evm:1","details":[{"field":"address","message":"must be a valid token or wallet address"},{"field":"chain","message":"must be a chain id like 1 or evm:1"}]}
```

Missing parameters, `GET /token`:

```json theme={null}
{"status":"error","statusCode":400,"code":"INVALID_PARAMETERS","message":"address: Invalid input: expected string, received undefined; chain: Invalid input: expected string, received undefined","details":[{"field":"address","message":"Invalid input: expected string, received undefined"},{"field":"chain","message":"Invalid input: expected string, received undefined"}]}
```

Limit too big and reversed time range, `GET /trades?...&limit=500&from=10&to=5`:

```json theme={null}
{"status":"error","statusCode":400,"code":"INVALID_PARAMETERS","message":"limit: Too big: expected number to be <=100; from: from must be before to","details":[{"field":"limit","message":"Too big: expected number to be <=100"},{"field":"from","message":"from must be before to"}]}
```

Malformed cursor, `GET /trades?...&cursor=zzz`:

```json theme={null}
{"status":"error","statusCode":400,"code":"INVALID_PARAMETERS","message":"cursor: invalid cursor","details":[{"field":"cursor","message":"invalid cursor"}]}
```

Empty batch body, `POST /market/details` with `[]`:

```json theme={null}
{"status":"error","statusCode":400,"code":"INVALID_PARAMETERS","message":"Too small: expected array to have >=1 items","details":[{"field":"","message":"Too small: expected array to have >=1 items"}]}
```

Missing search input, `GET /search`:

```json theme={null}
{"status":"error","statusCode":400,"code":"INVALID_PARAMETERS","message":"input: input is required unless type is pools or all","details":[{"field":"input","message":"input is required unless type is pools or all"}]}
```

Unsupported chain on `GET /wallet/holdings?chain=137&...` (no `details`):

```json theme={null}
{"status":"error","statusCode":400,"code":"INVALID_PARAMETERS","message":"Unsupported chain: evm:137"}
```

> [!NOTE]
>
> Messages written by ChainQuery (such as `must be a chain id like 1 or evm:1` or `from must be before to`) are stable. Generic messages such as `Invalid input: expected string, received undefined` or `Too big: expected number to be <=100` come from the validation library's defaults, and their wording may change. Match on `code` and `field`, not on the message text.

### Pulse views use string details

On `POST /pulse/views` and `POST /pulse/views/pagination`, errors found while interpreting the views (unsupported filters, unknown chains, duplicate names) return `details` as an **array of strings** instead of `{ field, message }` objects:

```json theme={null}
{
  "status": "error",
  "statusCode": 400,
  "code": "INVALID_PARAMETERS",
  "message": "views.0.filters.organic_volume_1h: not supported yet",
  "details": ["views.0.filters.organic_volume_1h: not supported yet"]
}
```

Each string is `path: message`. Handle both shapes if you call several endpoints. See [Pulse REST views](https://sonar-cf3aeac7.mintlify.site/pulse/rest-views.md).

## WebSocket errors

The WebSocket surfaces do not use HTTP status codes. They send `error` messages on the open connection and use WebSocket close codes for connection-level problems:

* Channel WebSocket (`/v1/ws`): [Limits and errors](https://sonar-cf3aeac7.mintlify.site/websocket/limits-and-errors.md)
* Pulse stream (`/v1/ws/pulse`): [Pulse stream](https://sonar-cf3aeac7.mintlify.site/pulse/stream.md)
* Multi-events stream (`/streams/v1/ws`): [Limits and cost](https://sonar-cf3aeac7.mintlify.site/streams/limits-and-cost.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.