Skip to content

vast-ai/vast-cli / vastai

vastai

Flagged

Vast.ai CLI to manage GPU instances, volumes, serverless endpoints, and billing.

FileKindSize
SKILL.mdskill md18.6 KB
__init__.pyscript1.8 KB
_base.pyscript1.6 KB
api/__init__.pyscript31 B
api/auth.pyscript15.3 KB
api/billing.pyscript10.4 KB
api/client.pyscript9.1 KB
api/clusters.pyscript4.5 KB
api/deployments.pyscript1.4 KB
api/endpoints.pyscript12.0 KB
api/instances.pyscript17.1 KB
api/keys.pyscript4.3 KB
api/machines.pyscript7.4 KB
api/metrics.pyscript2.6 KB
api/offers.pyscript21.2 KB
api/price_increase.pyscript4.0 KB
api/query.pyscript12.2 KB
api/storage.pyscript14.5 KB
api/teams.pyscript4.4 KB
async_/__init__.pyscript79 B
async_/client.pyscript9.6 KB
async_/results.pyscript1.3 KB
cli/__init__.pyscript25 B
cli/commands/__init__.pyscript757 B
cli/commands/auth.pyscript42.8 KB
cli/commands/benchmarks.pyscript42.0 KB
cli/commands/billing.pyscript30.4 KB
cli/commands/clusters.pyscript7.8 KB
cli/commands/deployments.pyscript7.8 KB
cli/commands/endpoints.pyscript17.3 KB
cli/commands/instances.pyscript55.4 KB
cli/commands/keys.pyscript7.9 KB
cli/commands/machines.pyscript78.4 KB
cli/commands/metrics.pyscript12.7 KB
cli/commands/misc.pyscript11.0 KB
cli/commands/offers.pyscript30.0 KB
cli/commands/price_increase.pyscript14.5 KB
cli/commands/repl.pyscript719 B
cli/commands/storage.pyscript38.9 KB
cli/commands/teams.pyscript6.4 KB
cli/commands/uninstall.pyscript2.4 KB
cli/commands/update.pyscript3.1 KB
cli/display.pyscript20.1 KB
cli/main.pyscript11.5 KB
cli/parser.pyscript18.1 KB
cli/repl/__init__.pyscript318 B
cli/repl/bridge.pyscript7.3 KB
cli/repl/catalog.pyscript6.3 KB
cli/repl/completion.pyscript8.2 KB
cli/repl/session.pyscript7.3 KB
cli/self_test/__init__.pyscript46 B
cli/self_test/machine_diagnostics.pyscript21.0 KB
cli/self_test/runtime_diagnostics.pyscript18.6 KB
cli/self_test/support_bundle.pyscript11.0 KB
cli/selfupdate.pyscript14.0 KB
cli/util.pyscript26.3 KB
cli/utils.pyscript577 B
data/__init__.pyscript303 B
data/deployment.pyscript3.5 KB
data/endpoint.pyscript2.1 KB
data/instance.pyscript3.6 KB
data/offer.pyscript4.4 KB
data/query.pyscript12.8 KB
data/workergroup.pyscript1.4 KB
pdf/__init__.pyscript0 B
pdf/vast.ai-logo-50pct.pngbinary7.4 KB
pdf/vast.ai-logo.pngbinary10.1 KB
pdf/vast_pdf.pyscript19.4 KB
pdf/watcher.shexecutablescript390 B
sdk.pyscript52.2 KB
serverless/__init__.pyscript193 B
serverless/client/__init__.pyscript346 B
serverless/client/client.pyscript36.7 KB
serverless/client/connection.pyscript11.5 KB
serverless/client/endpoint.pyscript6.9 KB
serverless/client/managed.pyscript7.3 KB
serverless/client/request_status.pyscript371 B
serverless/client/session.pyscript2.8 KB
serverless/client/worker.pyscript1.3 KB
serverless/remote/__init__.pyscript245 B
serverless/remote/base.pyscript6.3 KB
serverless/remote/deploy.pyscript12.6 KB
serverless/remote/serialization.pyscript3.7 KB
serverless/remote/serve.pyscript8.6 KB
serverless/remote/serve_deployment.pyscript6.3 KB
serverless/remote/utils.pyscript9.7 KB
serverless/server/__init__.pyscript0 B
serverless/server/lib/__init__.pyscript0 B
serverless/server/lib/backend.pyscript43.3 KB
serverless/server/lib/data_types.pyscript10.6 KB
serverless/server/lib/metrics.pyscript12.2 KB
serverless/server/lib/server.pyscript3.2 KB
serverless/server/worker.pyscript17.1 KB
sync/__init__.pyscript76 B
sync/client.pyscript4.9 KB
sync/results.pyscript1.2 KB
utils.pyscript12.2 KB

