// Every route of the API, in one table. The router in app.mjs dispatches from it (a route that is not here // cannot be served, and createApp() refuses to start if a row has no handler or a handler has no row), and // GET /v1/openapi.json is generated from it. So the document cannot say something the router does not do. // // access "public" no sign-in. Works while rentals are closed. // "signed-in" Authorization: Bearer ; `key: true` when an API key (idk_...) is taken too. // Answers 503 `not-open` until the engine is open. // "operator" Authorization: Bearer // limit which rate limit counts the call: "read", "write", "mcp", or "none" (the route limits itself) // cache true when the answer may sit in a shared cache for a few seconds (public reads only) // body "json" (a JSON object, the default for anything but GET), "raw" (the route parses it itself) const str = (description, extra = {}) => ({ type: "string", description, ...extra }); const num = (description, extra = {}) => ({ type: "number", description, ...extra }); const GPU = str("One of Idle's GPU ids.", { enum: ["rtx-4090", "rtx-5090", "l40s", "a100", "h100", "h200", "b200"] }); const ID = { id: str("The id, as listed by the account.") }; export const ROUTES = [ // ---- Public reads ---- { method: "GET", path: "/v1/health", access: "public", tag: "status", cache: true, summary: "What is open and what is not, and why", returns: "The mode (closed, test, live), what is missing, the tokens that buy credits, the MCP tools, the routing sources." }, { method: "GET", path: "/v1/gpus", access: "public", tag: "rates", cache: true, summary: "The rates of Idle's seven GPUs", returns: "The provider's live prices plus Idle's margin when a provider is configured, otherwise the target rate card with `available: 0`." }, { method: "GET", path: "/v1/quote", access: "public", tag: "rates", cache: true, summary: "What a duration on one GPU costs", query: { gpu: { ...GPU, required: true }, seconds: { type: "integer", description: "Whole seconds, 1 to 2592000.", required: true } }, returns: "The price in USD and in HYPE, billed per second." }, { method: "GET", path: "/v1/market", access: "public", tag: "status", cache: true, summary: "The live figures", returns: "The HYPE mid, Nvidia on HyperCore, the head of Elysium, USDC and EQNVDA on Elysium. A source that is down gives null and is named in `errors`." }, { method: "GET", path: "/v1/credits/quote", access: "public", tag: "credits", cache: true, summary: "What an amount of USDC or EQNVDA would buy in credits", query: { token: str("USDC or EQNVDA.", { enum: ["USDC", "EQNVDA"], required: true }), amount: str("A positive decimal amount of the token, for example 1.5.", { required: true }) }, returns: "The credits in USD, with the pool price, the mark and the haircut for EQNVDA." }, { method: "GET", path: "/v1/offers", access: "public", tag: "routing", cache: true, summary: "Whole Nvidia GPUs on offer on the market, cheapest first", description: "Market offers read from Runpod (list prices) and Vast.ai (live offers). They are not Idle's machines.", query: { gpu: GPU, minVram: num("Least GPU memory, in GB."), secure: { type: "boolean", description: "true: only secure-cloud or datacenter offers. false: only the others." }, limit: { type: "integer", description: "At most this many offers (default 50, at most 200)." } }, returns: "`{offers, count, total, sources, errors, asOf, note}`. Each offer is `{source, kind, gpu, model, vramGb, usdPerHour, secure, region, reliability, asOf}`.", }, { method: "GET", path: "/v1/route", access: "public", tag: "routing", cache: true, summary: "idle/auto: the offer that fits, by a stated rule", description: "Picks one market offer. `cheapest`: the lowest price. `fastest`: the highest tier, then the lowest price in it. `secure`: the lowest price among secure offers. The pick is a market offer from a named source, not a machine Idle holds.", query: { minVram: num("Least GPU memory, in GB (default 0)."), prefer: str("The rule (default cheapest).", { enum: ["cheapest", "fastest", "secure"] }), gpu: GPU }, returns: "`{rule, pick, alternatives, considered, marginBps, idleUsdPerHour, idleUsdPerSecond, rentableThroughIdle, sources, errors, asOf, note}`. 404 `no-offer` when nothing fits.", }, { method: "GET", path: "/v1/contract", access: "public", tag: "credits", cache: true, summary: "The credits contract on Elysium, read now", returns: "`{deployed, address, operator, withdrawalDelaySeconds, tokens, explorer, deployment, audited, wiredToRentals, relayer, note}`. Each token gives what users hold in the contract, what the operator has earned, and the contract's own token balance." }, { method: "GET", path: "/v1/contract/account", access: "public", tag: "credits", summary: "What one address holds in the credits contract", query: { address: str("The wallet address.", { required: true }) }, returns: "`{address, contract, tokens, withdrawalDelaySeconds}`. Each token gives the wallet balance, the allowance, the balance in the contract, what is available, and any pending withdrawal with its unlock time." }, { method: "GET", path: "/v1/openapi.json", access: "public", tag: "status", cache: true, summary: "This document", returns: "An OpenAPI 3.1 description of every route, generated from the router's own table." }, // ---- Public writes ---- { method: "POST", path: "/v1/rent", access: "public", tag: "status", limit: "none", body: "raw", summary: "Kept for older clients: refuses", returns: "503 `not-open` while closed; 400 `moved` once open (rent with POST /v1/instances)." }, { method: "POST", path: "/v1/auth/challenge", access: "public", needsOpen: true, tag: "sign-in", summary: "A message for the wallet to sign", bodyFields: { address: str("The wallet address.", { required: true }) }, returns: "`{address, message, nonce, issuedAt, expiresAt}`. Sign `message` with personal_sign." }, { method: "POST", path: "/v1/auth/verify", access: "public", needsOpen: true, tag: "sign-in", summary: "Exchange the signature for a session", bodyFields: { address: str("The wallet address.", { required: true }), signature: str("The personal_sign signature of the challenge.", { required: true }) }, returns: "`{token, address, expiresAt}`. The token is good for 24 hours." }, { method: "POST", path: "/rpc", access: "public", tag: "relayer", limit: "none", body: "raw", summary: "The scoped relayer (JSON-RPC)", returns: "Elysium reads are forwarded; `eth_sendRawTransaction` carries only a USDC or EQNVDA transfer to the treasury, an approval for the credits contract, and that contract's deposit and withdrawal calls, and only with a gas account." }, { method: "POST", path: "/mcp", access: "public", tag: "agents", limit: "mcp", body: "raw", summary: "The MCP server (Streamable HTTP, stateless, JSON responses)", returns: "A JSON-RPC response. Tools that act on an account take `Authorization: Bearer idk_...`." }, { method: "GET", path: "/mcp", access: "public", tag: "agents", limit: "none", summary: "Not a stream: 405", returns: "405. The MCP endpoint takes POST only." }, { method: "DELETE", path: "/mcp", access: "public", tag: "agents", limit: "none", body: "raw", summary: "No session to end: 405", returns: "405. The MCP endpoint keeps no session." }, // ---- Signed in ---- { method: "GET", path: "/v1/me", access: "signed-in", key: true, tag: "account", summary: "Credits, SSH keys, API keys, instances", returns: "The account." }, { method: "POST", path: "/v1/ssh-keys", access: "signed-in", tag: "account", summary: "Add an SSH public key", bodyFields: { name: str("A label.", { required: true }), publicKey: str("One ssh-ed25519 or ssh-rsa public key line.", { required: true }) }, returns: "201 `{id, name, type, fingerprint, addedAt}`." }, { method: "DELETE", path: "/v1/ssh-keys/{id}", access: "signed-in", tag: "account", params: ID, summary: "Remove an SSH key", returns: "`{ok, id}`." }, { method: "POST", path: "/v1/instances", access: "signed-in", key: true, tag: "instances", summary: "Rent a GPU", bodyFields: { gpu: { ...GPU, required: true }, sshKeyIds: { type: "array", items: { type: "string" }, description: "The SSH keys to put on the machine (default: all of the account's)." } }, returns: "201, the instance." }, { method: "GET", path: "/v1/instances", access: "signed-in", key: true, tag: "instances", summary: "The account's instances", returns: "`{instances}`, newest first." }, { method: "GET", path: "/v1/instances/{id}", access: "signed-in", key: true, tag: "instances", params: ID, summary: "One instance", returns: "The instance: status, SSH command when running, seconds billed, cost so far, and its receipt once ended." }, { method: "POST", path: "/v1/instances/{id}/end", access: "signed-in", key: true, tag: "instances", params: ID, summary: "End an instance", returns: "The receipt." }, { method: "POST", path: "/v1/credits/claim", access: "signed-in", key: true, tag: "credits", summary: "Credit a USDC or EQNVDA transfer to the treasury", bodyFields: { txHash: str("The transaction hash on Elysium.", { required: true }) }, returns: "`{ok, txHash, token, amount, priceUsd, creditedUsd, creditsUsd, block, confirmations, entry}`." }, { method: "GET", path: "/v1/ledger", access: "signed-in", key: true, tag: "credits", summary: "Top-ups, charges and refunds", query: { limit: { type: "integer", description: "At most this many entries (default 100, at most 500)." } }, returns: "`{address, creditsUsd, entries}`, newest first." }, { method: "POST", path: "/v1/api-keys", access: "signed-in", tag: "account", summary: "Create an API key with a daily spend cap", bodyFields: { name: str("A label.", { required: true }), capUsdPerDay: num("The most the key may spend per UTC day, in USD.", { required: true }) }, returns: "201, the key with its secret, shown once." }, { method: "POST", path: "/v1/api-keys/{id}/stop", access: "signed-in", tag: "account", params: ID, summary: "Stop an API key and end its instances", returns: "The key, and the receipts of what was ended." }, { method: "DELETE", path: "/v1/api-keys/{id}", access: "signed-in", tag: "account", params: ID, summary: "Delete an API key and end its instances", returns: "`{ok, id, ended}`." }, // ---- Operator ---- { method: "GET", path: "/v1/tick", access: "operator", tag: "operator", summary: "Settle, ask the provider, release machines", returns: "What the tick did." }, ].map((r) => ({ ...r, id: `${r.method} ${r.path}`, limit: r.limit ?? (r.method === "GET" ? "read" : "write"), body: r.body ?? (r.method === "GET" ? "none" : "json") })); const compiled = ROUTES.map((r) => ({ route: r, parts: r.path.split("/").filter(Boolean) })); /** The row a request falls on, with its path parameters, or null. */ export function matchRoute(method, path) { const seg = String(path).split("/").filter(Boolean); for (const { route, parts } of compiled) { if (route.method !== method || parts.length !== seg.length) continue; const params = {}; if (parts.every((p, i) => (p.startsWith("{") ? ((params[p.slice(1, -1)] = seg[i]), true) : p === seg[i]))) return { route, params }; } return null; } /** The paths that may be cached briefly by a shared cache. */ export const CACHEABLE = new Set(ROUTES.filter((r) => r.cache).map((r) => r.path)); const ERROR = { type: "object", required: ["error", "message"], properties: { error: { type: "string", description: "A stable code, for example not-open." }, message: { type: "string" } } }; /** * The OpenAPI 3.1 document of the table. * @param {{base:string, mode:"closed"|"test"|"live", version?:string}} o */ export function openapi({ base, mode, version = "0.4.0" }) { const open = mode !== "closed"; const paths = {}; for (const r of ROUTES) { const closed = (r.access === "signed-in" || r.needsOpen) && !open; const parameters = [ ...Object.entries(r.params ?? {}).map(([name, s]) => ({ name, in: "path", required: true, description: s.description, schema: { type: s.type } })), ...Object.entries(r.query ?? {}).map(([name, { description, required, ...schema }]) => ({ name, in: "query", required: !!required, description, schema })), ]; const fields = Object.entries(r.bodyFields ?? {}); const op = { operationId: r.id.replace(/[^A-Za-z0-9]+/g, "_").replace(/_+$/, ""), tags: [r.tag], summary: r.summary, description: [r.description, r.returns, r.access === "signed-in" || r.needsOpen ? (open ? "Open on this deployment." : "Closed on this deployment: answers 503 `not-open` until rentals open.") : null].filter(Boolean).join("\n\n"), "x-idle-access": r.access, "x-idle-status": closed ? "closed" : "open", ...(parameters.length ? { parameters } : {}), ...(fields.length ? { requestBody: { required: true, content: { "application/json": { schema: { type: "object", required: fields.filter(([, s]) => s.required).map(([n]) => n), properties: Object.fromEntries(fields.map(([n, { required, ...s }]) => [n, s])) } } } } } : r.body === "raw" && r.method === "POST" && r.path !== "/v1/rent" ? { requestBody: { required: true, content: { "application/json": { schema: { type: "object", description: "A JSON-RPC 2.0 request." } } } } } : {}), responses: { [r.id === "GET /mcp" || r.id === "DELETE /mcp" ? "405" : r.id === "POST /v1/rent" ? "503" : "200"]: { description: r.returns, content: { "application/json": { schema: { type: "object" } } } }, default: { description: "An error: `{error, message}`.", content: { "application/json": { schema: { $ref: "#/components/schemas/Error" } } } }, }, security: r.access === "signed-in" ? (r.key ? [{ session: [] }, { apiKey: [] }] : [{ session: [] }]) : r.access === "operator" ? [{ cronSecret: [] }] : [], }; (paths[r.path] ??= {})[r.method.toLowerCase()] = op; } return { openapi: "3.1.0", info: { title: "Idle, the GPU cloud on Elysium", version, description: "Routing over market offers, rates, credits and rentals of whole Nvidia GPUs. Public routes work on every deployment. Signed-in routes answer 503 `not-open` until a deployment has a GPU provider, a treasury, a session secret and a state store; this deployment is in `" + mode + "` mode. Errors are JSON `{error, message}`. Generated from the router's own table.", }, servers: [{ url: base }], tags: ["status", "rates", "routing", "credits", "sign-in", "account", "instances", "agents", "relayer", "operator"].map((name) => ({ name })), paths, components: { schemas: { Error: ERROR }, securitySchemes: { session: { type: "http", scheme: "bearer", description: "A session token from POST /v1/auth/verify (starts with ids_)." }, apiKey: { type: "http", scheme: "bearer", description: "An API key from POST /v1/api-keys (starts with idk_), with a spend cap per UTC day." }, cronSecret: { type: "http", scheme: "bearer", description: "The operator's CRON_SECRET." }, }, }, "x-idle-mode": mode, }; }