> For the complete documentation index, see [llms.txt](https://docs.pretoke.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pretoke.xyz/api-reference/overview.md).

# Overview & Authentication

This reference documents the platform's public HTTP API and WebSocket API. It's aimed at developers building bots, dashboards, or third-party integrations.

## Base URL

All REST endpoints are served under a single public gateway, prefixed with `/api/v1`:

```
https://predict.pretoke.xyz/api/v1
```

{% hint style="info" %}
There is no separate host per feature — every endpoint documented here (auth, markets, trading, portfolio, settlement, notifications) lives behind this one gateway. Internal services are **not** reachable directly; the gateway is the only supported entry point.
{% endhint %}

A health check endpoint is available at the root level (no prefix):

```
GET /health   →  200 { "status": "ok" }
```

## Response envelope

Every successful response is wrapped in a consistent envelope:

```json
{
  "data": { /* the actual payload */ },
  "requestId": "b3f1c2a0-...",
  "pagination": {
    "total": 128,
    "page": 1,
    "pageSize": 20,
    "hasNext": true
  }
}
```

* `requestId` — a unique ID for this request/response, useful for support requests and debugging.
* `pagination` — present only on paginated list endpoints.
* Field names in response bodies are always **camelCase**.

## Error format

```json
{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "quantity must be greater than 0",
    "fields": [{ "field": "quantity", "rule": "positive" }]
  },
  "requestId": "b3f1c2a0-..."
}
```

See [Errors & Rate Limits](/api-reference/errors-and-rate-limits.md) for the full list of error codes and HTTP statuses.

## Authentication

Almost every endpoint other than public market/event reads and the auth endpoints themselves requires a **Bearer token**:

```
Authorization: Bearer <accessToken>
```

You obtain this token via the [Auth API](/api-reference/auth.md) — the platform uses **TON Connect wallet-based login**, not passwords or API keys. See [Wallet Login Explained](/how-it-works/wallet-login-explained.md) for the full mechanics.

Tokens are signed **JWTs**, valid for 24 hours, containing your wallet address and internal user ID.

### Public endpoints (no auth required)

* `POST /auth/connect`, `POST /auth/refresh`
* `GET /events`, `GET /events/search`, `GET /events/:id`
* `GET /markets/:id`, `GET /markets/:id/orderbook`, `GET /markets/:id/price-history`

Everything else requires a valid Bearer token.

## Rate limits

| Category  | Limit              | Applies to                                                                                          |
| --------- | ------------------ | --------------------------------------------------------------------------------------------------- |
| **Read**  | 100 requests / 60s | Most GET endpoints                                                                                  |
| **Trade** | 10 requests / 60s  | `POST /orders`, `POST /trade/amm`, `POST /trade/market`, `POST /withdraw`, `POST /redeem/:marketId` |

Every response includes rate-limit headers:

```
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
```

Exceeding the limit returns `429 Too Many Requests` with a `Retry-After` header (seconds until you can retry).

## Micro-units

{% hint style="warning" %}
Trade quantities are expressed as integers in **micro-units** (`quantity × 1,000,000`) rather than decimals, to avoid floating-point rounding issues. For example, "50 shares" is sent as `50000000`. Prices, by contrast, are plain decimal strings/numbers between `"0.01"` and `"0.99"`.
{% endhint %}

## Quick start example

{% tabs %}
{% tab title="cURL" %}

```bash
# Get all open events
curl -X GET "https://predict.pretoke.xyz/api/v1/events?category=all&page=1" \
  -H "Content-Type: application/json"
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
const response = await fetch('https://predict.pretoke.xyz/api/v1/events?category=all&page=1', {
  headers: { 'Content-Type': 'application/json' }
});
const { data, pagination } = await response.json();
console.log(data); // EventItem[]
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

response = requests.get(
    "https://predict.pretoke.xyz/api/v1/events",
    params={"category": "all", "page": 1}
)
result = response.json()
print(result["data"])  # List of EventItem
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
const axios = require('axios');

const { data: result } = await axios.get('https://predict.pretoke.xyz/api/v1/events', {
  params: { category: 'all', page: 1 }
});
console.log(result.data); // EventItem[]
```

{% endtab %}
{% endtabs %}

Continue to [Auth](/api-reference/auth.md) →


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.pretoke.xyz/api-reference/overview.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
