---
title: Go SDK
slug: go-sdk
createdAt: 2026-11-25T00:02:22.875Z
---

The official Go library for the OctaSpace API.

- Package: `github.com/octaspace/go-sdk`
- Reference: [pkg.go.dev](https://pkg.go.dev/github.com/octaspace/go-sdk)
- Source and changelog: [GitHub](https://github.com/octaspace/go-sdk)

## Installation

```bash
go get github.com/octaspace/go-sdk
```

Requires Go 1.20 or later. The library depends only on the standard library.

## Create a client

```go
import octaspace "github.com/octaspace/go-sdk"

client := octaspace.NewClient(os.Getenv("OCTA_API_KEY"))
```

Create one client and reuse it: it is safe for concurrent use. Pass an empty key to use only the [public endpoints](#).

### Options

```go
client := octaspace.NewClient(os.Getenv("OCTA_API_KEY"),
	octaspace.WithTimeout(15*time.Second),
	octaspace.WithMaxRetries(3),
	octaspace.WithApp("my-service"),
	octaspace.WithLogger(octaspace.NewStdLogger(log.Default())),
)
```

| Option               | Default                  | Effect                                                                                          |
| -------------------- | ------------------------ | ----------------------------------------------------------------------------------------------- |
| `WithTimeout(d)`     | `30s`                    | Time limit for one method call, retries included                                                |
| `WithMaxRetries(n)`  | `2`                      | Retries of failed GET requests; `0` turns them off                                              |
| `WithUserAgent(ua)`  | `octaspace-go/<version>` | `User-Agent` header                                                                             |
| `WithApp(name)`      | `go-sdk`                 | Names your application in the `X-OCTA-APP` header                                               |
| `WithLogger(l)`      | none                     | Logs method, path, status and duration; the key and bodies are never logged                     |
| `WithHTTPClient(hc)` | tuned `http.Client`      | Your own client, for a proxy or tracing                                                         |
| `WithBaseURL(url)`   | `https://api.octa.space` | Another API host                                                                                |
| `WithBaseURLs(urls)` | none                     | Ordered list of hosts; a call moves to the next one only when the current one cannot be reached |

Every method takes a `context.Context` first. Cancelling it, or reaching its deadline, stops the call and its retries.

## Resources

| Resource          | Methods                                                         |
| ----------------- | --------------------------------------------------------------- |
| `client.Accounts` | `Balance`                                                       |
| `client.Compute`  | `List`, `ListRaw`, `Start`, `StartBatch`, `Restart`             |
| `client.Render`   | `List`, `ListRaw`, `Start`, `StartBatch`                        |
| `client.Sessions` | `List`, `ListRaw`, `Get`, `GetRaw`, `Logs`, `Stop`, `WaitReady` |
| `client.Hosting`  | `Nodes`, `NodesRaw`, `SetPrices`, `SetMaintenance`              |
| `client.Network`  | `Info`, `InfoRaw`                                               |
| `client.Stats`    | `GPUCurrent`, `GPUHistory`, `GPULocations`                      |

VPN, compute apps, network history and mining statistics are not in the Go SDK yet; call those endpoints directly.

## Examples

### Start a session and wait for it

```go
uuid, err := client.Compute.Start(ctx, &octaspace.ComputeStartParams{
	NodeNumber: "7KQ4-M2XD-4",
	Image:      "ubuntu:24.04",
	DiskSize:   20,
	SSH:        octaspace.Bool(true),
})
if err != nil {
	return err
}

waitCtx, cancel := context.WithTimeout(ctx, 10*time.Minute)
defer cancel()

session, err := client.Sessions.WaitReady(waitCtx, uuid, &octaspace.WaitOptions{
	OnProgress: func(s *octaspace.Session) {
		fmt.Println(s.Status, s.Progress)
	},
})
if errors.Is(err, octaspace.ErrSessionStopped) {
	// the session stopped while starting, for example SSH could not be set up
}
```

Optional fields are pointers; set them with `octaspace.Bool`, `octaspace.Int` and `octaspace.Price`, so that `false` and `0` can be sent too.

### Read logs

```go
logs, err := client.Sessions.Logs(ctx, uuid, &octaspace.LogsParams{Tail: 100})
if logs.Container != nil {
	fmt.Print(*logs.Container)
}
for _, e := range logs.System {
	fmt.Println(e.Time(), e.Msg)
}
```

### Set node prices

```go
err := client.Hosting.SetPrices(ctx, "7KQ4-M2XD-4", octaspace.NodePrices{
	Base:           octaspace.Price(250_000), // $0.25 per hour
	MinRentMinutes: octaspace.Int(15),
})
```

## Errors

```go
_, err := client.Compute.Start(ctx, params)
switch {
case octaspace.IsAuthError(err):
	// the key is missing, wrong or deleted
case octaspace.IsValidation(err):
	// rejected: err.Error() says why, for example "Insufficient balance"
case octaspace.IsRateLimit(err):
	var rl *octaspace.RateLimitError
	errors.As(err, &rl)
	// wait rl.RetryAfter seconds
case err != nil:
	var apiErr *octaspace.APIError
	if errors.As(err, &apiErr) {
		log.Printf("status %d: %s (request %s)", apiErr.StatusCode, apiErr.Message, apiErr.RequestID)
	}
	return err
}
```

All error types are listed in [Errors and rate limits](#). `client.RateLimit()` returns the rate limit state of the latest response.

GET requests are retried on `429`, `500`, `502`, `503` and `504`. Starts, restarts, stops and price changes are never retried.

## Raw JSON

To read a field the SDK has no model for yet, or to store a response as is, use the `...Raw` methods: `Compute.ListRaw`, `Render.ListRaw`, `Sessions.ListRaw`, `Sessions.GetRaw`, `Hosting.NodesRaw`, `Network.InfoRaw`. They return the body exactly as the API sent it.

## More

The repository has detailed guides: [client configuration](https://github.com/octaspace/go-sdk/blob/main/docs/getting-started.md), [resources](https://github.com/octaspace/go-sdk/blob/main/docs/resources.md), [sessions](https://github.com/octaspace/go-sdk/blob/main/docs/sessions.md), [errors and retries](https://github.com/octaspace/go-sdk/blob/main/docs/errors-and-reliability.md).
