Skip to content

Realms & Realm Tokens

A realm is an independent game world with its own rules and pacing. Restfall has three kinds of tokens:

  • Account token (the user token) — obtained from password login, POST /api/v1/token/login/. Bound to no realm. It is the only token that can do account-level actions: list, create and delete your players, realm login, and list your tokens.
  • Realm token — obtained from POST /api/v1/realms/login/. Bound to one realm and one player. Authorizes all gameplay endpoints (towns, buildings, combat, trades, and so on).
  • OAuth token — what an MCP agent gets when you authorize it. Bound to the realm you picked, like a realm token.

Gameplay endpoints reject an account token with 403 Forbidden. Account-level endpoints reject realm and OAuth tokens with 403 Forbidden: “Account-level actions need an account token from password login”. So after logging in, pick a realm, exchange your account token for a realm token, and keep the account token for account-level actions. An agent therefore cannot reach another realm on its own; you authorize it for that realm instead. Checking your account (GET /api/v1/users/me/) and logging a token out accept any token. On a free account, the account and realm tokens work only in the web client: a script gets its own token through OAuth, which needs a premium or creator entitlement (Scripting needs Premium). All three kinds are sent the same way:

Authorization: Bearer your-token-here

List Realms

GET /api/v1/realms/

Lists all joinable realms and their active season. No authentication required. Supports limit and offset query parameters for pagination (limit defaults to 50, max 200; offset defaults to 0).

import httpx
response = httpx.get("http://localhost:8731/api/v1/realms/")
realms = response.json()

Response

The standard pagination envelope { "count", "limit", "offset", "results" }, where count is the total number of joinable realms and results holds the realms for the requested page:

{
"count": 1,
"limit": 50,
"offset": 0,
"results": [
{
"name": "moria",
"active_season": {
"id": "season-uuid",
"number": 3
},
"time_scale": 1.0,
"training_time_scale": 0.1333
}
]
}

The realm name is its identifier — use it for realm login. active_season is null when the realm has no season running; its id is what you pass when creating a player.

Realm pace

time_scale is a multiplier applied to every timed duration in the realm — building, training, research, healing, travel, protection windows, season length — as well as to production rates. A realm at 2.0 runs twice as fast: durations are halved and production rates are doubled versus a 1.0 realm. It defaults to 1.0 when the realm has no active season. Use it before joining to see a realm’s pace, and to compute expected durations/rates client-side for any raw (unscaled) numbers you already know; endpoints that report durations or rates directly (like revenue_seconds in the building catalog) are already adjusted for it.

training_time_scale is a second knob that applies to troop training only. A unit’s published training_time is Evony’s canonical base seconds (a swordsman is 225), and a training order’s duration is computed in this order:

  1. training_time × count × training_time_scale — the realm’s training pace (0.1333 on the shipped free and fast realms, so a swordsman is 30 s of base training there; 1.0 means canonical);
  2. divided by time_scale (so on fast, 3.0, that swordsman is 10 s);
  3. then the town’s own reductions — Military Science / Metal Casting research and an idle Mayor’s attack — which the server applies after the two realm knobs.

Everything else — building, research, healing, marches, protection, the season — is time_scale only; training_time_scale never touches them. It defaults to 1.0 when the realm has no active season. A one-unit order of the cheapest units can land under the resolver’s 5-second tick on a fast-paced realm (a 25-second warrior at 0.1333 on fast is nominally about a second); such an order simply completes on the next resolver tick.

For example, a realm at 3.0 means every build, march, training order, research project and protection window — and the season itself — takes a third as long as the same realm at 1.0, while every cost, storage cap and unit stat stays identical. Only pacing changes; balance does not. A realm’s pace is fixed for the life of a season — it is set once when the season starts and does not change while that season is active.

Realm Login

POST /api/v1/realms/login/

Exchanges your account token for a realm-scoped token. You must already have a player in the realm’s active season — create one first via POST /api/v1/players/ (see Create a Player). A realm or OAuth token gets 403 Forbidden here and mints nothing.

import httpx
response = httpx.post(
"http://localhost:8731/api/v1/realms/login/",
headers={"Authorization": "Bearer your-user-token"},
json={"realm": "moria"},
)
realm_token = response.json()["api_key"]

Response

Returns 201 Created:

{
"realm": "moria",
"api_key": "your-realm-token",
"expires_at": "2026-07-12T12:00:00Z"
}

Save the api_key — it is shown only this once (tokens are stored hashed, and the listing endpoint redacts them). Use it as the Bearer token for all gameplay endpoints.

Realm tokens expire after 30 days. The 5-token limit is shared across your whole account: account tokens, realm tokens and agent (OAuth) tokens count against the same total. Logging in at the limit never fails: it revokes your oldest account or realm token to make room (an agent’s OAuth token only if there is nothing else to revoke; never the account token you call realm login with), and the revoked token answers 401 Unauthorized from then on. Expired tokens are cleaned up automatically on login and never count.

Returns 400 Bad Request if the realm doesn’t exist or you have no player in its active season.

Realm Logout

POST /api/v1/realms/logout/

Invalidates a realm token. Authenticate with the realm token itself, not your user token.

import httpx
httpx.post(
"http://localhost:8731/api/v1/realms/logout/",
headers={"Authorization": "Bearer your-realm-token"},
)

Returns 204 No Content on success, or 400 Bad Request if the token used is a user token rather than a realm token.

List Your Realm Tokens

GET /api/v1/realms/tokens/

Lists your realm tokens. Needs your account token; a realm or OAuth token gets 403 Forbidden. Keys are redacted — if you’ve lost a key, log in to the realm again to get a new one. Supports limit and offset query parameters for pagination (limit defaults to 50, max 200; offset defaults to 0).

import httpx
response = httpx.get(
"http://localhost:8731/api/v1/realms/tokens/",
headers={"Authorization": "Bearer your-user-token"},
)
tokens = response.json()

Response

The standard pagination envelope { "count", "limit", "offset", "results" }, where count is the total number of your realm tokens and results holds the tokens for the requested page:

{
"count": 1,
"limit": 50,
"offset": 0,
"results": [
{
"realm": "moria",
"api_key": null,
"expires_at": "2026-07-12T12:00:00Z"
}
]
}

Check Your Account

GET /api/v1/users/me/

Returns the authenticated user’s account details. Works with any token: account, realm or OAuth.

import httpx
response = httpx.get(
"http://localhost:8731/api/v1/users/me/",
headers={"Authorization": "Bearer your-user-token"},
)
me = response.json()

Response

{
"id": "uuid",
"email": "you@example.com",
"username": "yourname"
}