# Sulkyland API v1 — guide for AI assistants and scripts

Sulkyland is an online horse-racing management game (flat, hurdle and trot). This read-only API
returns game data as JSON (or CSV for lists). It is **navigable**: every response is short and
contains the URLs of related data. To dig deeper, follow the URLs — you never need to build
them yourself.

Base URL: `https://www.sulkyland.com/api/v1`
This guide: `https://www.sulkyland.com/api/v1/help` (no key needed, not counted in the quota).

## Read this first

- **Age: one real month = one game year.** A horse born 14 real months ago is 14 years old in the
  game. The `age` field is always this game age. Never recompute an age from a birth date with
  the real calendar. In a **race**, a runner's `age` is its age **on the race day**.
- **Identify horses by `code`, never by name.** Players rename their horses at any time.
- **Follow the `url` and `next` fields as they are.** They already carry the key when needed.
- **Worlds**: the game has three separate worlds, `almina`, `bezir` and `chorus`. Horses and races
  belong to one world (it is in the URL). Members and clans are shared by all three.
- **Money** is in SLK (the game currency). `earnings.free` and `earnings.extended` are two
  separate counters used by race conditions.
- **Times** are numbers in seconds (`timeSeconds`), dates are ISO 8601 with the Paris offset.
- No translated text: codes only (see "Codes"). Only names typed by players (horses, races,
  member names) are returned as they are, emojis included.

## Keys

| | Quota key | Private key |
|---|---|---|
| Gives access to | all **public** data | the player's **own private** data (full stable) |
| In the URL | `key=...` | `privatekey=...` |
| As a header | `X-Api-Key` | `X-Api-Private-Key` |

The player creates both keys on the game page "Search a record" (`/private/chercher`). The API is
reserved for subscribers and competition managers. Never send the private key anywhere else than
to this API.

## Quotas

A monthly number of calls, reset on the 1st of each month, plus a per-minute limit. Every
response carries `X-RateLimit-Limit`, `X-RateLimit-Remaining` and `X-RateLimit-Reset`. When a
limit is reached: HTTP 429 with a `Retry-After` header. Save calls: a CSV list returns the whole
list in **one** call.

## Lists and pagination

JSON lists return at most 100 items per page, in a common envelope:

```json
{ "items": [ ... ], "page": 1, "pageSize": 100, "total": 623,
  "next": "https://www.sulkyland.com/api/v1/chorus/races?organizer=905013&page=2&key=..." }
```

Follow `next` until it is `null`. Add `format=csv` to any list to get the whole list at once
(semicolon separator, UTF-8 with BOM, headers identical to the JSON field names; nested objects
are flattened). The last CSV column `url` is the address of each item.

## Errors

Body: `{ "error": "<code>", "message": "<text>", "help": "<this guide>" }`

| HTTP | `error` | Meaning |
|---|---|---|
| 400 | `bad_request` | invalid parameter (unknown world, bad date or page) |
| 401 | `key_required` / `key_invalid` | quota key missing or unknown |
| 403 | `subscription_required` | the key owner has no subscription |
| 403 | `private_key_required` / `private_key_invalid` | private route without a valid private key |
| 404 | `not_found` | unknown code, retired horse, or race older than 60 days |
| 429 | `quota_exceeded` / `rate_limited` | monthly quota or per-minute limit reached |

## Routes

| Route | Returns | List |
|---|---|---|
| `GET https://www.sulkyland.com/api/v1/{world}/horses/{code}` | a horse, its parents, people and links | |
| `GET https://www.sulkyland.com/api/v1/{world}/horses/{code}/children` | its direct offspring (active horses) | yes |
| `GET https://www.sulkyland.com/api/v1/{world}/horses/{code}/races` | its race record | yes |
| `GET https://www.sulkyland.com/api/v1/{world}/races/{code}` | a race, its conditions, runners and result | |
| `GET https://www.sulkyland.com/api/v1/{world}/races?organizer={code}&from=yyyy-mm-dd&to=yyyy-mm-dd` | races organized by a member | yes |
| `GET https://www.sulkyland.com/api/v1/members/{code}` | a member, its clan and the URL of its horses in each world | |
| `GET https://www.sulkyland.com/api/v1/{world}/members/{code}/horses` | horses owned by a member (public data) | yes |
| `GET https://www.sulkyland.com/api/v1/clans/{code}` | a clan and its members | |
| `GET https://www.sulkyland.com/api/v1/{world}/me/stable` | **private**: the key owner's full stable | yes |

### References

A link to another resource is always `{ "code", "name", "url" }`. A horse that has retired is
shown as `{ "code", "name", "retired": true, "url": null }`: it can no longer be opened. Member 1,
"webmaster", is the game itself (default jockey, organizer of generated races): it has a name but
`"url": null`.

### Horse — `{world}/horses/{code}`

Only active horses (born and not retired); otherwise 404.
`code`, `name`, `world`, `specialty`, `sex`, `birth`, `age`, `retirement` (planned date),
`father`, `mother` (references, `null` for a horse created by the game), `owner` (`null` for a
clan horse), `clan` (for a clan horse), `trainer`, `jockey`, `breeder`,
`earnings { free, extended }`, `score`, `handicapScore`, `links { children, races }`.

### Offspring — `{world}/horses/{code}/children`

Sorted by birth. `code`, `name`, `sex`, `specialty`, `birth`, `fatherCode`, `motherCode`, `url`.

### Race record — `{world}/horses/{code}/races`

