On this page

← All documentation

Online API

Where the Prism web API is described, how to sign in, what needs no account, the real rate limits, and how to generate a typed client.

The Prism site and the game talk to one backend (services/api, a Loco.rs application) over HTTPS and JSON. This page is the pointer: where the exhaustive reference is, how to authenticate, what you can read without an account, the limits, and how to get a typed client. The pages that follow explain the groups of endpoints that matter to tool makers: map index and boards, catalogue, submission and game updates.

Where the reference lives

The API describes itself. The description is generated from the Rust code (the controller attributes), so it cannot drift from the server.

What Address Content
Interactive reference https://prism.am/api/docs A Scalar page. Its script is served by the API itself (no third-party host), under a policy that allows scripts from the page's own origin only. The backend serves the same page at GET /.
Public description https://prism.am/api/openapi.json OpenAPI 3.1. It hides the ops and admin tags.
Committed copy services/api/types/openapi.json The full description (the public one plus the ops operations: health, the description, the public keys; and the staff API), as a file of the repository. It is not served.

The staff API (/api/admin/*) is not reachable on the public host: the reverse proxy answers 404 there, and only the admin site relays it. It appears in the committed full description for the people who maintain it. Do not build on it.

The committed file is regenerated from the code, never edited by hand. From services/api:

cargo openapi

cargo openapi is an alias of cargo run -p prism_backend --bin openapi --. It writes types/openapi.json and opens no database. A test fails when the committed file is out of date.

The public description lists 110 operations: 61 need no token (the sign-in calls included) and 49 require a signed-in account (bearer). The map index, the boards, the players, the rankings, the marathon reads, the catalogue and the releases are all in the first group.

Authentication

Public reads need nothing: no key, no header. Everything that acts for a player (profile, friends, clans, presets, sending a marathon) needs an access token.

  • The token is a JWT signed with EdDSA (Ed25519). Send it as Authorization: Bearer <accessToken>.
  • The only security scheme of the description is bearer. There are no API keys, no personal tokens and no OAuth application.
  • POST /api/auth/login takes { "login": "<username or e-mail>", "password": "…", "device": "…" } (device is optional) and answers accessToken, refreshToken, expiresIn and user.
  • The access token lives 600 seconds (expiresIn). The refresh token lives 30 days and rotates: POST /api/auth/refresh with { "refreshToken": "…" } answers a new pair, and the old refresh token is dead. Presenting an old one again ends the whole session, so a client that refreshes from two places at once logs itself out.
  • POST /api/auth/logout ends one session, POST /api/auth/logout-all ends every session of the account.
  • Registration asks for a proof of work first (GET /api/auth/pow) and an e-mail confirmation. An account that is banned cannot sign in (403 account_banned, with reason and bannedUntil).
  • The public keys that verify the tokens are served at /.well-known/prism-keys.json (the current key and, during a rotation, the previous ones). The game server reads them; an ordinary client never needs them.

A 401 with invalid_token means the access token is missing, expired or not accepted: refresh it and retry once.

What is public

All of these answer without an account, as JSON unless said otherwise:

  • the map index: chart identity and sources, the .rox file, notes, pp, ratings, chartsets and their filters, the crawl status;
  • the boards: the board of a chart, its rates, one player's entry, one play and its replay;
  • players and rankings: profiles, search, ranks, achievements, the global, achievement and clan rankings;
  • marathons: the list, a marathon, its recipe, its board;
  • the catalogue of mods, skins and playlists (GET /api/catalog);
  • challenges, tournaments, titles, filter presets (reads);
  • the game builds: /releases.json, /download/{channel}/latest and /download/{channel}/installer;
  • the rating calculators (GET /api/ratings) and the health of the service.

The map index and boards page documents the first four groups with their real parameters. Everything else is in the reference at /api/docs.

Conventions

  • JSON, camelCase. Field names are camelCase. Dates are either an ISO 8601 string (generatedAt, createdAt) or a number of milliseconds since the Unix epoch in a field whose name ends in Ms (playedAtMs).
  • Additive. The documents only grow. Ignore the fields and the enum values you do not know. The catalogue has no v2 and the game protocol has none either.
  • Errors. An error answers its status code and a JSON body { "error": "<code>", "description": "<sentence>" }. error is a stable snake_case code to branch on (bad_request, invalid_token, rate_limited, invalid_credentials…); description names what is wrong and is meant for people. A banned account's 403 carries reason and bannedUntil too.
  • Identities. A chart is a note hash: 64 lowercase hexadecimal characters (what it hashes). An account is a lowercase UUID. A play, a marathon and a chartset have an integer id (a chartset also has a uuid).
  • Caching. Most reads carry an ETag: send If-None-Match and a 304 costs nothing. Content-addressed files (.rox, notes) are immutable.
  • Bodies. The public host refuses a request body above 64 KB, except the profile picture (5 MiB) and the one-time osu! import's files (1 MiB).
  • Courtesy. Put a way to reach you in your User-Agent. Do not poll: ask again when an ETag or a ttlMs says the answer may have changed.

Rate limits

Limits are per client address and per minute, in a fixed window. A client that goes over is answered 429 with { "error": "rate_limited", … } and a Retry-After header in seconds.

The client address is the first value of the X-Forwarded-For header. The reverse proxy overwrites that header with the real peer, so it cannot be forged from outside. Without a proxy (development), every client is direct. The proxy applies no rate limit of its own.

Limiter Default Setting Counts
Public reads 240 per minute CHARTS_RATE_PER_MINUTE One counter per bucket (below) and per address: a client can use 240 per minute in each bucket.
Catalogue 120 per minute CATALOG_RATE_PER_MINUTE GET /api/catalog.
Accounts 60 per minute none Every /api/auth/* call, one counter per address (an IPv6 address counts by its /64).
Performance reports 4 per minute none POST /api/perf-reports.

The buckets of the public reads limiter are these thirteen. A request is counted in the bucket of its endpoint:

Bucket Endpoints
lookup GET /api/charts/{hash}, and ratings or pp of a chart already computed
rating-compute ratings or pp of a chart at a rate that must be computed first
rox GET /api/charts/{hash}/rox and /notes
scores boards, plays, players, rankings (global, achievements, clans), marathon boards, achievements
browse chartsets, one chartset, the crawl status, marathons (list, one, recipe, by hash)
suggest GET /api/chartsets/suggest
replay GET /api/scores/{id}/replay
challenges the weekly challenge reads
clans GET /api/clans/{uuid}
presets the filter preset reads
tournaments the tournament reads
titles GET /api/titles
link-preview the page previews that chat apps fetch

GET /api/ratings is not throttled. The limits are the server's defaults: a self-hosted server may set others.

The game protocol

Lobbies, chat, presence and score submission do not go through this API. The game opens a WebSocket on wss://prism.am/play to the game server and exchanges JSON text frames, one message per frame. Both sides use the same Rust types (crates/online_protocol), published as the TypeScript package @pvng/online (generated by prism.exe --write-ts-packages [dir], committed at apps/web/packages/@pvng/online).

  • PROTOCOL_VERSION is 1 and there will be no v2: messages are enums tagged by type, a new message or field is additive, and a reader ignores what it does not know. The constant moves only if a message changes its meaning.
  • What both sides can do is negotiated by the features list of the handshake (hello from the game, welcome from the server): presence, chat, lobbies, lobby-files, scores, lobby-open, lobby-late-join, chat-commands, titles, clan-chat, lobby-draft.
  • The first message is hello with the protocol, the clientVersion, the features the client speaks and the account's access token (at most 2048 bytes). The server answers welcome with the features it offers and the minimum client version, or an error code.

The protocol is for the game, not for third-party bots: a score only counts after the server has replayed it on its own copy of the chart.

Generate a typed client

The website itself does this. From services/website, bun run gen:api runs:

openapi-typescript ../api/types/openapi.json -o src/lib/api/schema.d.ts

For your own project, point the generator at the public description:

bunx openapi-typescript https://prism.am/api/openapi.json -o prism-api.d.ts

The file exports paths, components and operations: a type for every path, parameter and response. The typed fetch wrapper openapi-fetch (createClient<paths>({ baseUrl: "https://prism.am" })) reads them directly. Any other OpenAPI 3.1 generator works as well, since the document is plain OpenAPI.

Source in the game repository: services/api/src/openapi.rs,services/api/src/controllers/openapi.rs,services/api/src/controllers/catalog.rs,services/api/src/controllers/charts.rs,services/api/src/controllers/auth.rs,services/api/src/app.rs,services/api/src/accounts/settings.rs,services/api/types/openapi.json,services/api/config/production.yaml,crates/online_protocol/src/lib.rs,deploy/Caddyfile,services/website/package.json