The Unikraft Cloud Go SDK is an autogenerated client library that interfaces
with the Unikraft Cloud platform API, based on the public OpenAPI
specification at https://github.com/unikraft-cloud/openapi.
Installation
Code
go get unikraft.com/cloud/sdk
Requires Go 1.27 or later.
Quickstart
main.go
package mainimport ( "context" "fmt" "unikraft.com/cloud/sdk/platform")func main() { ctx := context.Background() // Create a new client. NewClientFromEnv reads the token and default metro // from environment variables (UKC_TOKEN and UKC_METRO). client := platform.NewClientFromEnv() // List all instances resp, err := client.GetInstances(ctx, nil, platform.GetInstancesOpts{}) if err != nil { panic(err) } // Check for API-level errors if resp.Status != platform.ResponseStatusSuccess { panic(resp.Message) } for _, inst := range resp.Data.Instances { fmt.Printf("Name: %s\n", inst.Name) fmt.Printf("UUID: %s\n", inst.Uuid) fmt.Printf("State: %s\n", inst.State) fmt.Printf("Image: %s\n", inst.Image) fmt.Println("---") }}
NewClient uses only the options you pass and doesn't read the environment.
To configure the client from the environment, use NewClientFromEnv.
It reads the token from the first of these environment variables that's set:
UKC_TOKEN
UNIKRAFT_CLOUD_TOKEN
KRAFTCLOUD_TOKEN (legacy name)
It also reads the default metro from the UKC_METRO environment variable.
If not specified, the SDK defaults to fra.
Options you pass to NewClientFromEnv take precedence over the environment.
Code
// Reads UKC_TOKEN (or a fallback) and UKC_METRO from the environmentclient := platform.NewClientFromEnv()
Client options
Option
Description
WithDefaultEndpoint(string)
Full API endpoint address (for example, https://api.fra.unikraft.cloud)
WithDefaultMetro(string)
Metro shorthand—converted to endpoint address automatically
WithToken(string)
API token
WithHTTPClient(...)
Custom http.Client
WithUserAgent(string)
Override the User-Agent header
WithAllowInsecure(bool)
Skip TLS verification (development only)
WithDefaultEndpoint and WithDefaultMetro both set the API endpoint.
Use WithDefaultMetro("fra") as a shorthand for WithDefaultEndpoint("https://api.fra.unikraft.cloud").
The base address is https://api.<metro>.unikraft.cloud.
An existing client also has methods that return a client with one setting changed:
Method
Description
WithMetro(string)
Use a different metro
WithTimeout(time.Duration)
Set the request timeout
WithHTTPClient(...)
Use a different HTTP client
Code
// Query another metro with the same tokenresp, err := client.WithMetro("sfo").GetInstances(ctx, nil, platform.GetInstancesOpts{})
Resources
The platform.Client interface covers the full Unikraft Cloud REST API surface.
In the examples below:
ids is a []platform.NameOrUUID that selects resources by name or UUID.
Passing nil to a list method, such as GetInstances or GetVolumes, returns all resources.
The autoscale read methods are the exception and need at least one service group.
req is the request type that the method takes, for example platform.CreateInstanceRequest or []platform.StartInstancesRequestItem.
platform.<Method>Opts{} holds the optional query parameters, for example platform.GetInstancesOpts{Details: &details, Tags: []string{"production"}}.
// Configuration (by service group UUID)client.CreateAutoscaleConfigurationByServiceGroupUUID(ctx, uuid, req)client.GetAutoscaleConfigurationsByServiceGroupUUID(ctx, uuid)client.DeleteAutoscaleConfigurationsByServiceGroupUUID(ctx, uuid)
In the image methods, req is a list of image references ([]platform.GetImagesRequestTagOrDigest, []platform.PinImageRequestItem or []platform.UnpinImageRequestItem).