cli/commands/metrics.py

View on GitHub
"""CLI commands for platform-wide GPU market metrics (host/admin access)."""

import json
import sys
from datetime import datetime, timezone

from vastai.cli.parser import argument, hidden_aliases
from vastai.cli.display import display_table, deindent
from vastai.cli.utils import get_parser as _get_parser, get_client
from vastai.api import metrics as metrics_api


parser = _get_parser()


_VERIFIED_MAP = {"true": "yes", "false": "no", "all": "all"}
_HOSTING_MAP = {"true": "secure_cloud", "false": "community", "all": "all"}

_NEEDS_MACHINE_MSG = "No metrics available. This endpoint is for hosts with active machines."


def notice_if_old_name(args, old, new):
    if getattr(args, "command", None) == old:
        print(f"NOTICE: `vastai {old}` is now `vastai {new}`. The old name will be removed in the next release.",
              file=sys.stderr)


_GPU_CURRENT_FIELDS = (
    ("gpu_name",          "GPU",      "{}",     None, True),
    ("total",             "Total",    "{}",     None, False),
    ("available",         "Avail",    "{}",     None, False),
    ("unavailable",       "Unrent",   "{}",     None, False),
    ("usage",             "Usage%",   "{:.1f}", None, False),
    ("rented_verified",   "Rnt/Ver",  "{}",     None, False),
    ("avail_verified",    "Avl/Ver",  "{}",     None, False),
    ("rented_unverified", "Rnt/Unv",  "{}",     None, False),
    ("avail_unverified",  "Avl/Unv",  "{}",     None, False),
    ("dlperf",            "DLPerf",   "{:.1f}", None, False),
    ("tflops",            "TFLOPS",   "{:.1f}", None, False),
    ("tflops_per_dollar", "TFLOPS/$", "{:.1f}", None, False),
    ("price_p10",         "P10 $/hr", "{:.4f}", None, False),
    ("price_median",      "Med $/hr", "{:.4f}", None, False),
    ("price_p90",         "P90 $/hr", "{:.4f}", None, False),
)


_GPU_TRENDS_FIELDS = (
    ("date",              "Date",     "{}",     None, True),
    ("rented_verified",   "Rnt/Ver",  "{}",     None, False),
    ("avail_verified",    "Avl/Ver",  "{}",     None, False),
    ("rented_unverified", "Rnt/Unv",  "{}",     None, False),
    ("avail_unverified",  "Avl/Unv",  "{}",     None, False),
    ("unavail_verified",  "Unr/Ver",  "{}",     None, False),
    ("unavail_unverified","Unr/Unv",  "{}",     None, False),
    ("total",             "Total",    "{}",     None, False),
    ("rented_p10",        "R.p10",    "{:.4f}", None, False),
    ("rented_median",     "R.med",    "{:.4f}", None, False),
    ("rented_p90",        "R.p90",    "{:.4f}", None, False),
    ("avail_p10",         "A.p10",    "{:.4f}", None, False),
    ("avail_median",      "A.med",    "{:.4f}", None, False),
    ("avail_p90",         "A.p90",    "{:.4f}", None, False),
)


_GPU_LOCATION_FIELDS = (
    ("gpu_name",     "GPU",       "{}",     None, True),
    ("city",         "City",      "{}",     None, True),
    ("country_code", "CC",        "{}",     None, True),
    ("num_gpus",     "GPUs",      "{}",     None, False),
    ("state",        "State",     "{}",     None, False),
    ("verified",     "Verified",  "{}",     None, False),
    ("latitude",     "Lat",       "{:.4f}", None, False),
    ("longitude",    "Lon",       "{:.4f}", None, False),
)


