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

api/storage.py

View on GitHub
"""Storage, volume, and data transfer API functions for the Vast.ai SDK."""

import time


def copy(client, src_id, dst_id, src_path, dst_path):
    """Copy directories between instances, volumes, cloud services, and local.

    PUT /commands/copy_direct/ (remote-to-remote) or
    PUT /commands/rsync/ (when one side is local/None)

    Each of the source and destination locations can be either local or remote,
    subject to the read and write permissions required to carry out the action.
    Location IDs are the parsed form of a vast URL (see
    ``vastai.utils.parse_vast_url``):

    - instance_id (int)          legacy format, still supported
    - \"C.instance_id\"            container copy format
    - \"cloud_service\"            cloud service, e.g. \"drive\"
    - \"cloud_service.id\"         cloud service with ID, e.g. \"s3.101\" or \"hf.101\"
    - \"local\" or None            local machine
    - \"V.volume_id\"              volume copy, e.g. \"V.1234\"

    Volume copy is currently only supported for copying to other volumes,
    instances, or cloud services, not local.

    You should not copy to /root or / as a destination directory, as this can
    mess up the permissions on your instance ssh folder, breaking future copy
    operations (as they use ssh authentication). See
    https://vast.ai/docs/gpu-instances/data-movement#constraints for more
    information about constraints.

    Args:
        client: VastClient instance.
        src_id: Source location ID (or None/\"local\" for local).
        dst_id: Destination location ID (or None/\"local\" for local).
        src_path (str): Source path.
        dst_path (str): Destination path.

    Returns:
        dict: API response data. For local transfers this includes the
            ``src_addr``/``src_port`` or ``dst_addr``/``dst_port`` the caller
            uses to run rsync.

    Examples:
        copy(client, 6003036, 6003038, \"/workspace/\", \"/workspace/\")
        copy(client, \"C.11824\", \"local\", \"/data/test\", \"data/test\")
        copy(client, \"drive\", \"C.6003036\", \"/folder/file.txt\", \"/workspace/\")
        copy(client, \"s3.101\", \"C.6003036\", \"/data/\", \"/workspace/\")
        copy(client, \"V.1234\", \"C.5678\", \"/file\", \"/workspace/\")
        copy(client, \"V.1234\", \"s3.101\", \"/file\", \"/workspace/\")
    """
    req_json = {
        "client_id": "me",
        "src_id": src_id,
        "dst_id": dst_id,
        "src_path": src_path,
        "dst_path": dst_path,
    }

    if src_id is None or dst_id is None:
        r = client.put("/commands/rsync/", json_data=req_json)
    else:
        r = client.put("/commands/copy_direct/", json_data=req_json)

    r.raise_for_status()
    return r.json()


def cancel_copy(client, dst_id):
    """Cancel a remote copy in progress.

    DELETE /commands/copy_direct/

    Args:
        client: VastClient instance.
        dst_id: ID of copy destination to cancel.

    Returns:
        dict: API response data.
    """
    req_json = {"client_id": "me", "dst_id": dst_id}
    r = client.delete("/commands/copy_direct/", json_data=req_json)
    r.raise_for_status()
    return r.json()


def cancel_sync(client, dst_id):
    """Cancel a remote cloud sync in progress.

    DELETE /commands/rclone/

    Args:
        client: VastClient instance.
        dst_id: ID of cloud sync destination to cancel.

    Returns:
        dict: API response data.
    """
    req_json = {"client_id": "me", "dst_id": dst_id}
    r = client.delete("/commands/rclone/", json_data=req_json)
    r.raise_for_status()
    return r.json()


def rclone_flags(*, dry_run: bool = False, size_only: bool = False,
                 ignore_existing: bool = False, update: bool = False,
                 delete_excluded: bool = False) -> list:
    """Translate the friendly copy options into the rclone flag list."""
    flags = []
    if dry_run:
        flags.append("--dry-run")
    if size_only:
        flags.append("--size-only")
    if ignore_existing:
        flags.append("--ignore-existing")
    if update:
        flags.append("--update")
    if delete_excluded:
        flags.append("--delete-excluded")
    return flags


