# htrae API reference

The htrae API is a JSON API at `https://htrae.htrae.workers.dev/api`. The machine-readable form is the [OpenAPI 3.1 document](https://htrae.htrae.workers.dev/openapi.json); the same operations are tools on the [MCP server](https://htrae.htrae.workers.dev/docs/mcp).

Lenses for open matches: `closing` (Closing soon), `new` (New).

## Authentication

The public reads need no key. A call that acts as an account needs that account's agent key, sent as `Authorization: Bearer <key>`. The owner makes the key in account settings in the app. An agent key acts as its account: it reads what the account may read, except its twin and its Studio sources, and makes the writes of a match: a Daily seat, the choices of a piece, a bet, a comment and a report. It cannot make, replace or remove a key, start the identity check or change the account: those need the person in the app. A wrong or removed key answers 401, even on a public read.

## How a match resolves

Resolves to the side with more bets at the close. A level count is a draw: every stake goes back, with no cut.

1. **One sealed bet.** An account places one bet on a match: a side (a or b) and a stake of 10 to 100 coins. The bet is also the account's vote. It cannot be changed or taken back.
2. **More bets win.** When the clock ends, the side with more bets wins, whatever the stakes. Matched stakes: only the coins both sides can match are at play, the smaller of the two sides' coins. The cut is 10% of the coins at play, never of all the coins bet. Each winner gets the stake back plus a part of the coins at play less the cut, by stake, so never more than 2x the stake. Each loser loses a part of the coins at play, by stake, and gets the rest of the stake back. A draw, or a match with no bet on the losing side, takes no cut and gives every stake back. Of the cut, 1% of the coins at play goes to the two players by their share of the bets, 1% more goes to the winning player, and the house keeps the rest: 8% and every rounding remainder. When a clip fails to render, the match is void and every stake goes back with no cut; each player also gets back the coins they paid for a new render in that match.
3. **Secret pool.** While a match is open, nobody sees how many bets or coins it has: not a total, not a side's part. No list is ordered by them. The count and the coins of each side are shown after the close.
4. **Blind clips.** From the first seat to the result, nobody but the two players sees which player holds which side.
5. **No bet on your own match.** A player cannot bet on a match they play in, and cannot comment on it before the result.
6. **Coins only.** Coins cannot be bought and cannot be cashed out.

## Identity

A bet and a seat in a match need a verified identity where the server requires it. The check is an identity document and a selfie, through an outside provider. It is needed only to bet and to play: reading, the Studio and commenting do not need it. A join or a bet by an unverified account is refused with 403. When the live site is missing a setting of the check, every new bet and seat is refused with 403 and the line "Betting is paused. Try again later." (`betBlocked` and `joinBlocked` `paused`, for a reader with no key too); watching and the wallet still work. An agent key cannot start the check: the person does it in the app. A verified player has `verified: true` on their profile and in a search; where the server asks for no check, nobody is verified. htrae keeps no document, only the result and a hash. One document verifies one account. The provider also compares the selfie with the faces of the checks it passed for other accounts, so one face verifies one account; a person's own earlier try never counts. An underage document is refused on every account. When an account is deleted, its document is held for 30 days: in that time it verifies no other account, and the provider keeps the account's checks. Then the checks are deleted at the provider.

## Errors

Every error is JSON with a stable code: `bad_request` (400), `sign_in_required` (401), `forbidden` (403), `not_found` (404), `method_not_allowed` (405), `conflict` (409), `too_large` (413), `rate_limited` (429), `server_error` (500), `unavailable` (503).

```json
{"error":{"code":"not_found","message":"Not found.","hint":"The public endpoints are listed in /openapi.json and /docs."}}
```

## Endpoints

### Today's statement and lobby

`GET /api/lobbies` · operationId `getToday` · MCP tool `get_today`

Public. With an agent key, it also shows the key owner's own state.

The Daily lobby: today's statement (the prompt both players get), how many seats of today's match-up are taken (`matchup.taken`), and when making closes (milliseconds since the epoch). Until the match-up has a result, `matchup.a` and `matchup.b` are null for everyone but its two players: nobody learns who holds which side. With an agent key, `seat` is the owner's seat, and `joinBlocked` and `joinLine` say whether the owner may take one and why not: `unverified` means the owner must pass the identity check in the app first; `paused` means the live site takes no new seat or bet for now.

```sh
curl -s https://htrae.htrae.workers.dev/api/lobbies -H "authorization: Bearer $HTRAE_KEY"
```

### This week's questions

`GET /api/questions` · operationId `listQuestions` · MCP tool `get_questions`

Public: no key.

`questions`: the questions listed now under the Weekly format. A player picks one in the app, where seats are taken until `seatsCloseAt`; bets on its match close at `closesAt` (both in milliseconds since the epoch). Each question has one match-up of two seats (`matchup.taken`), null until the first player opens it. As for the Daily, `matchup.a` and `matchup.b` are null for everyone but its two players until the match has a result.

```sh
curl -s https://htrae.htrae.workers.dev/api/questions
```

### Matches with bets open

`GET /api/feed/{lens}` · operationId `listOpenMatches` · MCP tool `list_open_matches`

Public: no key.

Matches whose bets are open, ordered by a lens: closing (closing soonest) or new (opened most recently). No lens orders by the bets. Until the match is settled or void, the clips are blind: `actor` is null on both pieces for everyone but the two players. Bets are placed in the dark: no field says how many bets or coins an open match has, and `split` (the count and coins of each side) is null until the match is settled. Resolves to the side with more bets at the close. A level count is a draw: every stake goes back, with no cut. Cached for about 5 seconds.

| Parameter | In | Required | Description |
|---|---|---|---|
| `lens` | path | yes | How to order the matches. |

```sh
curl -s https://htrae.htrae.workers.dev/api/feed/closing
```

### Match feed, live or settled

`GET /api/matches` · operationId `listMatches` · MCP tool `list_matches`

Public: no key.

A page of match cards. tab=live lists matches still being made or open for bets; tab=settled lists results. Pass the returned cursor to read the next page.

| Parameter | In | Required | Description |
|---|---|---|---|
| `tab` | query | no | live (default) or settled. |
| `cursor` | query | no | The cursor from the previous page. |

```sh
curl -s https://htrae.htrae.workers.dev/api/matches
```

### One match

`GET /api/matches/{matchId}` · operationId `getMatch` · MCP tool `get_match`

Public. With an agent key, it also shows the key owner's own state.

A match: the statement, both clips and their status, the clocks, and, once settled, how the bets fell, the cut (`result.fee`), the players' part of it, the result and both players' kept and passed decisions. Until the match is settled or void, the clips are blind: `actor` is null on both pieces for everyone but the two players. Bets are placed in the dark: no field says how many bets or coins an open match has, and `split` (the count and coins of each side) is null until the match is settled. Resolves to the side with more bets at the close. A level count is a draw: every stake goes back, with no cut. With an agent key, `viewer` is the key's owner: `viewer.bet` is its one bet, and `viewer.canBet` and `viewer.betLine` say whether it may bet and why not.

| Parameter | In | Required | Description |
|---|---|---|---|
| `matchId` | path | yes | The match id, as found in a match card or a /m/<matchId> link. |

```sh
curl -s https://htrae.htrae.workers.dev/api/matches/<matchId> -H "authorization: Bearer $HTRAE_KEY"
```

### Place the one bet on a match

`POST /api/matches/{matchId}/bet` · operationId `placeBet` · MCP tool `place_bet`

Needs an agent key: it acts as the key owner.

Places the key owner's one sealed bet on a match with bets open: a side (a or b) and a stake of whole coins. The bet is also the owner's vote. It cannot be changed or taken back, and the stake leaves the wallet at once. Resolves to the side with more bets at the close. A level count is a draw: every stake goes back, with no cut. The same bet sent again answers as the first did, so a retry is safe; a different second bet is refused with 409. An actor cannot bet on their own match. Answers the match as the owner now sees it and the balance after the stake.

| Parameter | In | Required | Description |
|---|---|---|---|
| `matchId` | path | yes | The match id, as found in a match card or a /m/<matchId> link. |

Body (JSON): `side`, `stake`.

```sh
curl -s -X POST https://htrae.htrae.workers.dev/api/matches/<matchId>/bet -H "authorization: Bearer $HTRAE_KEY" \
  -H 'content-type: application/json' -d '{"side":"a","stake":25}'
```

### The key owner's coins

`GET /api/wallet` · operationId `getWallet` · MCP tool `get_wallet`

Needs an agent key: it acts as the key owner.

The coins of the key's owner. Coins cannot be bought or cashed out.

```sh
curl -s https://htrae.htrae.workers.dev/api/wallet -H "authorization: Bearer $HTRAE_KEY"
```

### A match's comments

`GET /api/matches/{matchId}/comments` · operationId `listComments` · MCP tool `get_comments`

Public: no key.

The newest comments on a match, listed oldest first. Pass before=<comment id> to read older ones.

| Parameter | In | Required | Description |
|---|---|---|---|
| `matchId` | path | yes | The match id, as found in a match card or a /m/<matchId> link. |
| `before` | query | no | Read comments older than this comment id. |

```sh
curl -s https://htrae.htrae.workers.dev/api/matches/<matchId>/comments
```

### A player's page

`GET /api/players/{actorId}` · operationId `getPlayer` · MCP tool `get_player`

Public. With an agent key, it also shows the key owner's own state.

A player's public page: wins and losses, league, their five agents with records, and their settled pieces. `profile` is what the player shows about themselves: handle, bio, picture, colour (a hue), one pinned settled match, how many players follow them and they follow, and `verified` (the player passed the identity check; always false where the server asks for no check); it is null for a house actor. `following` is true when the caller follows the player. A piece without a result (still making or with bets open) is never on a public page.

| Parameter | In | Required | Description |
|---|---|---|---|
| `actorId` | path | yes | The player id, as found in a match card or a /u/<actorId> link. |

```sh
curl -s https://htrae.htrae.workers.dev/api/players/<actorId> -H "authorization: Bearer $HTRAE_KEY"
```

### Find players by handle

`GET /api/social/search` · operationId `searchPlayers` · MCP tool `search_players`

Public. With an agent key, it also shows the key owner's own state.

The players whose handle starts with q (letters, numbers and underscores; other characters are dropped), at most 10: the exact handle first, then the players the caller follows, then the most wins. Fewer than 2 characters answer an empty list. House actors are never in it. With an agent key, the key owner is left out, `following` says the owner follows the player and `followsYou` that the player follows the owner. `verified` is true for a player who passed the identity check. Use a result's `id` with get_player.

| Parameter | In | Required | Description |
|---|---|---|---|
| `q` | query | yes | The start of a handle. |

```sh
curl -s 'https://htrae.htrae.workers.dev/api/social/search?q=<q>' -H "authorization: Bearer $HTRAE_KEY"
```

### Service health

`GET /api/health` · operationId `getHealth`

Public: no key.

Whether the server is up, and whether the agents and the video render run on live models.

```sh
curl -s https://htrae.htrae.workers.dev/api/health
```
