{
 "openapi": "3.1.0",
 "info": {
  "title": "relay.bitcraftsync.app cache API",
  "version": "1.0.0",
  "summary": "Read-only JSON API over a live mirror of the BitCraft game databases.",
  "description": "No authentication. All ids are 64-bit integers serialised as strings. Responses are live game state: cache them for at least a minute rather than polling. Response fields are defined by the protobuf messages listed at `/proto` (`relay_cache.proto`); JSON is the default encoding. Community project, not affiliated with Clockwork Labs. Overview for agents: `/llms.txt`."
 },
 "servers": [
  {
   "url": "https://relay.bitcraftsync.app"
  }
 ],
 "paths": {
  "/claim": {
   "get": {
    "operationId": "searchClaims",
    "summary": "Find claims by name",
    "parameters": [
     {
      "name": "name",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Case-insensitive substring of the claim name. Be specific: common words match thousands of claims."
     }
    ],
    "responses": {
     "200": {
      "description": "Claim summaries (possibly empty). Field definitions: the matching message in /proto/relay_cache.proto.",
      "content": {
       "application/json": {
        "schema": {
         "type": "array",
         "items": {
          "type": "object"
         }
        }
       }
      }
     },
     "400": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/claim/{id}": {
   "get": {
    "operationId": "getClaim",
    "summary": "Claim details",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[0-9]+$"
      },
      "description": "Claim entity_id (from /claim?name=)."
     }
    ],
    "responses": {
     "200": {
      "description": "Supplies, upkeep, treasury, tier, researched techs, location. Field definitions: the matching message in /proto/relay_cache.proto.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/claim/{id}/inventory": {
   "get": {
    "operationId": "getClaimInventory",
    "summary": "Contents of a claim's shared storage",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[0-9]+$"
      },
      "description": "Claim entity_id (from /claim?name=)."
     }
    ],
    "responses": {
     "200": {
      "description": "Storage buildings grouped by dimension. Town Banks are not included. Field definitions: the matching message in /proto/relay_cache.proto.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/claim/{id}/members": {
   "get": {
    "operationId": "getClaimMembers",
    "summary": "Claim roster",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[0-9]+$"
      },
      "description": "Claim entity_id (from /claim?name=)."
     }
    ],
    "responses": {
     "200": {
      "description": "Members with roles, skills, hexcoins and last login. Field definitions: the matching message in /proto/relay_cache.proto.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/claim/{id}/crafts": {
   "get": {
    "operationId": "getClaimCrafts",
    "summary": "Crafts at a claim",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[0-9]+$"
      },
      "description": "Claim entity_id (from /claim?name=)."
     },
     {
      "name": "completed",
      "in": "query",
      "required": false,
      "schema": {
       "type": "boolean"
      },
      "description": "Only completed (true) or only in-progress (false) crafts. Omit for both."
     }
    ],
    "responses": {
     "200": {
      "description": "In-progress and completed crafts with recipe outputs. Field definitions: the matching message in /proto/relay_cache.proto.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/player": {
   "get": {
    "operationId": "searchPlayers",
    "summary": "Find players by name",
    "parameters": [
     {
      "name": "name",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Case-insensitive substring of the username; 2+ characters recommended."
     }
    ],
    "responses": {
     "200": {
      "description": "Players across all regions (possibly empty). Field definitions: the matching message in /proto/relay_cache.proto.",
      "content": {
       "application/json": {
        "schema": {
         "type": "array",
         "items": {
          "type": "object"
         }
        }
       }
      }
     },
     "400": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/player/{id}": {
   "get": {
    "operationId": "getPlayer",
    "summary": "Player profile",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[0-9]+$"
      },
      "description": "Player entity_id (from /player?name=)."
     }
    ],
    "responses": {
     "200": {
      "description": "Username, region, sign-in state. Field definitions: the matching message in /proto/relay_cache.proto.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/player/{id}/inventory": {
   "get": {
    "operationId": "getPlayerInventory",
    "summary": "Player inventories",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[0-9]+$"
      },
      "description": "Player entity_id (from /player?name=)."
     }
    ],
    "responses": {
     "200": {
      "description": "Pockets, toolbelt, wallet, bank, wagon, cache, boat, recovery, deployables. Field definitions: the matching message in /proto/relay_cache.proto.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/player/{id}/housing": {
   "get": {
    "operationId": "getPlayerHousing",
    "summary": "Player house and its storage",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[0-9]+$"
      },
      "description": "Player entity_id (from /player?name=)."
     }
    ],
    "responses": {
     "200": {
      "description": "`status` is `ok` or `noHouse`. Field definitions: the matching message in /proto/relay_cache.proto.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/player/{id}/skills": {
   "get": {
    "operationId": "getPlayerSkills",
    "summary": "Player profession levels",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[0-9]+$"
      },
      "description": "Player entity_id (from /player?name=)."
     }
    ],
    "responses": {
     "200": {
      "description": "Experience and level per skill. Field definitions: the matching message in /proto/relay_cache.proto.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/player/{id}/crafts": {
   "get": {
    "operationId": "getPlayerCrafts",
    "summary": "A player's crafts",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "pattern": "^[0-9]+$"
      },
      "description": "Player entity_id (from /player?name=)."
     },
     {
      "name": "completed",
      "in": "query",
      "required": false,
      "schema": {
       "type": "boolean"
      },
      "description": "Only completed (true) or only in-progress (false) crafts. Omit for both."
     }
    ],
    "responses": {
     "200": {
      "description": "In-progress and completed crafts. Field definitions: the matching message in /proto/relay_cache.proto.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/leaderboard": {
   "get": {
    "operationId": "getLeaderboard",
    "summary": "Ranked player board",
    "description": "Ranks every player by XP (or by level). `level` and `xp` are the selected profession's, or the totals when `profession` is omitted. A player's `region` is where they are now, or where they last logged out. `q` only narrows the rows returned: `rank` stays the rank on the whole (profession, region) board, `total_players` is that board's size and `matches` the number of them passing `q`. `partial` is true while a region is still loading. Each board is reused for 5 s, and the route is rate limited per IP (30 requests/minute): poll no faster than every 10 s.",
    "parameters": [
     {
      "name": "profession",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Skill id (5) or case-insensitive name (Mining), from /leaderboard/options. Omit for the overall board."
     },
     {
      "name": "region",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer"
      },
      "description": "One region id, from /leaderboard/options. Omit for all regions."
     },
     {
      "name": "q",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "maxLength": 64
      },
      "description": "Case-insensitive substring of the username. Omit for every player."
     },
     {
      "name": "sort",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "xp",
        "level"
       ]
      },
      "description": "Ranking key. Default: xp."
     },
     {
      "name": "limit",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 500
      },
      "description": "Rows per page. Default: 100."
     },
     {
      "name": "offset",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 0
      },
      "description": "Rows to skip, after the `q` filter. Default: 0."
     }
    ],
    "responses": {
     "200": {
      "description": "The board: `scope`, `players[]`, `total_players`, `matches`, `offset`, `limit`, `partial`, `generated_at`. Field definitions: the Leaderboard message in /proto/relay_cache.proto.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Error: JSON `{\"error\": \"<message>\"}` — an unknown profession or region, or a `limit` outside 1..500.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "Too many requests from this IP (nginx budget of 30 per minute). Retry after a few seconds.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "Error: JSON `{\"error\": \"<message>\", \"code\": \"cache_syncing\"}` with a `Retry-After` header: no region (or the one asked for) has finished loading.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/leaderboard/options": {
   "get": {
    "operationId": "getLeaderboardOptions",
    "summary": "Professions and regions for the leaderboard",
    "description": "`professions[]` (`skill_id`, `name`, `title`, `max_level`) and `regions[]` (`region`, `name`, `players`, `ready`), plus `defaults` (`limit`, `max_limit`). Reused for 10 s.",
    "parameters": [],
    "responses": {
     "200": {
      "description": "Pickers for /leaderboard. Field definitions: the LeaderboardOptions message in /proto/relay_cache.proto.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "503": {
      "description": "Error: JSON `{\"error\": \"<message>\", \"code\": \"cache_syncing\"}` with a `Retry-After` header while no region has finished loading.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/deposits": {
   "get": {
    "operationId": "getHexiteDeposits",
    "summary": "Hexite deposits",
    "parameters": [
     {
      "name": "region",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer"
      },
      "description": "Limit to one region id (7, 8, 9, 12, 13, 14, 17, 18, 19)."
     }
    ],
    "responses": {
     "200": {
      "description": "`{count, deposits}`; depleted deposits carry `respawn_at`. Field definitions: the matching message in /proto/relay_cache.proto.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/storage-logs": {
   "get": {
    "operationId": "getStorageLogs",
    "summary": "Storage deposit/withdraw history (~15 days)",
    "parameters": [
     {
      "name": "storageId",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Storage building entity id."
     },
     {
      "name": "playerId",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Player entity id."
     },
     {
      "name": "itemId",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Item or cargo id; requires claimId or playerId."
     },
     {
      "name": "claimId",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string"
      },
      "description": "Claim entity id (with itemId)."
     },
     {
      "name": "itemType",
      "in": "query",
      "required": false,
      "schema": {
       "enum": [
        "Item",
        "Cargo"
       ]
      },
      "description": "With itemId."
     },
     {
      "name": "region",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer"
      },
      "description": "Region id."
     },
     {
      "name": "limit",
      "in": "query",
      "required": false,
      "schema": {
       "type": "integer",
       "minimum": 1
      },
      "description": "Newest N entries. Always set this."
     }
    ],
    "responses": {
     "200": {
      "description": "Log entries, newest first when limited. Exactly one mode per request: `storageId`, or `playerId`, or `itemId` with `claimId` or `playerId`. Field definitions: the matching message in /proto/relay_cache.proto.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/health": {
   "get": {
    "operationId": "getFleetHealth",
    "summary": "Mirror fleet status",
    "parameters": [],
    "responses": {
     "200": {
      "description": "Per-source database name, port and connectivity. Field definitions: the matching message in /proto/relay_cache.proto.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/cache-health": {
   "get": {
    "operationId": "getCacheHealth",
    "summary": "Cache readiness",
    "parameters": [],
    "responses": {
     "200": {
      "description": "`ready` overall and per region. Field definitions: the matching message in /proto/relay_cache.proto.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/proto": {
   "get": {
    "operationId": "listProtos",
    "summary": "Index of protobuf schema files",
    "parameters": [],
    "responses": {
     "200": {
      "description": "`{protos: [{name, path, bytes}]}`. Field definitions: the matching message in /proto/relay_cache.proto.",
      "content": {
       "application/json": {
        "schema": {
         "type": "object"
        }
       }
      }
     },
     "400": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "description": "Error: JSON `{\"error\": \"<message>\"}`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  }
 },
 "components": {
  "schemas": {
   "Error": {
    "type": "object",
    "required": [
     "error"
    ],
    "properties": {
     "error": {
      "type": "string"
     },
     "code": {
      "type": "string",
      "description": "Stable code when present, e.g. `not_found`."
     },
     "kind": {
      "type": "string",
      "description": "Entity kind for not-found errors, e.g. `claim`."
     }
    }
   }
  }
 }
}