@parser.command(
    argument("--verified", type=str, choices=["true", "false", "all"], default="all",
             help="Filter GPUs by verification status"),
    argument("--datacenter", type=str, choices=["true", "false", "all"], default="all",
             help="Filter GPUs by datacenter hosting type"),
    argument("--num-gpus", type=str, choices=["all", "1", "2", "4", "8", "other"], default="all",
             help="Filter by machine GPU-count bucket (1x, 2x, 4x, 8x, or other)"),
    usage="vastai show gpu-metrics [OPTIONS]",
    aliases=hidden_aliases(["metrics gpu"]),
    help="[Host] Get current GPU market metrics",
    epilog=deindent("""
        Get current GPU metrics with counts, usage, performance, and pricing.
        For historical metrics, see the `show gpu-trends` command.
        Requires host or admin access.

        Examples:
            vastai show gpu-metrics
            vastai show gpu-metrics --verified true --datacenter true
            vastai show gpu-metrics --num-gpus 8
            vastai show gpu-metrics --raw
    """),
)
def show__gpu_metrics(args):
    """Get current GPU metrics."""
    notice_if_old_name(args, "metrics gpu", "show gpu-metrics")
    client = get_client(args)
    resp = metrics_api.gpu_current(
        client,
        verified=_VERIFIED_MAP[args.verified],
        hosting_type=_HOSTING_MAP[args.datacenter],
        num_gpus=args.num_gpus,
    )
    if resp.get("needs_machine"):
        print(_NEEDS_MACHINE_MSG)
        return
    if args.raw:
        print(json.dumps(resp, indent=1))
        return
    display_table(resp.get("gpus", []), _GPU_CURRENT_FIELDS)


