Skip to content

vast-ai/vast-sdk

Repository files navigation

Vast.ai Python SDK

This repo is deprecated. It has been merged into vast-ai/vast-cli. pip install vastai now installs both the SDK and CLI in a single package. pip install vastai-sdk still works and installs the same package. For issues and PRs, go to vast-ai/vast-cli.

Install

pip install vastai

Note: pip install vastai-sdk also works and installs the same package. Both package names are supported for backward compatibility.

Quickstart

  1. Get your API key from https://cloud.vast.ai/manage-keys/

  2. Set your API key:

from vastai import VastAI
vast = VastAI(api_key="YOUR_API_KEY")

Or set the VAST_API_KEY environment variable and just use:

vast = VastAI()

SDK Usage

from vastai import VastAI

vast = VastAI()  # uses VAST_API_KEY env var, or pass api_key="..."

vast.search_offers(query='gpu_name=RTX_4090 num_gpus>=4')
vast.show_instances()
vast.start_instance(id=12345)
vast.stop_instance(id=12345)

Use help(vast.search_offers) to view documentation for any method.

Migrating from vastai-sdk? The old import still works: from vastai_sdk import VastAI

Using the Serverless Client

  1. Create the client
from vastai import Serverless
serverless = Serverless() # or, Serverless("YOUR_API_KEY")
  1. Get an endpoint
endpoint = await serverless.get_endpoint("my-endpoint")
  1. Make a request
request_body = {
    "model": "Qwen/Qwen3-8B",
    "prompt" : "Who are you?",
    "max_tokens" : 100,
    "temperature" : 0.7
}
response = await serverless.request("/v1/completions", request_body)
  1. Read the response
text = response["response"]["choices"][0]["text"]
print(text)

Find more examples in the examples/ directory.

Contributing

This repo is deprecated. For issues, PRs, and documentation, go to vast-ai/vast-cli.

Packages

 
 
 

Contributors

Languages