// What whole Nvidia GPUs cost on the market right now, read from two public sources that answer without a key: // // runpod list prices of every GPU type, for its secure cloud and its community cloud // POST https://api.runpod.io/graphql { gpuTypes { id displayName memoryInGb secureCloud communityCloud securePrice communityPrice } } // vast live offers that can be rented this minute, one GPU each, from verified hosts // GET https://console.vast.ai/api/v0/bundles/?q= // // These are other people's machines and other people's prices. Idle owns none of them and rents none of them // through this file: it reads, normalises and sorts. Nothing here is a price Idle made up; a source that does // not answer gives no offers and is named in `errors`. // // Every offer comes out as // {source, kind, gpu, model, vramGb, usdPerHour, secure, region, reliability, asOf} // source "runpod" | "vast" // kind "list-price" (a published rate, not a promise of stock) | "live-offer" (a machine on offer now) // gpu Idle's id for the model (rates.mjs) or null for an Nvidia model Idle has no id for // secure runpod: the secure cloud. vast: a datacenter host (what Vast itself sells as its secure cloud). // A host being "verified" is not enough: every Vast offer read here is verified. // region where the machine is, as the source says it, or null // reliability the source's own score from 0 to 1, or null // // Two things about Vast's answers, both checked on real reads (29 November 2026): // - A search returns at most 64 offers whatever `limit` says, so one broad search misses the large GPUs. // Idle asks five narrow questions instead (see VAST_QUERIES). // - `gpu_frac` is the share of the host's GPUs that the offer takes (one GPU of an eight-GPU host is 0.125; // the CPU share is the same fraction), not a slice of a GPU. With `num_gpus` 1 every offer is one whole GPU, // with its whole memory in `gpu_ram`. Offers are kept only when num_gpus is exactly 1. import { GPUS } from "./rates.mjs"; import { GPU_TYPES } from "./provider-runpod.mjs"; export const RUNPOD_PRICES_URL = "https://api.runpod.io/graphql"; export const RUNPOD_PRICES_QUERY = "query { gpuTypes { id displayName memoryInGb secureCloud communityCloud securePrice communityPrice } }"; export const VAST_OFFERS_URL = "https://console.vast.ai/api/v0/bundles/"; /** The Vast model name of each of Idle's GPUs. A name only counts with the memory Idle's GPU has (see idOnVast). */ export const VAST_NAMES = { "rtx-4090": "RTX 4090", "rtx-5090": "RTX 5090", l40s: "L40S", a100: "A100 SXM4", h100: "H100 SXM", h200: "H200", b200: "B200", }; const base = { rentable: { eq: true }, num_gpus: { eq: 1 }, verified: { eq: true }, type: "on-demand", order: [["dph_total", "asc"]] }; const named = (ids, limit) => ({ ...base, gpu_name: { in: ids.map((id) => VAST_NAMES[id]) }, limit }); /** The five searches, cheapest first within each. Together they cover Idle's seven GPUs and the cheap end of the rest. */ export const VAST_QUERIES = [ { ...base, limit: 64 }, // the cheapest machines of any model named(["rtx-4090"], 16), named(["rtx-5090"], 16), named(["l40s", "a100"], 64), named(["h100", "h200", "b200"], 64), ]; const runpodIds = new Map(Object.entries(GPU_TYPES).map(([id, type]) => [type, id])); const round6 = (x) => Math.round(x * 1e6) / 1e6; const isNvidia = (id) => /^(nvidia|tesla)\b/i.test(id); /** Runpod's price list as offers: one per GPU type and per cloud that really carries it. */ export function fromRunpod(json, asOf) { const types = json?.data?.gpuTypes; if (!Array.isArray(types)) throw new Error("no gpuTypes in the answer"); const out = []; for (const t of types) { if (typeof t?.id !== "string" || !isNvidia(t.id) || !(t.memoryInGb > 0)) continue; // AMD cards, and the "unknown" row if (/\bMIG\b/.test(t.id)) continue; // a MIG type is a slice of a GPU: whole GPUs only const one = (secure, price) => ({ source: "runpod", kind: "list-price", gpu: runpodIds.get(t.id) ?? null, model: t.displayName, vramGb: t.memoryInGb, usdPerHour: round6(price), secure, region: null, reliability: null, asOf }); // A price is only a price where the cloud carries the type: Runpod fills the other column with a placeholder. if (t.secureCloud === true && t.securePrice > 0) out.push(one(true, t.securePrice)); if (t.communityCloud === true && t.communityPrice > 0) out.push(one(false, t.communityPrice)); } return out; } /** Idle's id for a Vast offer: the model name must match and the memory must be the one Idle's GPU has. */ function idOnVast(name, vramGb) { for (const g of GPUS) { // Vast reports usable memory, a little under the nominal figure (an L40S shows 45 GB of its 48). if (VAST_NAMES[g.id] === name && vramGb <= g.vram + 1 && vramGb >= g.vram - 3) return g.id; } return null; } /** Vast's offers as offers. Anything that is not one whole, rentable Nvidia GPU with a price is left out. */ export function fromVast(json, asOf) { const offers = json?.offers; if (!Array.isArray(offers)) throw new Error("no offers in the answer"); const out = []; for (const o of offers) { if (o?.gpu_arch !== "nvidia" || o.num_gpus !== 1 || o.rentable !== true || o.rented === true) continue; if (!(o.dph_total > 0) || !(o.gpu_ram > 0) || typeof o.gpu_name !== "string") continue; if (o.gpu_total_ram != null && o.gpu_total_ram !== o.gpu_ram) continue; // more than one GPU's memory: not a single GPU const vramGb = Math.round(o.gpu_ram / 1024); const reliability = Number.isFinite(o.reliability2) ? o.reliability2 : Number.isFinite(o.reliability) ? o.reliability : null; out.push({ source: "vast", kind: "live-offer", gpu: idOnVast(o.gpu_name, vramGb), model: o.gpu_name, vramGb, usdPerHour: round6(o.dph_total), // Vast's total per hour for the offer as searched, its default disk included secure: o.hosting_type === 1, region: typeof o.geolocation === "string" ? o.geolocation.replace(/^[\s,]+/, "").trim() || null : null, // Vast sometimes sends ", US" reliability, asOf, id: o.id, }); } return out; } export const SOURCES = [ { name: "runpod", kind: "list-price", url: RUNPOD_PRICES_URL, what: "Runpod's published price per GPU type, secure cloud and community cloud" }, { name: "vast", kind: "live-offer", url: VAST_OFFERS_URL, what: "Vast.ai offers rentable now: one whole GPU each, verified hosts" }, ]; /** * @param {{fetch?:typeof fetch, now?:()=>number, ttlMs?:number, retryMs?:number, timeoutMs?:number}} o * @returns {() => Promise<{offers:object[], sources:object[], errors:string[], asOf:string}>} * Each source is read at most once per `ttlMs` (60 s), simultaneous callers share one read, and a source that * failed is not asked again for `retryMs` (15 s): a source that is down is not hammered. */ export function makeOffers(o = {}) { const f = o.fetch ?? fetch; const now = o.now ?? Date.now; const ttlMs = o.ttlMs ?? 60_000; const retryMs = o.retryMs ?? 15_000; const timeoutMs = o.timeoutMs ?? 8_000; const get = async (url, init) => { const r = await f(url, { ...init, signal: AbortSignal.timeout(timeoutMs) }); if (!r.ok) throw new Error("answered " + r.status); return r.json(); }; const readers = { async runpod(asOf) { return fromRunpod(await get(RUNPOD_PRICES_URL, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ query: RUNPOD_PRICES_QUERY }) }), asOf); }, async vast(asOf) { const pages = await Promise.all(VAST_QUERIES.map((q) => get(VAST_OFFERS_URL + "?q=" + encodeURIComponent(JSON.stringify(q)), { method: "GET", headers: { Accept: "application/json" } }))); const seen = new Set(); // The same machine can answer two searches: keep it once. return pages.flatMap((p) => fromVast(p, asOf)).filter((x) => (seen.has(x.id) ? false : seen.add(x.id))); }, }; const state = Object.fromEntries(SOURCES.map((s) => [s.name, { at: -Infinity, offers: [], error: null, flight: null }])); async function source(name) { const s = state[name]; const t = now(); if (t - s.at < (s.error ? retryMs : ttlMs)) return s; s.flight ??= (async () => { const at = now(); try { s.offers = await readers[name](new Date(at).toISOString()); s.error = null; } catch (e) { s.offers = []; s.error = String(e?.message ?? e); } s.at = at; s.flight = null; return s; })(); return s.flight; } return async function offers() { const got = await Promise.all(SOURCES.map((s) => source(s.name))); return { offers: got.flatMap((s) => s.offers.map(({ id, ...offer }) => offer)), sources: SOURCES.map((s, i) => ({ name: s.name, kind: s.kind, url: s.url, what: s.what, ok: !got[i].error, count: got[i].offers.length, asOf: Number.isFinite(got[i].at) ? new Date(got[i].at).toISOString() : null })), errors: got.flatMap((s, i) => (s.error ? [`${SOURCES[i].name}: ${s.error}`] : [])), asOf: new Date(Math.min(...got.map((s) => s.at))).toISOString(), }; }; } // ---- Choosing among offers: this is what "idle/auto" does ---- /** * Idle's seven GPUs from the most to the least capable for training and inference. It is Idle's own ranking, * by generation and memory, not a benchmark. `prefer=fastest` reads it; models Idle has no id for have no rank. */ export const TIER_ORDER = ["b200", "h200", "h100", "a100", "rtx-5090", "l40s", "rtx-4090"]; export const PREFER = ["cheapest", "fastest", "secure"]; const RULES = { cheapest: "The lowest price among the offers that meet the constraints.", fastest: "The highest tier present among the offers that meet the constraints, then the lowest price within that tier. Tiers, highest first: " + TIER_ORDER.join(", ") + ". Only Idle's seven GPUs have a tier.", secure: "The lowest price among the offers that meet the constraints and are marked secure (Runpod's secure cloud, or a datacenter host on Vast).", }; const byPrice = (a, b) => a.usdPerHour - b.usdPerHour || (a.source < b.source ? -1 : a.source > b.source ? 1 : 0); /** The offers that meet the constraints, cheapest first. */ export function filterOffers(offers, { gpu = null, minVram = 0, secure = null } = {}) { return offers.filter((x) => (!gpu || x.gpu === gpu) && x.vramGb >= minVram && (secure === null || x.secure === secure)).sort(byPrice); } /** * @returns {{rule:object, pick:object|null, alternatives:object[], considered:number}} * `alternatives` are the next three in the rule's order that differ from the pick, and from each other, * by source, model, memory or cloud. */ export function chooseOffer(offers, { prefer = "cheapest", minVram = 0, gpu = null } = {}) { let list = filterOffers(offers, { gpu, minVram, secure: prefer === "secure" ? true : null }); if (prefer === "fastest") { const tier = (x) => (x.gpu ? TIER_ORDER.indexOf(x.gpu) : -1); list = list.filter((x) => tier(x) >= 0).sort((a, b) => tier(a) - tier(b) || byPrice(a, b)); } const rule = { prefer, minVram, gpu, description: RULES[prefer], ...(prefer === "fastest" ? { tierOrder: TIER_ORDER } : {}) }; const key = (x) => [x.source, x.model, x.vramGb, x.secure].join("|"); const seen = new Set(); const distinct = list.filter((x) => (seen.has(key(x)) ? false : seen.add(key(x)))); return { rule, pick: distinct[0] ?? null, alternatives: distinct.slice(1, 4), considered: list.length }; }