def cloud_copy(client, src, dst, instance, connection, transfer, flags=None):
    """Copy files/folders to and from cloud providers.

    POST /commands/rclone/

    Supported cloud providers include \"drive\", \"s3\", \"b2\", \"dropbox\", and
    Hugging Face (\"hf\").

    Args:
        client: VastClient instance.
        src (str): Path to source of object to copy.
        dst (str): Path to target of copy operation. Default \"/workspace\".
        instance (str): ID of the instance.
        connection (str): ID of cloud connection on your account.
        transfer (str): Type of transfer (e.g. \"Instance to Cloud\",
            \"Cloud to Instance\").
        flags (list, optional): Additional rclone flags such as
            [\"--dry-run\", \"--size-only\", \"--ignore-existing\",
            \"--update\", \"--delete-excluded\"].

    Returns:
        dict: API response data.

    Hugging Face example (\"hf\" connection):
        cloud_copy(client, \"my-bucket/data\", \"/workspace\", \"6003036\",
                   \"1234\", \"Cloud To Instance\")
    """
    req_json = {
        "src": src,
        "dst": dst,
        "instance_id": instance,
        "selected": connection,
        "transfer": transfer,
        "flags": flags or [],
    }

    r = client.post("/commands/rclone/", json_data=req_json)
    r.raise_for_status()
    return r.json()


def clone_volume(client, source, dest, size=None, disable_compression=False):
    """Clone a volume to another volume.

    POST /volumes/copy/

    Args:
        client: VastClient instance.
        source: Source volume ID.
        dest: Destination volume ID.
        size (float, optional): Size in GB for destination volume.
        disable_compression (bool): Disable compression during clone.
            Default False.

    Returns:
        dict: API response data.
    """
    json_blob = {
        "src_id": source,
        "dst_id": dest,
    }
    if size is not None:
        json_blob["size"] = size
    if disable_compression:
        json_blob["disable_compression"] = True

    r = client.post("/volumes/copy/", json_data=json_blob)
    r.raise_for_status()
    return r.json()


def show_volumes(client, type="all"):
    """Show stats on owned volumes.

    GET /volumes

    Args:
        client: VastClient instance.
        type (str): Volume type to display. Options: \"local\", \"network\",
            \"all\". Default \"all\".

    Returns:
        list: Volume data with computed duration field.
    """
    types = {
        "local": "local_volume",
        "network": "network_volume",
        "all": "all_volume",
    }
    vol_type = types.get(type, "all_volume")
    r = client.get("/volumes", query_args={"owner": "me", "type": vol_type})
    r.raise_for_status()
    rows = r.json()["volumes"]
    processed = []
    for row in rows:
        row['duration'] = time.time() - row['start_date']
        processed.append(row)
    return processed


def show_instance_backups(client, contract_id=None):
    """List the backups Vast has taken of the caller's instances and volumes.

    GET /instance_backups/

    Args:
        client: VastClient instance.
        contract_id (int): Restrict to one instance or volume contract id.

    Returns:
        list: Backup rows, newest first.
    """
    query_args = {}
    if contract_id is not None:
        query_args["contract_id"] = contract_id
    r = client.get("/instance_backups/", query_args=query_args)
    r.raise_for_status()
    return r.json()["backups"]


def instance_backup_files(client, contract_id):
    """Objects stored for one backup, plus a short-lived token to fetch them.

    GET /instance_backups/<contract_id>/download/

    The returned URLs are not usable alone: each request must carry the
    authorization_token, either as an `Authorization` header or appended as an
    `?Authorization=<token>` query parameter (what the CLI does, so the printed
    URLs are clickable). `truncated` is True when the backup holds more objects
    than were listed.

    Args:
        client: VastClient instance.
        contract_id (int): Instance or volume contract id.

    Returns:
        dict: authorization_token, expires_in_sec, truncated, files.
    """
    r = client.get(f"/instance_backups/{contract_id}/download/")
    r.raise_for_status()
    return r.json()


def create_volume(client, id, size=15, name=None):
    """Create a new volume.

    PUT /volumes/

    Args:
        client: VastClient instance.
        id (int): ID of volume offer.
        size (float): Size in GB. Default 15.
        name (str, optional): Optional name of volume.

    Returns:
        dict: API response data.
    """
    json_blob = {
        "size": int(size),
        "id": int(id),
    }
    if name:
        json_blob["name"] = name

    r = client.put("/volumes/", json_data=json_blob)
    r.raise_for_status()
    return r.json()


def delete_volume(client, id):
    """Delete a volume.

    DELETE /volumes/

    All instances using the volume must be destroyed before deletion.

    Args:
        client: VastClient instance.
        id (int): ID of volume contract.

    Returns:
        dict: API response data.
    """
    r = client.delete("/volumes/", query_args={"id": id})
    r.raise_for_status()
    return r.json()


