Skip to Content
MineDuels

Rate limits and errors

How requests are limited, what protects the server, and every error code.

The API is built so that clients cannot slow the game down. Requests are limited, queued with a cap, cached, and kept off the game's own database threads.

Rate limits

Limits use token buckets. A bucket refills at the per-second rate and holds up to the burst size. A request takes one token. With no token left the answer is 429.

BucketApplies toPer secondBurstSetting
AddressEvery request, before the key is checked3060limits.per-ip
Readstatus, servers, kits, arenas, queues, parties, tournaments, drain2040limits.read
Heavyplayers/*, leaderboards/*, matches*, config reads510limits.heavy
Writedrain/start, drain/stop, reload, config PUT and PATCH26limits.write
Wrong keysFailed authentication, per address1 per 5 s10fixed

The read, heavy and write buckets are per key and separate from each other. Many reads do not use up the write bucket. The address bucket is shared by every key behind one address.

A limited request:

HTTP/1.1 429 Too Many Requests
Retry-After: 1
Content-Type: application/json; charset=utf-8

{"ok":false,"error":{"code":"rate_limited","message":"this key is over its heavy limit"}}

Retry-After is in seconds. Wait that long, then retry.

Behind a reverse proxy every request comes from 127.0.0.1. Set trust-forwarded-for: true so the limit follows the real client address.

Other protections

ProtectionValueResult when exceeded
Worker threads and queuethreads 4, queue 64503 busy, Retry-After: 1
Database reads at oncedatabase-concurrency 3, 2 second wait503 busy
Request bodymax-body-kb 256413 too_large
Address length512 characters, query 2048414 uri_too_long
Query parameters32extra ones are ignored
Config batch200 changes400 bad_request
Wait for the game thread5 seconds (30 for a reload)503 unavailable
Wait for the database8 seconds503 unavailable

Other things that keep it stable:

  • The API has its own small database pool. It never uses the threads that save player data.
  • Game state is read on the server's main thread (the global region on Folia), never from a worker, so reads cannot corrupt it.
  • Lists, leaderboards, stats and match queries are cached for cache-seconds (5 by default). Fifty clients asking for the same leaderboard cost one query. Set cache-seconds: 0 for live data, at the cost of more queries. Reload, config edits and remote drain requests clear the cache.
  • A failing request answers 500 with a generic message and never shows internals. The server keeps running.
  • If the port cannot be opened, MineDuels logs a warning and carries on.

Handling 429 and 503 in a client

Retry after the time in Retry-After, with a limit on attempts:

async function call(path, options = {}, attempts = 4) {
  for (let i = 0; i < attempts; i++) {
    const res = await fetch(process.env.MD_URL + path, {
      ...options,
      headers: { Authorization: `Bearer ${process.env.MD_KEY}`, ...(options.headers || {}) },
    });
    if (res.status !== 429 && res.status !== 503) return res;
    const wait = Number(res.headers.get('retry-after') || 1);
    await new Promise((r) => setTimeout(r, wait * 1000));
  }
  throw new Error('still limited after ' + attempts + ' attempts');
}
import time, requests

def call(method, path, **kw):
    for _ in range(4):
        r = requests.request(method, BASE + path, headers=HEADERS, **kw)
        if r.status_code not in (429, 503):
            return r
        time.sleep(int(r.headers.get("Retry-After", 1)))
    raise RuntimeError("still limited")

To stay under the limits, poll at most once per cache-seconds. Data changes no faster than that anyway.

Error format

{ "ok": false, "error": { "code": "not_found", "message": "no player Nobody is known" } }

The code is stable and meant for programs. The message is for people and may change.

Error codes

StatuscodeMeaning
400bad_requestA parameter or the body is invalid. The message names it.
401unauthorizedNo key, or a key that does not exist.
403forbiddenThe key's scope is too low.
403protectedThe setting or file cannot be changed through the API.
404not_foundNo such endpoint, player, kit, match, server or file.
405method_not_allowedThe path exists but not for this method. The Allow header lists the right ones.
413too_largeThe body is larger than max-body-kb.
414uri_too_longThe address is too long.
422invalid_changesA config batch has an invalid item. Nothing was written.
422invalid_fileA config file on disk is not valid YAML.
429rate_limitedOver a limit. Wait Retry-After seconds.
500internalAn unexpected error. Details are in the server console.
500reload_failedA config edit was written but the reload failed, so the files were put back.
503busyThe server is handling as much as it should. Retry after Retry-After.
503unavailableThe game or the database did not answer in time.

Examples:

curl -s -H "Authorization: Bearer $MD_KEY" "$MD_URL/matches?limit=500"
{"ok":false,"error":{"code":"bad_request","message":"limit must be from 1 to 100"}}
curl -s -X DELETE -H "Authorization: Bearer $MD_KEY" "$MD_URL/status"
{"ok":false,"error":{"code":"method_not_allowed","message":"DELETE is not allowed here; use GET"}}

Response headers

HeaderValue
Content-Typeapplication/json; charset=utf-8
Cache-Controlno-store
X-Content-Type-Optionsnosniff
Retry-AfterSeconds, on 429 and 503
AllowAllowed methods, on 405
WWW-AuthenticateBearer, on 401
Access-Control-Allow-*Only when cors-origin is set

On this page