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

serverless/client/managed.py

View on GitHub
from __future__ import annotations
from typing import TYPE_CHECKING, Awaitable, Generic, Optional, Union, TypeVar

from vastai.data.endpoint import EndpointData
from vastai.data.deployment import DeploymentData, DeploymentPutResponse
from vastai.data.workergroup import WorkergroupConfig
from .endpoint import Endpoint_
import requests

if TYPE_CHECKING:
    from .client import _ServerlessBase

R = TypeVar("R", bound=Awaitable)


class ManagedEndpoint(Generic[R]):
    """Wraps an endpoint with lazy data fetching, caching, and request dispatch.

    The .id property is always available. All other data is fetched on first
    access via .get() and cached. Call .invalidate() to force a re-fetch.
    """

    def __init__(
        self, id: int, client: _ServerlessBase[R], data: Optional[EndpointData] = None
    ):
        self._id = id
        self._client = client
        self._routing_endpoint: Optional[Endpoint_[R]] = (
            Endpoint_[R](client, data=data) if isinstance(data, EndpointData) else None
        )

    @property
    def id(self) -> int:
        return self._id

    def invalidate(self):
        """Clear cached data so the next .get() re-fetches from the API."""
        self._data = None
        self._routing_endpoint = None

    async def _get_routing_endpoint(self) -> Endpoint_[R]:
        if self._routing_endpoint is None:
            data = await self._client.fetch_endpoint(self._id)
            self._routing_endpoint = Endpoint_(client=self._client, data=data)
        return self._routing_endpoint

    async def request(self, route: str, payload: dict, **kwargs) -> dict:
        """Route a request to this endpoint's workers. Fetches endpoint data if needed."""
        ep = await self._get_routing_endpoint()
        return await self._client.queue_endpoint_request(
            endpoint=ep,
            worker_route=route,
            worker_payload=payload,
            **kwargs,
        )

    async def add_workergroup(
        self,
        config_or_template_hash: Union[WorkergroupConfig, str, None] = None,
        **kwargs,
    ) -> int:
        """Add a workergroup to this endpoint. Returns the workergroup ID.

        Accepts either:
          - A WorkergroupConfig object
          - A template_hash string (common case)
          - Keyword arguments passed to WorkergroupConfig
        """
        if isinstance(config_or_template_hash, WorkergroupConfig):
            config = config_or_template_hash
            if config.endpoint_id is None:
                config.endpoint_id = self._id
        elif isinstance(config_or_template_hash, str):
            config = WorkergroupConfig(
                endpoint_id=self._id, template_hash=config_or_template_hash, **kwargs
            )
        else:
            config = WorkergroupConfig(endpoint_id=self._id, **kwargs)
        return await self._client.create_workergroup(config)

    async def delete(self) -> None:
        """Delete this endpoint."""
        await self._client.delete_endpoint(self._id)

    def __repr__(self) -> str:
        status = "loaded" if self._routing_endpoint is not None else "lazy"
        return f"<ManagedEndpoint id={self._id} ({status})>"


class ManagedDeployment(Generic[R]):
    """Wraps a deployment with lazy data fetching, caching, and endpoint access.

    The .id and .endpoint_id properties are always available.
    If the deployment was just created/updated, .needs_upload and .upload()
    are available to handle S3 blob uploads.
    """

    def __init__(
        self,
        id: int,
        endpoint_id: int,
        client: _ServerlessBase[R],
        data: Optional[DeploymentData] = None,
        put_response: Optional[DeploymentPutResponse] = None,
    ):
        self._id = id
        self._endpoint_id = endpoint_id
        self._client = client
        self._data = data
        self._put_response = put_response
        self._endpoint: Optional[ManagedEndpoint[R]] = None

    @property
    def id(self) -> int:
        return self._id

    @property
    def endpoint_id(self) -> int:
        return self._endpoint_id

    @property
    def action(self) -> Optional[str]:
        """The action taken by put_deployment (e.g. 'created', 'soft_update', 'exists')."""
        return self._put_response.action if self._put_response else None

    @property
    def workergroup_id(self) -> Optional[int]:
        """The workergroup ID associated with this deployment, if returned by the server."""
        return self._put_response.workergroup_id if self._put_response else None

    @property
    def needs_upload(self) -> bool:
        """True if the deployment requires a blob upload to S3 to complete setup."""
        return (
            self._put_response is not None
            and self._put_response.upload_url is not None
            and self._put_response.upload_fields is not None
        )

    async def upload(self, file_path: str) -> None:
        """Upload a tarball to S3 using the presigned POST from put_deployment.

        Raises ValueError if no upload is needed, RuntimeError on upload failure.
        """
        if not self.needs_upload:
            raise ValueError("No upload needed for this deployment")

        import aiohttp
        import os

        upload_url = self._put_response.upload_url
        upload_fields = self._put_response.upload_fields

        data = aiohttp.FormData()
        for key, value in upload_fields.items():
            data.add_field(key, value)
        data.add_field(
            "file",
            open(file_path, "rb"),
            filename=os.path.basename(file_path),
            content_type="application/gzip",
        )

        session = await self._client._get_session()
        async with session.post(upload_url, data=data) as resp:
            if resp.status not in (200, 201, 204):
                text = await resp.text()
                raise RuntimeError(
                    f"S3 upload failed: HTTP {resp.status} - {text[:512]}"
                )

        self._put_response.upload_url = None
        self._put_response.upload_fields = None

    @property
    def endpoint(self) -> ManagedEndpoint[R]:
        """Get the ManagedEndpoint for this deployment (lazy — data fetched on first use)."""
        if self._endpoint is None:
            self._endpoint = ManagedEndpoint(id=self._endpoint_id, client=self._client)
        return self._endpoint

    async def get(self) -> DeploymentData:
        """Fetch and cache the full deployment data. Returns cached data on subsequent calls."""
        if self._data is None:
            self._data = await self._client.fetch_deployment(self._id)
        return self._data

    def invalidate(self):
        """Clear cached data so the next .get() re-fetches from the API."""
        self._data = None

    def sync_heartbeat(
        self,
    ):  # for use in background thread outside of main aiohttp connection
        headers = {"Authorization": f"Bearer {self._client.api_key}"}
        requests.post(
            url=self._client.vast_web_url.rstrip("/")
            + f"/api/v0/deployment/{self.id}/heartbeat/",
            headers=headers,
        )

    def __repr__(self) -> str:
        status = "loaded" if self._data is not None else "lazy"
        upload = " needs_upload" if self.needs_upload else ""
        return f"<ManagedDeployment id={self._id} endpoint_id={self._endpoint_id} ({status}{upload})>"
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