# Messages

> Every message on the WebSocket, and the unsubscribe and schema methods.

This page is part of the Intear API docs. The Intear API is at `https://api.intea.rs` and `wss://api.intea.rs/ws`, with no API key. https://docs.intear.tech/api/llms-full.txt has all of its pages in one file, and https://docs.intear.tech/llms.txt lists every page of the Intear docs.

See [Connecting](https://docs.intear.tech/api/guides/connecting.md) for how they fit together.

## From the client

```json
{ "id": 1, "method": "tokens.get", "params": { ... } }
```

| Key | Description |
| --- | --- |
| `id` | A number or a string. Names the reply, and the subscription if the method makes one |
| `method` | The method to call |
| `params` | The method's params. Can be left out when there are none |

## From the server

Every message also has `credits_used`, see [Credits](https://docs.intear.tech/api/reference/limits.md#credits).

| Message | When |
| --- | --- |
| `{ "hello": { "version": 2, "height", "timestamp_millis", "limits" } }` | First, once |
| `{ "id": 1, "result": { ... } }` | The reply to request `1` |
| `{ "id": 1, "error": { "code", "message" } }` | Request `1` failed. A subscription it would have made doesn't exist |
| `{ "sub": 1, "height", "timestamp_millis", ... }` | A push of the subscription request `1` made |
| `{ "sub": 1, "end": { "code", "message" } }` | The server ended subscription `1` |
| `{ "idle": { "height", "timestamp_millis" } }` | After 15 seconds with nothing else sent |

## Closing codes

| Code | Why |
| --- | --- |
| `1008` | The client sent a binary message, or one that isn't a JSON object with an `id` and a `method` |
| `1006` | The connection dropped without a close frame, as it does when the client sends a message too large |

## `unsubscribe`

Ends a subscription, so its `id` can be used again.

| Param | Description |
| --- | --- |
| `sub` | **Required.** The subscription's `id` |

The result is `{}`.

## `schema`

Takes no params. HTTP: `/schema`. The result describes the whole API, for checking a client against and generating types from:

- `version`: the protocol version, as in `hello`;
- `token_fields`: every token field with its type and `kind`, and whether it works in `where`, `sort` and `min_change`;
- `windows`, `thresholds`, `intervals_ms` and `limits`;
- `trade_fields`, `transfer_fields` and `transaction_fields`;
- `methods`: every method's params, and its HTTP path if it has one.
