Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ for your region, `gpushed plans --region asia-southeast1` for another, and

**Balance.** Credit is prepaid: the minimum top-up is $10, and you can top up
any amount above that at any time with `gpushed topup 25`. To create or start a
box you need at least one hour of its price in your balance. Premium plans,
those at $10/hour or more (`h100`), need $100.
box you need at least one hour of its price in your balance.

**Running out.** When your balance falls below $2 you get an email. When it's
nearly used up, your box is **stopped** (its disk is kept) and you get another
Expand Down
24 changes: 8 additions & 16 deletions api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type Box, type User, credit, getBox, meterBox, runMetering, updateBox, welcomeOnFirstTopup } from "./billing";
import { type Env, numVar } from "./env";
import { type ProvisionAction, dispatchProvision } from "./external";
import { DEFAULT_PLAN, PLANS, isPremium, planPrice, requiredBalanceMicros } from "./pricing";
import { DEFAULT_PLAN, PLANS, planPrice } from "./pricing";
import { REGIONS, byDistance, enabledRegions, regionOfZone, requestLocation } from "./regions";
import { PLAN_ZONES } from "./zones.generated";
import { type CheckoutSession, createCheckoutSession, topupCents, verifyStripeSignature } from "./stripe";
Expand Down Expand Up @@ -290,8 +290,6 @@ route("GET", "/plans", async (req, env) => {
machine_type: p.machineType,
hourly_usd: usd(price.hourlyMicros),
stopped_hourly_usd: usd(price.stoppedHourlyMicros),
premium: isPremium(price.hourlyMicros),
min_balance_usd: usd(requiredBalanceMicros(price.hourlyMicros)),
// available: can be created now; unavailable: not offered yet (no GCP
// quota); elsewhere: offered, but not in this region.
status: !p.available || where.length === 0 ? "unavailable" : offered ? "available" : "elsewhere",
Expand Down Expand Up @@ -402,11 +400,8 @@ route("POST", "/stripe/webhook", async (req, env) => {

// ---------------------------------------------------------------- boxes

function balanceShortMessage(balanceMicros: number, planId: string, hourlyMicros: number, neededMicros: number): string {
const why = isPremium(hourlyMicros)
? `the $${usd(neededMicros)} minimum for ${planId}, a premium plan ($${usd(hourlyMicros)}/h)`
: `one hour of ${planId} ($${usd(neededMicros)})`;
return `balance $${usd(balanceMicros)} is less than ${why}; run gpushed topup`;
function balanceShortMessage(balanceMicros: number, planId: string, hourlyMicros: number): string {
return `balance $${usd(balanceMicros)} is less than one hour of ${planId} ($${usd(hourlyMicros)}); run gpushed topup`;
}

route("POST", "/box", async (req, env) => {
Expand Down Expand Up @@ -434,12 +429,10 @@ route("POST", "/box", async (req, env) => {
}
if (candidates.length === 0) throw new HttpError(503, `${plan.id} isn't available right now`);
const premium = numVar(env.PREMIUM_PCT, 20);
// At least an hour at the price shown for the first region (what plans
// shows), or $100 for a premium plan.
// At least an hour at the price shown for the first region (what plans shows).
const price = planPrice(plan, candidates[0].id, premium)!;
const needed = requiredBalanceMicros(price.hourlyMicros);
if (user.balance_micros < needed) {
throw new HttpError(402, balanceShortMessage(user.balance_micros, plan.id, price.hourlyMicros, needed));
if (user.balance_micros < price.hourlyMicros) {
throw new HttpError(402, balanceShortMessage(user.balance_micros, plan.id, price.hourlyMicros));
}
const now = nowSec();
const box: Box = {
Expand Down Expand Up @@ -494,9 +487,8 @@ route("POST", "/box/start", async (req, env) => {
const box = await activeBox(env, user.id);
if (!box) throw new HttpError(404, "you have no box");
if (box.status !== "stopped") throw new HttpError(409, `box is ${box.status}; only a stopped box can be started`);
const needed = requiredBalanceMicros(box.hourly_micros);
if (user.balance_micros < needed) {
throw new HttpError(402, balanceShortMessage(user.balance_micros, box.plan, box.hourly_micros, needed));
if (user.balance_micros < box.hourly_micros) {
throw new HttpError(402, balanceShortMessage(user.balance_micros, box.plan, box.hourly_micros));
}
const now = nowSec();
const updated = await updateBox(env, box, { status: "starting" }, now);
Expand Down
15 changes: 0 additions & 15 deletions api/src/pricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,6 @@ export function planPrice(plan: Plan, region: string, premiumPct: number) {
};
}

// Premium plans (H100 today) cost $10/hour or more, and need $100 in the
// balance to create or start a box, so a box isn't stopped for lack of credit
// a few minutes in. Every other plan needs an hour of use.
export const PREMIUM_HOURLY_USD = 10;
export const PREMIUM_MIN_BALANCE_USD = 100;

export function isPremium(hourlyMicros: number): boolean {
return hourlyMicros >= PREMIUM_HOURLY_USD * 1e6;
}

// Balance, in micro-dollars, needed to create or start a box at this rate.
export function requiredBalanceMicros(hourlyMicros: number): number {
return isPremium(hourlyMicros) ? Math.max(hourlyMicros, PREMIUM_MIN_BALANCE_USD * 1e6) : hourlyMicros;
}

// Charge for `seconds` at an hourly rate, rounded down to the micro-dollar.
export function chargeMicros(hourlyMicros: number, seconds: number): number {
if (seconds <= 0 || hourlyMicros <= 0) return 0;
Expand Down
12 changes: 1 addition & 11 deletions api/test/pricing.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
import { meterRate } from "../src/billing";
import { IP_HOURLY_USD, PLANS, chargeMicros, diskHourlyUsd, gcpHourlyUsd, isPremium, planPrice, requiredBalanceMicros, withPremium } from "../src/pricing";
import { IP_HOURLY_USD, PLANS, chargeMicros, diskHourlyUsd, gcpHourlyUsd, planPrice, withPremium } from "../src/pricing";
import { REGIONS, byDistance, enabledRegions, regionOfZone } from "../src/regions";

describe("pricing", () => {
Expand Down Expand Up @@ -36,16 +36,6 @@ describe("pricing", () => {
expect(chargeMicros(1_000_000, -5)).toBe(0);
});

it("makes plans of $10/h or more premium, needing $100 to create", () => {
const h100 = planPrice(PLANS.h100, "us-central1", 20)!.hourlyMicros;
const a100 = planPrice(PLANS.a100, "us-central1", 20)!.hourlyMicros;
expect(isPremium(h100)).toBe(true);
expect(isPremium(a100)).toBe(false);
expect(requiredBalanceMicros(h100)).toBe(100_000_000);
expect(requiredBalanceMicros(a100)).toBe(a100); // just an hour of use
expect(requiredBalanceMicros(150_000_000)).toBe(150_000_000); // never less than an hour
});

it("lists H100 but doesn't offer it until GCP grants quota", () => {
expect(PLANS.h100.available).toBe(false);
expect(Object.values(PLANS).filter((p) => p.id !== "h100").every((p) => p.available)).toBe(true);
Expand Down
14 changes: 6 additions & 8 deletions client/gpushed-cli
Original file line number Diff line number Diff line change
Expand Up @@ -344,25 +344,23 @@ case "$cmd" in
if [ "${1:-}" = --region ]; then region="${2:-}"; [ -n "$region" ] || die "Usage: gpushed plans [--region REGION]"; fi
NO_AUTH=1 api GET "/plans${region:+?region=$region}"
jq -r '"Prices in \(.region_name) (\(.region))\(if .nearest then ", the region nearest you" else "" end). Default plan: \(.default)\n"' <<<"$API_BODY"
# One row per plan: id, GPU and machine, price, stopped price, minimum
# balance, status. Older APIs send no status: treat the plan as available.
# One row per plan: id, GPU, price, stopped price, status. Older APIs send
# no status: treat the plan as available.
jq -r '.plans[] | [
.id,
(.label | split(", ")[0] | sub("^1x NVIDIA "; "")),
"$\(.hourly_usd)",
"$\(.stopped_hourly_usd)",
"$\(.min_balance_usd // .hourly_usd)",
((.status // "available") as $s
| if $s == "unavailable" then "coming soon (no GPU quota yet)"
elif $s == "elsewhere" then "not here; in \(.regions | join(", "))"
else "available" end
+ (if .premium then ", premium" else "" end))
else "available" end)
] | @tsv' <<<"$API_BODY" |
awk -F'\t' 'BEGIN { printf " %-8s %-18s %9s %9s %11s %s\n", "PLAN", "GPU", "PER HOUR", "STOPPED", "MIN BALANCE", "STATUS" }
{ printf " %-8s %-18s %9s %9s %11s %s\n", $1, $2, $3, $4, $5, $6 }'
awk -F'\t' 'BEGIN { printf " %-8s %-18s %9s %9s %s\n", "PLAN", "GPU", "PER HOUR", "STOPPED", "STATUS" }
{ printf " %-8s %-18s %9s %9s %s\n", $1, $2, $3, $4, $5 }'
jq -r '"\nRegions: \([.regions[] | .id] | join(", "))"' <<<"$API_BODY"
say "Prices include disk and IP, and differ a little by region. A stopped box costs only its disk."
say "Min balance is what you need to create or start a box: an hour of use, or \$100 for premium plans (\$10/h or more)."
say "To create or start a box you need an hour of its price in your balance."
say "Your box goes to the nearest region with free GPUs; pick one with: gpushed up [plan] --region REGION"
;;

Expand Down
Loading