Most recent first. `raceCode`, `raceName`, `date`, `specialty`, `distance`, `ground`, `class`,
`runners`, `place`, `timeSeconds`, `reductionSeconds` (`null` when no time), `handicap`,
`earnings`, `entryFee`. The record keeps races older than 60 days, whose `raceCode` then answers
404 on the race route.

### Race — `{world}/races/{code}`

`code`, `name`, `world`, `date`, `specialty`, `distance`, `class`, `status`, `organizer`,
`racecourse`, `entries`, `minimumEntries`, `entryFee`, `conditions`, `runners[]`.

`conditions` — who may enter:
`ageMin`, `ageMax`, `sex` (`null` = all, `female`, `no_gelding`, `male` = stallions only,
`gelding`), `earningsType` (`free` or `extended`: which earnings counter is checked),
`earningsMin`, `earningsMax`, `scoreMin`, `scoreMax`, `maxPerOwner` (horses per owner; the game
allows one more during the last hour before entries close), `start` (starting order:
`earnings`, `random`, `obedience`, `handicap`), `claiming` (claiming race: horses can be bought
after it), `smallStables` (reserved to small stables), `reserved` (reserved to a list of
players).

`runners[]` — in finishing order once the result is published, otherwise by number:
`number` (`null` before the draw), `horse` (`{ code, name, retired, url }`), `sex`, `age` (on
the race day; `null` for a horse retired since), `owner` (the owner **when the horse was
entered**), `trainer`, `jockey`, `handicap` (`null` before the draw), and once the race is
`finished`: `place`, `timeSeconds`, `incident`.

With `format=csv`: one line per runner.

Races are kept **60 days**, then answer 404.

### Races of an organizer — `{world}/races?organizer={code}&from=&to=`

Oldest first. `organizer` is required; `from` and `to` are dates (`to` included); without them,
everything still kept (60 days). Items: `code`, `name`, `date`, `specialty`, `distance`, `class`,
`status`, `entries`, `conditions`, `url`.

### Member — `members/{code}`

`code`, `name`, `clan` (reference), `worlds[]`: `{ world, racecourse, horses }` for each world
where the member plays (`horses` is the URL of the list of its horses).

### Horses of a member — `{world}/members/{code}/horses`

Active horses owned by the member. `code`, `name`, `specialty`, `sex`, `birth`, `age`,
`fatherCode`, `motherCode`, `earnings { free, extended }`, `score`, `handicapScore`, `url`.

### Clan — `clans/{code}`

`code`, `name`, `motto`, `website`, `memberCount`, `members[]`: `{ code, name, owner, url }`
(`owner` = the clan leader).

### Private stable — `{world}/me/stable?privatekey=...`

The key owner's whole stable, **unborn foals included**. `code`, `name`, `specialty`, `birth`,
`age`, `born` (`false` for an unborn foal), `sex`, `retirement`, `fatherCode`, `fatherName`,
`motherCode`, `motherName`, `trainer`, `jockey`, `breeder` (member names), `earnings`, `score`,
`handicapScore`, `folders { owner, trainer, jockey, breeding }` (the player's own folders),
`genetics { current, birth }` with `speed`, `resistance`, `suppleness`, `obedience` (and
`constitution` in chorus) — `null` for an unborn foal — and `url` (`null` for an unborn foal).
In CSV, birth values have the suffix `Birth` (`speedBirth`…).

`fatherCode` and `motherCode` point to other lines of the same file when the parent belongs to
the player: to compare a sire with its offspring, match `fatherCode` with `code`. No extra call
is needed.

## Codes

| Field | Values |
|---|---|
| `world` | `almina`, `bezir`, `chorus` |
| `specialty` | `flat`, `hurdle`, `trot` |
| `sex` (horse) | `male`, `female`, `gelding` |
| `class` (race) | `regulated`, `free`, `competition`, `cup`, `clan` |
| `status` (race) | `entries` (open), `preparation` (numbers drawn), `finished` (result published), `error` (engine incident, race never run), `cancelled` |
| `ground` | `dry`, `light`, `soft`, `sticky`, `heavy` |
| `incident` (runner) | `fall`, `fault`, `not_finished`, or `null` |

## What the API never returns

Genetics of other players' horses, hidden horse values, folders, notes, contracts, balances,
email addresses. Retired horses cannot be opened (404). The only private route is the key
owner's own stable.

## Recipes

**Ranking of a competition** (for a competition manager):
1. `https://www.sulkyland.com/api/v1/{world}/races?organizer=<code>&from=<first day>&to=<last day>&format=csv` — one call.
2. Keep the races of the competition (usually recognizable by their `name`) and drop those whose
   `status` is not `finished` (especially `cancelled`).
3. Open the `url` of each kept race: runners with `place` and `owner`.
4. Put each race in a category with `conditions` (`ageMin`/`ageMax`, `sex`), not by guessing
   from the runners.
5. Apply the competition's own rules (points per place, number of horses counted per owner…).
   Count per horse **code** and per `owner` code.
6. Ask the manager for anything the data cannot know: disqualifications, multi-accounts,
   penalties.

**Summary of a stable** (private): `https://www.sulkyland.com/api/v1/{world}/me/stable?privatekey=...&format=csv`, one call.
Group by `age`, `sex`, `specialty`; remember that unborn foals have `born: false`.

**Career of a horse**: `https://www.sulkyland.com/api/v1/{world}/horses/{code}` then `links.races` (race record) and
`links.children` (offspring).

**Lineage**: horse → `father.url`, `mother.url` → their parents, and so on.

**A clan**: `https://www.sulkyland.com/api/v1/clans/{code}` → each `members[].url` → `worlds[].horses`.
