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/endpoint.py

View on GitHub
# endpoint.py
import asyncio
from dataclasses import dataclass

import time
from .connection import _make_request
from typing import Awaitable, Generic, Optional, TypeVar, Union, TYPE_CHECKING
import logging

from vastai.data.endpoint import EndpointData

logger = logging.getLogger("vastai")

if TYPE_CHECKING:
    from .client import _ServerlessBase, ServerlessRequest
    from .request_status import RequestStatus
    from .session import Session

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


@dataclass
class EndpointDataPartial:
    name: str
    id: int
    api_key: str


class Endpoint_(Generic[R]):
    client: "_ServerlessBase[R]"

    def __repr__(self):
        return f"<Endpoint {self.name} (id={self.data.id})>"

    def __init__(
        self,
        client: "_ServerlessBase[R]",
        name: Optional[str] = None,
        id: Optional[int] = None,
        api_key: Optional[str] = None,
        data: Optional[EndpointData] = None,
        soft_refresh_threshold=3 * 24 * 3600,
        hard_refresh_threshold=6 * 24 * 3600,
    ):
        if client is None:
            raise ValueError("client is required")
        self.client = client
        if isinstance(data, EndpointData):
            self.data: "EndpointData | EndpointDataPartial" = data
        elif isinstance(name, str) and isinstance(id, int) and isinstance(api_key, str):
            self.data: "EndpointData | EndpointDataPartial" = EndpointDataPartial(
                name, id, api_key
            )
        else:
            raise ValueError(
                "Either data or all of name, id, and api_key are required!"
            )
        self.refresh_task: Optional[asyncio.Task[EndpointData]] = None
        self.last_refresh = time.time()
        self.soft_refresh_threshold = soft_refresh_threshold
        self.hard_refresh_threshold = hard_refresh_threshold

    @property
    def name(self):
        return (
            self.data.config.endpoint_name
            if isinstance(self.data, EndpointData)
            else self.data.name
        )

    @property
    def id(self):
        return self.data.id

    @property
    def api_key(self):
        return self.data.api_key

    async def refresh(self, block=False):
        logger.debug("refresh")
        if self.refresh_task is not None:
            if block:
                try:
                    self.data = await self.refresh_task
                finally:
                    self.refresh_task = None
            else:
                try:
                    self.data = self.refresh_task.result()
                    self.refresh_task = None
                except asyncio.InvalidStateError:
                    pass
                except Exception as e:  # refresh task errored, reset it.
                    self.refresh_task = None
                    raise e
        else:
            if block:
                self.data = await self.client.fetch_endpoint(self.data.id)
            else:
                self.refresh_task = asyncio.create_task(
                    self.client.fetch_endpoint(self.data.id)
                )

    def request(
        self,
        route,
        payload,
        serverless_request: Optional[
            Union["ServerlessRequest", "RequestStatus"]
        ] = None,
        cost: int = 100,
        retry: bool = True,
        stream: bool = False,
        timeout: Optional[float] = None,
        session: Optional["Session"] = None,
    ) -> R:
        return self.client.queue_endpoint_request(
            endpoint=self,
            worker_route=route,
            worker_payload=payload,
            serverless_request=serverless_request,
            cost=cost,
            retry=retry,
            stream=stream,
            timeout=timeout,
            session=session,
        )

    def close_session(self, session: "Session"):
        return self.client.end_endpoint_session(session=session)

    async def session_healthcheck(self, session: "Session"):
        result = await self.client.get_endpoint_session(
            endpoint=self, session_id=session.session_id, session_auth=session.auth_data
        )
        return result is not None

    def get_session(self, session_id: int, session_auth: dict, timeout: float = 10):
        return self.client.get_endpoint_session(
            endpoint=self,
            session_id=session_id,
            session_auth=session_auth,
            timeout=timeout,
        )

    def session(
        self,
        cost: int = 100,
        lifetime: float = 60,
        on_close_route: str = None,
        on_close_payload: dict = None,
        timeout: float = None,
    ) -> "Session":
        return self.client.start_endpoint_session(
            endpoint=self,
            cost=cost,
            lifetime=lifetime,
            on_close_route=on_close_route,
            on_close_payload=on_close_payload,
            timeout=timeout,
        )

    def get_workers(self):
        return self.client.get_endpoint_workers(self)

    async def _route(
        self, cost: float = 0.0, req_idx: int = 0, timeout: float = 60.0
    ) -> "RouteResponse":
        await self.client._get_session()
        if time.time() > self.last_refresh + self.soft_refresh_threshold:
            await self.refresh(
                block=time.time() > self.last_refresh + self.hard_refresh_threshold
            )
        try:
            result = await _make_request(
                client=self.client,
                url=self.client.autoscaler_url,
                route="/route/",
                api_key=self.data.api_key,
                body={
                    "endpoint": self.name,
                    "api_key": self.data.api_key,
                    "cost": cost,
                    "request_idx": req_idx,
                    "replay_timeout": timeout,
                },
                method="POST",
                timeout=10.0,
                retries=1,
                stream=False,
            )
        except Exception as ex:
            raise RuntimeError(f"Failed to route endpoint: {ex}") from ex

        if not result.get("ok"):
            raise RuntimeError(
                f"Failed to route endpoint: HTTP {result.get('status')} - {result.get('text', '')[:512]}"
            )

        return RouteResponse(result.get("json") or {})


class RouteResponse:
    status: str
    body: dict
    request_idx: int

    def __repr__(self):
        return f"<RouteResponse status={self.status}>"

    def __init__(self, body: dict):
        if "request_idx" in body.keys():
            self.request_idx = body.get("request_idx")
        else:
            self.request_idx = 0
        if "url" in body.keys():
            self.status = "READY"
            self.body = body
        else:
            self.status = "WAITING"
            self.body = body

    def get_url(self):
        return self.body.get("url")


# Backward-compatible alias — works for instantiation at runtime.
# Static analysis infers the R parameter from the client argument to __init__.
Endpoint = Endpoint_
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