Skip to content

clients.vastai #

vastai

To get started



import freeflowuniverse.herolib.clients. vastai

mut client:= vastai.get()!

client...

example heroscript

!!vastai.configure
    secret: '...'
    host: 'localhost'
    port: 8888

Constants #

const version = '1.14.3'

fn get #

fn get(args_ ArgsGet) !&VastAI

fn heroscript_default #

fn heroscript_default() !string

Todo: THIS IS EXAMPLE CODE AND NEEDS TO BE CHANGED IN LINE TO STRUCT BELOW, IS STRUCTURED AS HEROSCRIPT

fn play #

fn play(args_ PlayArgs) !

fn switch #

fn switch(name string)

switch instance to be used for vastai

struct ArgsGet #

@[params]
struct ArgsGet {
pub mut:
	name string
}

///////FACTORY

struct AttachSshKeyToInstanceArgs #

@[params]
struct AttachSshKeyToInstanceArgs {
pub:
	id      int @[required]
	ssh_key string
}

struct AttachSshKeyToInstanceResponse #

struct AttachSshKeyToInstanceResponse {
pub:
	success bool
	msg     string
}

struct CreateInstanceArgs #

@[params]
struct CreateInstanceArgs {
pub:
	id     int
	config CreateInstanceConfig
}

struct CreateInstanceConfig #

@[params]
struct CreateInstanceConfig {
pub:
	template_id      ?string
	template_hash_id ?string
	image            ?string // Docker image name
	disk             ?int
	extra_env        ?map[string]string // Environment variables
	runtype          ?string            // "args" or "ssh"
	onstart          ?string
	label            ?string
	image_login      ?string
	price            ?f32
	target_state     ?string // "running" or "stopped"
	cancel_unavail   ?bool
	vm               ?bool
	client_id        ?string
	apikey_id        ?string
}

CreateInstanceConfig represents the configuration for creating a new instance from an offer

struct CreateInstanceResponse #

struct CreateInstanceResponse {
pub:
	success      bool
	new_contract int
}

CreateInstanceResponse represents the response from creating a new instance

struct DestroyInstanceArgs #

@[params]
struct DestroyInstanceArgs {
pub:
	id int @[required]
}

struct DestroyInstanceResponse #

struct DestroyInstanceResponse {
pub:
	success bool
	msg     string
}

struct GPUOffer #

struct GPUOffer {
pub:
	id                  int    // Unique instance ID
	cuda_max_good       int    // Maximum reliable CUDA version
	gpu_name            string // Name of the GPU
	gpu_ram             int    // GPU RAM in MB
	num_gpus            int    // Number of GPUs
	dlperf              f64    // Deep Learning Performance score
	dlperf_per_dphtotal f64    // Performance per dollar per hour
	reliability         f64    // Instance reliability score
	total_flops         f64    // Total FLOPS
	credit_discount     f64    // Credit discount
	rented              bool   // Whether instance is currently rented
	rentable            bool   // Whether instance can be rented
	verification        string // Verification status
	external            bool   // Whether instance is external
	dph_total           f64    // Total dollars per hour
	storage_total       int    // Total storage in GB
	inet_up             f64    // Upload bandwidth in Mbps
	inet_down           f64    // Download bandwidth in Mbps
}

Represents a GPU offer from Vast.ai

struct LaunchInstanceArgs #

@[params]
struct LaunchInstanceArgs {
pub:
	num_gpus int    @[required]
	gpu_name string @[required]
	region   string @[required]
	image    string @[required]
	disk     int    @[required]
	env      ?string
	args     ?[]string
}

struct PlayArgs #

@[params]
struct PlayArgs {
pub mut:
	heroscript string // if filled in then plbook will be made out of it
	plbook     ?playbook.PlayBook
	reset      bool
}

struct SearchParams #

@[params]
struct SearchParams {
pub mut:
	order           ?string // Sort order (default: score descending)
	query           ?string // Search query string
	min_gpu_ram     ?int    // Minimum GPU RAM in MB
	min_num_gpus    ?int    // Minimum number of GPUs
	min_dlperf      ?f64    // Minimum deep learning performance score
	max_dph         ?f64    // Maximum dollars per hour
	min_reliability ?f64    // Minimum reliability score
	verified_only   ?bool   // Only show verified instances
	external        ?bool   // Include external instances
	rentable        ?bool   // Show only rentable instances
	rented          ?bool   // Show only rented instances
}

Search parameters for filtering GPU offers

struct StartInstanceArgs #

@[params]
struct StartInstanceArgs {
pub:
	id int @[required]
}

struct StartInstancesArgs #

@[params]
struct StartInstancesArgs {
pub:
	ids []int @[json: 'IDs'; required]
}

struct StartInstancesResponse #

struct StartInstancesResponse {
pub:
	success bool
	msg     string
}

struct StopInstanceArgs #

@[params]
struct StopInstanceArgs {
pub:
	id    int @[required]
	state string
}

struct StopInstanceResponse #

struct StopInstanceResponse {
pub:
	success bool
	msg     string
}

struct VastAI #

@[heap]
struct VastAI {
pub mut:
	name     string = 'default'
	api_key  string
	base_url string
}

THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED

fn (VastAI) attach_sshkey_to_instance #

fn (mut va VastAI) attach_sshkey_to_instance(args AttachSshKeyToInstanceArgs) !AttachSshKeyToInstanceResponse

Attach SSH Key to Instance

fn (VastAI) create_instance #

fn (mut va VastAI) create_instance(args CreateInstanceArgs) !CreateInstanceResponse

Creates a new instance by accepting a provider offer

fn (VastAI) destroy_instance #

fn (mut va VastAI) destroy_instance(args DestroyInstanceArgs) !DestroyInstanceResponse

Destroys an instance.

fn (VastAI) find_cheapest_offers #

fn (mut va VastAI) find_cheapest_offers(min_gpu_ram int, min_gpus int, count int) ![]GPUOffer

Helper method to find cheapest offers meeting minimum requirements

fn (VastAI) find_most_powerful #

fn (mut va VastAI) find_most_powerful(count int) ![]GPUOffer

Helper method to find most powerful GPUs available

fn (VastAI) get_top_offers #

fn (mut v VastAI) get_top_offers(count int) ![]GPUOffer

Helper method to get top N offers sorted by performance/price

fn (VastAI) launch_instance #

fn (mut va VastAI) launch_instance(args LaunchInstanceArgs) !CreateInstanceResponse

Launch an instance, This endpoint launches an instance based on the specified parameters, selecting the first available offer that meets the criteria.

fn (VastAI) search_offers #

fn (mut va VastAI) search_offers(params SearchParams) ![]GPUOffer

Searches for GPU offers based on the provided parameters

fn (VastAI) start_instance #

fn (mut va VastAI) start_instance(args StartInstanceArgs) !StartInstancesResponse

Start Instance, Start an instance specified by its ID.

fn (VastAI) start_instances #

fn (mut va VastAI) start_instances(args StartInstancesArgs) !StartInstancesResponse

Start Instances, Start a list of instances specified by their IDs.

fn (VastAI) stop_instance #

fn (mut va VastAI) stop_instance(args StopInstanceArgs) !StopInstanceResponse

Stops a running container and updates its status to 'stopped'.