The official Vast.ai SDK pip package.
pip install vastai-sdkNOTE: 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.
- Create the client
from vastai import VastAI
vastai = VastAI() # or, VastAI("YOUR_API_KEY")- Run commands
vastai.search_offers()- Get help
help(v.create_instances)- Create the client
from vastai import Serverless
serverless = Serverless() # or, Serverless("YOUR_API_KEY")- Get an endpoint
endpoint = await serverless.get_endpoint("my-endpoint")- 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)- Read the response
text = response["response"]["choices"][0]["text"]
print(text)Find more examples in the examples directory