Skip to content

vast-ai/vast-sdk

Repository files navigation

Vast.ai Python SDK

PyPI version

The official Vast.ai SDK pip package.

Install

pip install vastai-sdk

Examples

NOTE: Ensure your Vast.ai API key is set in your working environment as VAST_API_KEY. Alternatively, you may pass the API key in as a parameter to either client.

Using the VastAI CLI client

  1. Create the client
from vastai import VastAI
vastai = VastAI() # or, VastAI("YOUR_API_KEY")
  1. Run commands
vastai.search_offers()
  1. Get help
help(v.create_instances)

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 = {
                "input" : {
                    "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