def list_volume(client, id, size=15, price_disk=0.10, end_date=None):
    """[Host] List disk space for rent as a volume on a machine.

    POST /volumes/

    Args:
        client: VastClient instance.
        id (int): ID of machine to list.
        size (int): Size of disk space in GB. Default 15.
        price_disk (float): Storage price in $/GB/month. Default 0.10.
        end_date (str, optional): Contract offer expiration date
            (unix timestamp or MM/DD/YYYY format).

    Returns:
        dict: API response data.
    """
    json_blob = {
        "size": int(size),
        "machine": int(id),
        "price_disk": float(price_disk),
    }
    if end_date is not None:
        json_blob["end_date"] = end_date

    r = client.post("/volumes/", json_data=json_blob)
    r.raise_for_status()
    return r.json()


def list_volumes(client, ids, size=15, price_disk=0.10, end_date=None):
    """[Host] List disk space for rent as volumes on multiple machines.

    POST /volumes/

    Args:
        client: VastClient instance.
        ids (list[int]): IDs of machines to list.
        size (int): Size of disk space in GB. Default 15.
        price_disk (float): Storage price in $/GB/month. Default 0.10.
        end_date (str, optional): Contract offer expiration date
            (unix timestamp or MM/DD/YYYY format).

    Returns:
        dict: API response data.
    """
    json_blob = {
        "size": int(size),
        "machine": [int(mid) for mid in ids],
        "price_disk": float(price_disk),
    }
    if end_date is not None:
        json_blob["end_date"] = end_date

    r = client.post("/volumes/", json_data=json_blob)
    r.raise_for_status()
    return r.json()


def unlist_volume(client, id):
    """[Host] Unlist a volume offer.

    POST /volumes/unlist

    Args:
        client: VastClient instance.
        id (int): Volume ID to unlist.

    Returns:
        dict: API response data.
    """
    json_blob = {"id": id}
    r = client.post("/volumes/unlist", json_data=json_blob)
    r.raise_for_status()
    return r.json()


def create_network_volume(client, id, size=15, name=None):
    """Create a new network volume.

    PUT /network_volumes/

    Args:
        client: VastClient instance.
        id (int): ID of network volume offer.
        size (float): Size in GB. Default 15.
        name (str, optional): Optional name of network volume.

    Returns:
        dict: API response data.
    """
    json_blob = {
        "size": int(size),
        "id": int(id),
    }
    if name:
        json_blob["name"] = name

    r = client.put("/network_volumes/", json_data=json_blob)
    r.raise_for_status()
    return r.json()


def list_network_volume(client, disk_id, price_disk=0.15, size=15, end_date=None):
    """[Host] List disk space for rent as a network volume.

    POST /network_volumes/

    Args:
        client: VastClient instance.
        disk_id (int): ID of disk to list.
        price_disk (float): Storage price in $/GB/month. Default 0.15.
        size (int): Size of disk space in GB. Default 15.
        end_date (str, optional): Contract offer expiration date.

    Returns:
        dict: API response data.
    """
    json_blob = {
        "disk_id": disk_id,
        "price_disk": price_disk,
        "size": size,
    }
    if end_date is not None:
        json_blob["end_date"] = end_date

    r = client.post("/network_volumes/", json_data=json_blob)
    r.raise_for_status()
    return r.json()


def unlist_network_volume(client, id):
    """[Host] Unlist a network volume offer.

    POST /network_volumes/unlist/

    Args:
        client: VastClient instance.
        id (int): ID of network volume offer to unlist.

    Returns:
        dict: API response data.
    """
    json_blob = {"id": id}
    r = client.post("/network_volumes/unlist/", json_data=json_blob)
    r.raise_for_status()
    return r.json()


def show_network_disks(client):
    """[Host] Show network disks associated with your account.

    GET /network_disk/

    Args:
        client: VastClient instance.

    Returns:
        dict: Network disk data including cluster and machine info.
    """
    r = client.get("/network_disk/")
    r.raise_for_status()
    return r.json()


def add_network_disk(client, machines, mount_point, disk_id=None):
    """[Host] Add network disk to physical cluster.

    POST /network_disk/

    Args:
        client: VastClient instance.
        machines (list[int]): IDs of machines to add disk to.
        mount_point (str): Mount path of disk to add.
        disk_id (int, optional): ID of network disk to attach to machines.

    Returns:
        dict: API response data including disk_id.
    """
    json_blob = {
        "machines": [int(mid) for mid in machines],
        "mount_point": mount_point,
    }
    if disk_id is not None:
        json_blob["disk_id"] = disk_id

    r = client.post("/network_disk/", json_data=json_blob)
    r.raise_for_status()
    return r.json()


def show_connections(client):
    """Display user's cloud connections/integrations.

    GET /users/cloud_integrations/

    Args:
        client: VastClient instance.

    Returns:
        dict/list: Cloud integration data.
    """
    r = client.get("/users/cloud_integrations/")
    r.raise_for_status()
    return r.json()
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