@parser.command(
    argument("name", type=str, nargs="?", default="RTX 5090,RTX 4090,RTX 3090",
             help="GPU name, comma-separated list, or 'all'. Underscores are accepted in place of spaces."),
    argument("--verified", type=str, choices=["true", "false", "all"], default="all",
             help="Filter by verified status"),
    argument("--datacenter", type=str, choices=["true", "false", "all"], default="all",
             help="Filter by datacenter hosting type"),
    argument("--num-gpus", type=str, choices=["all", "1", "2", "4", "8", "other"], default="all",
             help="Filter by machine GPU-count bucket (1x, 2x, 4x, 8x, or other)"),
    argument("--start", type=int, default=None, help="Start unix timestamp"),
    argument("--end", type=int, default=None, help="End unix timestamp"),
    argument("--step", type=int, default=None,
             help="Time between data points in seconds (e.g. 3600 for hourly). Minimum 60s; step may be raised server-side to cap points returned."),
    argument("--full", action="store_true", default=False,
             help="Show all data points instead of sampling ~20"),
    usage="vastai show gpu-trends [NAME] [OPTIONS]",
    aliases=hidden_aliases(["metrics gpu-trends"]),
    help="[Host] Get GPU market history",
    epilog=deindent("""
        Show GPU supply/demand and pricing trends over time. Defaults to RTX 5090, 4090, 3090
        for the last 24 hours. Requires host or admin access.

        Examples:
            vastai show gpu-trends
            vastai show gpu-trends "RTX 4090"
            vastai show gpu-trends "RTX 4090" --full
            vastai show gpu-trends "RTX 4090" --raw
            vastai show gpu-trends all --verified true --datacenter true
            vastai show gpu-trends "RTX 5090" --num-gpus 8
            vastai show gpu-trends "RTX 4090,H100_SXM" --start 1773298800 --end 1773817200 --step 3600
    """),
)
def show__gpu_trends(args):
    """Get GPU metrics history."""
    notice_if_old_name(args, "metrics gpu-trends", "show gpu-trends")
    # Accept underscores as space aliases: "H100_SXM" -> "H100 SXM"
    args.name = args.name.replace("_", " ")
    client = get_client(args)
    resp = metrics_api.gpu_history(
        client,
        gpu_name=args.name,
        verified=_VERIFIED_MAP[args.verified],
        hosting_type=_HOSTING_MAP[args.datacenter],
        start=args.start,
        end=args.end,
        step=args.step,
        num_gpus=args.num_gpus,
    )
    if resp.get("needs_machine"):
        print(_NEEDS_MACHINE_MSG)
        return

    if "gpus" in resp:
        requested = [g.strip() for g in args.name.split(",")]
        gpu_items = [(name, resp["gpus"][name]) for name in requested if name in resp["gpus"]]
        seen = set(requested)
        for name, data in resp["gpus"].items():
            if name not in seen:
                gpu_items.append((name, data))
    else:
        gpu_items = [(args.name, resp)]

    sd_keys = ["rented_verified", "avail_verified", "rented_unverified", "avail_unverified",
               "unavail_verified", "unavail_unverified", "total"]
    pr_keys = ["rented_p10", "rented_median", "rented_p90", "avail_p10", "avail_median", "avail_p90"]

    if args.raw:
        raw_out = {}
        for gpu_name, gpu_data in gpu_items:
            sd = gpu_data.get("supply_demand", {})
            pr = gpu_data.get("pricing", {})
            timestamps = sd.get("timestamps", [])
            rows = []
            for i, ts in enumerate(timestamps):
                row = {"date": datetime.fromtimestamp(ts, tz=timezone.utc).strftime("%Y-%m-%d %H:%M:%S"), "timestamp": ts}
                for key in sd_keys:
                    arr = sd.get(key, [])
                    row[key] = arr[i] if i < len(arr) else None
                for key in pr_keys:
                    arr = pr.get(key, [])
                    row[key] = arr[i] if i < len(arr) else None
                rows.append(row)
            raw_out[gpu_name] = {"stats": gpu_data.get("stats", {}), "rows": rows}
        print(json.dumps(raw_out, indent=1))
        return

    for gpu_name, gpu_data in gpu_items:
        stats = gpu_data.get("stats", {})
        print(f"\n=== {gpu_name} ===")
        print(f"  tflops: {stats.get('tflops', '-')}  dlperf: {stats.get('dlperf', '-')}  tflops/$: {stats.get('tflops_per_dollar', '-')}")
        sd = gpu_data.get("supply_demand", {})
        pr = gpu_data.get("pricing", {})
        timestamps = sd.get("timestamps", [])
        if not timestamps:
            print("  (no data)")
            continue

        n = len(timestamps)
        sample_step = 1 if args.full else max(1, n // 20)
        rows = []
        for i in range(0, n, sample_step):
            row = {"date": datetime.fromtimestamp(timestamps[i], tz=timezone.utc).strftime("%Y-%m-%d %H:%M")}
            for key in sd_keys:
                arr = sd.get(key, [])
                row[key] = arr[i] if i < len(arr) else None
            for key in pr_keys:
                arr = pr.get(key, [])
                row[key] = arr[i] if i < len(arr) else None
            rows.append(row)

        display_table(rows, _GPU_TRENDS_FIELDS)
        if sample_step > 1:
            print(f"\n  ({n} data points, showing every {sample_step}th. Use --full for all.)")


@parser.command(
    argument("--verified", type=str, choices=["true", "false", "all"], default="all",
             help="Filter by verification status"),
    argument("--datacenter", type=str, choices=["true", "false", "all"], default="all",
             help="Filter by datacenter hosting type"),
    argument("--rented", type=str, choices=["true", "false", "all"], default="all",
             help="Filter by rented status. 'false' covers both available and unrentable GPUs; use --state to tell them apart"),
    argument("--state", type=str, choices=["all", "rented", "available", "unavailable"], default="all",
             help="Filter by listing state. 'unavailable' means listed but neither rentable nor rented"),
    argument("--gpu", type=str, default=None,
             help="Filter by GPU name (comma-separated list). Underscores are accepted in place of spaces."),
    usage="vastai show gpu-locations [OPTIONS]",
    aliases=hidden_aliases(["metrics gpu-locations"]),
    help="[Host] Get GPU location metrics",
    epilog=deindent("""
        Show geographic locations of GPUs on the platform. Filtering is applied
        client-side — the endpoint returns one shared dataset and the CLI narrows
        the rows locally. Requires host or admin access.

        Examples:
            vastai show gpu-locations
            vastai show gpu-locations --verified true --datacenter true
            vastai show gpu-locations --gpu "RTX 4090,H100_SXM"
            vastai show gpu-locations --rented false --raw
    """),
)
def show__gpu_locations(args):
    """Get GPU location metrics."""
    notice_if_old_name(args, "metrics gpu-locations", "show gpu-locations")
    client = get_client(args)
    resp = metrics_api.gpu_locations(client)
    if resp.get("needs_machine"):
        print(_NEEDS_MACHINE_MSG)
        return

    locations = resp.get("locations", [])

    for field in ("verified", "datacenter"):
        choice = getattr(args, field)
        if choice != "all":
            want = choice == "true"
            locations = [loc for loc in locations if bool(loc.get(field)) == want]

    # current servers send a three-valued state; older ones only the rented boolean
    def state_of(loc):
        return loc.get("state") or ("rented" if loc.get("rented") else "available")

    if args.rented != "all":
        locations = [loc for loc in locations if (state_of(loc) == "rented") == (args.rented == "true")]
    if args.state != "all":
        locations = [loc for loc in locations if state_of(loc) == args.state]
    if args.gpu:
        wanted_gpus = {g.strip().replace("_", " ") for g in args.gpu.split(",") if g.strip()}
        locations = [loc for loc in locations if loc.get("gpu_name") in wanted_gpus]

    if args.raw:
        print(json.dumps({"success": True, "locations": locations}, indent=1))
        return
    display_table(locations, _GPU_LOCATION_FIELDS)
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall