OctaSpace Ruby SDK
The official Ruby library for the OctaSpace API. Rent compute machines, render nodes and VPN, manage sessions and the nodes you host, and read platform, GPU market and mining statistics from Ruby code.
Contents: Installation · Quick start · Authentication · Handling errors · API overview · Documentation · Versioning
Installation
bundle add octaspaceRequires Ruby 3.3 or later. The only runtime dependency is Faraday.
Quick start
-
Create an API key and export it:
export OCTA_API_KEY="octa_ak_..."
-
Run this program:
require "octaspace" client = OctaSpace::Client.new(api_key: ENV["OCTA_API_KEY"]) begin balance = client.accounts.balance puts "Balance: #{balance.formatted}" # Balance: $12.500000 client.compute.list.each do |m| puts "#{m.node_number} #{m.city} #{OctaSpace::Money.format(m.base_price)} per hour" end rescue OctaSpace::Error => e abort e.message end
Create one client and reuse it: it is safe to share between threads.
Authentication
The SDK authenticates with an API key of your OctaSpace account. You create and delete API keys in the OctaSpace dashboard:
- Sign in to the OctaSpace dashboard.
- In the sidebar, open Account → Credentials.
- In the API Keys section, click Add API Key.
- Enter a Label that tells you where the key is used, for example
billing-service, and click Create key. - Copy the key. It starts with
octa_ak_. You can copy it again later from the API Keys list.
Pass the key to OctaSpace::Client.new, or set the OCTA_API_KEY environment
variable: a client created without api_key: reads it. The SDK sends the key in
the Authorization: Bearer <key> header.
client = OctaSpace::Client.new(api_key: ENV["OCTA_API_KEY"])Warning
An API key acts on behalf of your account: it can start sessions that are charged to your balance. Keep it out of source code and version control. If a key leaks, delete it under Account → Credentials → API Keys; every program that uses it stops working at once.
The API Keys list shows each key's label, its first characters and when it was last used. Use a separate key for each program or machine, so that you can delete one without affecting the others. The number of keys per account is limited; the counter next to API Keys shows how many you have.
Calls without an API key
These methods also work without an API key. To call them without one, create
the client with api_key: "" (or without api_key: when OCTA_API_KEY is not
set):
| Method | Without a key |
|---|---|
network.info, network.history
|
Same result |
stats.gpu_current, stats.gpu_history, stats.gpu_locations, stats.mining
|
Same result |
compute.list, render.list, vpn.list
|
Refreshed about once an hour instead of every 10 seconds |
compute.apps |
Official apps only, without your own |
Every other method requires an API key and raises
OctaSpace::AuthenticationError without one, before any request is sent.
Handling errors
Every error the SDK raises is an OctaSpace::Error. Rescue the specific class
you can handle:
begin
uuid = client.compute.start(node_number: "7KQ4-M2XD-4", image: "ubuntu:24.04")
rescue OctaSpace::AuthenticationError
# the API key is missing, wrong or deleted
rescue OctaSpace::ValidationError => e
# the request was rejected; e.message says why
rescue OctaSpace::RateLimitError => e
# too many requests; wait e.retry_after seconds
endSee Errors, rate limits and retries.
API overview
| Resource | Dashboard section | Operations | Guide |
|---|---|---|---|
client.compute |
Marketplace → Compute, Applications | List machines and apps, start, batch start, restart | Compute |
client.vpn |
Marketplace → VPN | List VPN nodes, start | VPN |
client.render |
Render → Launch Nodes | List render nodes, start, batch start | Render |
client.sessions |
Marketplace → Sessions, Render → Render Nodes | List, get, logs, stop, wait until ready or stopped | Sessions |
client.hosting |
Hosting → Nodes | Your nodes, one node, set prices, maintenance | Hosting |
client.accounts |
Account → Billing | Balance | Accounts |
client.network |
— | Platform statistics now and over time | Network |
client.stats |
Marketplace → Mining | GPU market: current, history, locations; mining | Stats |
Every class and method is documented on RubyDoc.info.
Documentation
| Guide | Covers |
|---|---|
| Client configuration | Options and defaults, timeouts, logging, Rails, keep-alive connections |
| Resources | Compute, VPN, render, hosting, balance, network, GPU and mining statistics |
| Sessions | Waiting until ready, connecting, logs, stopping |
| Errors, rate limits and retries | Error classes, limits, automatic retries |
| Changelog | Changes in each release |
Versioning
The library follows Semantic Versioning. Until version 1.0, a minor release can contain breaking changes; the changelog marks them as Breaking.