octaspace 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +93 -30
- data/LICENSE +21 -0
- data/README.md +104 -289
- data/lib/octaspace/client.rb +40 -23
- data/lib/octaspace/configuration.rb +73 -14
- data/lib/octaspace/errors.rb +70 -39
- data/lib/octaspace/json_null.rb +56 -0
- data/lib/octaspace/middleware/url_rotator.rb +3 -3
- data/lib/octaspace/model.rb +115 -0
- data/lib/octaspace/money.rb +69 -0
- data/lib/octaspace/railtie.rb +1 -2
- data/lib/octaspace/resources/accounts.rb +8 -20
- data/lib/octaspace/resources/base.rb +49 -2
- data/lib/octaspace/resources/compute.rb +123 -0
- data/lib/octaspace/resources/hosting.rb +107 -0
- data/lib/octaspace/resources/network.rb +24 -5
- data/lib/octaspace/resources/render.rb +46 -0
- data/lib/octaspace/resources/sessions.rb +125 -10
- data/lib/octaspace/resources/stats.rb +57 -0
- data/lib/octaspace/resources/vpn.rb +48 -0
- data/lib/octaspace/response.rb +62 -12
- data/lib/octaspace/transport/base.rb +30 -30
- data/lib/octaspace/transport/faraday_transport.rb +157 -91
- data/lib/octaspace/transport/persistent_transport.rb +23 -49
- data/lib/octaspace/types/account.rb +17 -4
- data/lib/octaspace/types/hosting.rb +116 -0
- data/lib/octaspace/types/machines.rb +158 -0
- data/lib/octaspace/types/network.rb +87 -0
- data/lib/octaspace/types/session.rb +173 -4
- data/lib/octaspace/types/stats.rb +143 -0
- data/lib/octaspace/version.rb +1 -1
- data/lib/octaspace.rb +21 -19
- metadata +30 -35
- data/MIT-LICENSE +0 -22
- data/lib/octaspace/payload_helpers.rb +0 -53
- data/lib/octaspace/resources/apps.rb +0 -19
- data/lib/octaspace/resources/idle_jobs.rb +0 -32
- data/lib/octaspace/resources/nodes.rb +0 -63
- data/lib/octaspace/resources/services/machine_rental.rb +0 -78
- data/lib/octaspace/resources/services/render.rb +0 -30
- data/lib/octaspace/resources/services/session_proxy.rb +0 -54
- data/lib/octaspace/resources/services/vpn.rb +0 -30
- data/lib/octaspace/resources/services.rb +0 -39
- data/lib/octaspace/types/balance.rb +0 -11
- data/lib/octaspace/types/node.rb +0 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f25e5f1a46bb6780c2ddc35b1641d001a91e8846f74d6714711be25d4facf034
|
|
4
|
+
data.tar.gz: ff9fa708b0a95f2d32df623e823c474b7d30e4c8c298dd57c013a1bdc03a7c98
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a15f98cfb00b8646fadc39f342f126e97f52ffbf399acfd59be64afcdd718bb5a46f7c58578f1ecaa6d80551f3c97193fa0e8c594a05f99f6336d6afe74e5186
|
|
7
|
+
data.tar.gz: 85fe51b96d0c7e2ed579d12d25f0640a37946caa4d13d7267edcbadecda1f5e0a2044e185b7fca3d54348727e56d1cdea889b859acac912cd5aa95d3d30f023c
|
data/CHANGELOG.md
CHANGED
|
@@ -1,50 +1,113 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
All notable changes to this project
|
|
3
|
+
All notable changes to this project are documented in this file.
|
|
4
4
|
|
|
5
|
-
The format
|
|
6
|
-
and
|
|
5
|
+
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and the project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.3.0] - 2026-11-27
|
|
9
|
+
|
|
10
|
+
The SDK follows the current OctaSpace API. Most resources changed; see the
|
|
11
|
+
[resources](docs/resources.md) and [sessions](docs/sessions.md) guides.
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- `client.compute`: `list`, `apps`, `start`, `start_batch` and `restart`.
|
|
16
|
+
- `client.vpn`: `list` and `start` (WireGuard, AmneziaWG, VLESS Reality and
|
|
17
|
+
HTTP proxy).
|
|
18
|
+
- `client.render`: `list`, `start` and `start_batch`.
|
|
19
|
+
- `client.sessions`: `get`, `logs`, `stop`, `wait_ready` and `wait_stopped`;
|
|
20
|
+
VPN sessions.
|
|
21
|
+
- `client.hosting`: `nodes`, `get`, `set_prices`, `start_maintenance` and
|
|
22
|
+
`end_maintenance`.
|
|
23
|
+
- `client.network.history`, with `points`.
|
|
24
|
+
- `client.stats`: `gpu_current`, `gpu_history`, `gpu_locations` and `mining`.
|
|
25
|
+
- Read-only response models under `OctaSpace::Types`, with `[]`, `to_h` and
|
|
26
|
+
pattern matching.
|
|
27
|
+
- `OctaSpace::Money` for amounts in micro-USD.
|
|
28
|
+
- `ConflictError` (HTTP 409), `SessionStoppedError` and `WaitTimeoutError`.
|
|
29
|
+
- `retry_after`, `rate_limit` and `body` on `ApiError`, and `client.rate_limit`.
|
|
30
|
+
- The `max_retry_after` and `max_retry_interval` options.
|
|
31
|
+
- `OctaSpace::DEFAULT_BASE_URL` constant.
|
|
32
|
+
- The `OCTA_API_KEY` and `OCTA_API_URL` environment variables set the default
|
|
33
|
+
API key and host.
|
|
34
|
+
- Guides under `docs/`.
|
|
35
|
+
|
|
36
|
+
### Changed
|
|
37
|
+
|
|
38
|
+
- **Breaking:** the API key is sent as `Authorization: Bearer <key>`. A key
|
|
39
|
+
that already has the `Bearer ` prefix is accepted.
|
|
40
|
+
- **Breaking:** the SDK works with the current OctaSpace API at
|
|
41
|
+
`https://api.octa.space` (`DEFAULT_BASE_URL`).
|
|
42
|
+
- **Breaking:** nodes are identified by their node number, for example
|
|
43
|
+
`7KQ4-M2XD-4`.
|
|
44
|
+
- **Breaking:** prices, charges and the balance are integer micro-USD.
|
|
45
|
+
- **Breaking:** resource methods return models, session UUIDs or `nil` instead
|
|
46
|
+
of `OctaSpace::Response`.
|
|
47
|
+
- **Breaking:** `sessions.list` takes no parameters and returns running
|
|
48
|
+
sessions only.
|
|
49
|
+
- **Breaking:** HTTP 400 raises `ValidationError`, and the error message is the
|
|
50
|
+
API's message.
|
|
51
|
+
- **Breaking:** only GET requests, `sessions.stop` and node maintenance are
|
|
52
|
+
retried; starting and restarting sessions and setting prices are never
|
|
53
|
+
retried. A `Retry-After` longer than 60 seconds raises the error at once.
|
|
54
|
+
- **Breaking:** a method that needs an API key raises `AuthenticationError`
|
|
55
|
+
before sending a request when none is configured.
|
|
56
|
+
- **Breaking:** an unknown parameter raises `ArgumentError` before the request
|
|
57
|
+
is sent.
|
|
58
|
+
- Every request carries the `X-OCTA-APP: ruby-sdk` header.
|
|
59
|
+
- **Breaking:** `on_request` no longer receives the request headers. The log
|
|
60
|
+
never contains headers or bodies.
|
|
61
|
+
- **Breaking:** requires Ruby 3.3 or later and Faraday 2.14.3 or later;
|
|
62
|
+
`faraday-retry` is no longer a dependency.
|
|
63
|
+
|
|
64
|
+
### Removed
|
|
65
|
+
|
|
66
|
+
- **Breaking:** `client.nodes`, `client.apps`, `client.idle_jobs`,
|
|
67
|
+
`client.services`, `accounts.profile` and `accounts.generate_wallet`, with
|
|
68
|
+
their types. Hosted nodes and their prices are in `client.hosting`, sessions
|
|
69
|
+
in `client.sessions`.
|
|
70
|
+
- **Breaking:** `ProvisionRejectedError`, `PayloadHelpers`,
|
|
71
|
+
`Transport::MockTransport`, the `OctaSpace::Engine` playground and the
|
|
72
|
+
`persistent` configuration alias of `keep_alive`.
|
|
7
73
|
|
|
8
74
|
## [0.2.0] - 2026-04-16
|
|
9
75
|
|
|
10
76
|
### Added
|
|
11
77
|
|
|
12
|
-
-
|
|
13
|
-
|
|
14
|
-
- `OctaSpace::
|
|
15
|
-
|
|
16
|
-
-
|
|
78
|
+
- `client.services.session(uuid).logs(recent: true)` for the logs of a finished
|
|
79
|
+
session.
|
|
80
|
+
- `OctaSpace::ProvisionRejectedError` for machine rental requests that the API
|
|
81
|
+
accepts but rejects in the response body.
|
|
82
|
+
- `OctaSpace::PayloadHelpers` for app port lists sent as strings and for
|
|
83
|
+
marketplace bandwidth values.
|
|
17
84
|
|
|
18
85
|
### Changed
|
|
19
86
|
|
|
20
|
-
- `services.mr.list`, `services.render.list
|
|
21
|
-
|
|
22
|
-
-
|
|
23
|
-
- Playground and README copy now reflect live API quirks for app ports, recent sessions, and finished-session logs.
|
|
24
|
-
- Publishing guidance now uses an explicit manual release flow, and the local `rake release` helper is disabled to avoid accidental RubyGems publication.
|
|
87
|
+
- `services.mr.list`, `services.render.list` and `services.vpn.list` return
|
|
88
|
+
the marketplace catalog, not sessions.
|
|
89
|
+
- `services.mr.create` passes the optional `organization_id` and `project_id`.
|
|
25
90
|
|
|
26
91
|
### Fixed
|
|
27
92
|
|
|
28
|
-
-
|
|
29
|
-
|
|
30
|
-
- Corrected fixtures and tests that modeled `/services/mr` and `/services/vpn` as session lists.
|
|
31
|
-
- Corrected logs fixtures and tests to match the live `{system, container}` payload shape.
|
|
32
|
-
- Corrected the playground Apps page so port counts work when the live API returns stringified JSON arrays.
|
|
33
|
-
- Corrected test coverage for `sessions?recent=true` by using live-shaped string telemetry fields.
|
|
93
|
+
- `services.mr.create` raises `ProvisionRejectedError` for a rejection returned
|
|
94
|
+
with HTTP 200.
|
|
34
95
|
|
|
35
96
|
## [0.1.0] - 2026-04-12
|
|
36
97
|
|
|
98
|
+
First release.
|
|
99
|
+
|
|
37
100
|
### Added
|
|
38
101
|
|
|
39
|
-
-
|
|
40
|
-
|
|
41
|
-
-
|
|
42
|
-
-
|
|
43
|
-
-
|
|
44
|
-
-
|
|
45
|
-
-
|
|
46
|
-
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
[0.2.0]: https://github.com/octaspace/ruby-sdk/compare/v0.1.0...
|
|
102
|
+
- `OctaSpace::Client` and `OctaSpace.configure`, with accounts, nodes,
|
|
103
|
+
sessions, apps, network, idle jobs and services resources.
|
|
104
|
+
- Persistent HTTP connections with a connection pool (`keep_alive`).
|
|
105
|
+
- Failover between several base URLs.
|
|
106
|
+
- Retries with exponential backoff and jitter for transient errors.
|
|
107
|
+
- Typed errors mapped from HTTP status codes.
|
|
108
|
+
- Rails integration: a shared client that is shut down when the process exits.
|
|
109
|
+
- A playground Rails engine for trying the API.
|
|
110
|
+
|
|
111
|
+
[0.3.0]: https://github.com/octaspace/ruby-sdk/compare/v0.2.0...v0.3.0
|
|
112
|
+
[0.2.0]: https://github.com/octaspace/ruby-sdk/compare/v0.1.0...v0.2.0
|
|
50
113
|
[0.1.0]: https://github.com/octaspace/ruby-sdk/releases/tag/v0.1.0
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 OctaSpace
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
|
@@ -1,340 +1,155 @@
|
|
|
1
|
-
#
|
|
1
|
+
# OctaSpace Ruby SDK
|
|
2
2
|
|
|
3
3
|
[](https://rubygems.org/gems/octaspace)
|
|
4
4
|
[](https://github.com/octaspace/ruby-sdk/actions/workflows/ci.yml)
|
|
5
|
-
[](
|
|
5
|
+
[](LICENSE)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
The official Ruby library for the [OctaSpace](https://octa.space) API. Rent
|
|
8
|
+
compute machines, render nodes and VPN, manage sessions and the nodes you host,
|
|
9
|
+
and read platform, GPU market and mining statistics from Ruby code.
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
- **URL rotation / failover** — round-robin across multiple endpoints with per-URL cooldown
|
|
14
|
-
- **Retry with exponential backoff + jitter** — configurable retries on transient failures
|
|
15
|
-
- **Typed error hierarchy** — 12 exception classes mapped from HTTP status codes
|
|
16
|
-
- **`on_request` / `on_response` hooks** — for logging, tracing, APM
|
|
17
|
-
- **Rails integration** — Railtie, shared client, graceful shutdown at_exit
|
|
18
|
-
- **Playground app** — `bin/playground` with live diagnostics page
|
|
19
|
-
- **Ruby ≥ 3.2**, Rails 7.1 / 7.2 / 8.0
|
|
11
|
+
**Contents:** [Installation](#installation) ·
|
|
12
|
+
[Quick start](#quick-start) · [Authentication](#authentication) ·
|
|
13
|
+
[Handling errors](#handling-errors) · [API overview](#api-overview) ·
|
|
14
|
+
[Documentation](#documentation) · [Versioning](#versioning)
|
|
20
15
|
|
|
21
16
|
## Installation
|
|
22
17
|
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
gem "octaspace"
|
|
26
|
-
|
|
27
|
-
# Optional — required for keep_alive: true
|
|
28
|
-
gem "faraday-net_http_persistent"
|
|
29
|
-
gem "connection_pool"
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
```ruby
|
|
33
|
-
bundle install
|
|
18
|
+
```bash
|
|
19
|
+
bundle add octaspace
|
|
34
20
|
```
|
|
35
21
|
|
|
36
|
-
|
|
22
|
+
Requires Ruby 3.3 or later. The only runtime dependency is
|
|
23
|
+
[Faraday](https://github.com/lostisland/faraday).
|
|
37
24
|
|
|
38
|
-
|
|
39
|
-
require "octaspace"
|
|
25
|
+
## Quick start
|
|
40
26
|
|
|
41
|
-
|
|
42
|
-
client = OctaSpace::Client.new
|
|
43
|
-
client.network.info # GET /network
|
|
27
|
+
1. [Create an API key](#authentication) and export it:
|
|
44
28
|
|
|
45
|
-
|
|
46
|
-
|
|
29
|
+
```bash
|
|
30
|
+
export OCTA_API_KEY="octa_ak_..."
|
|
31
|
+
```
|
|
47
32
|
|
|
48
|
-
|
|
49
|
-
client.accounts.profile # GET /accounts
|
|
50
|
-
client.accounts.balance # GET /accounts/balance
|
|
51
|
-
|
|
52
|
-
# Nodes
|
|
53
|
-
client.nodes.list # GET /nodes
|
|
54
|
-
client.nodes.find(123) # GET /nodes/:id
|
|
55
|
-
client.nodes.reboot(123) # GET /nodes/:id/reboot
|
|
56
|
-
client.nodes.update_prices(123, gpu_hour: 0.5) # PATCH /nodes/:id/prices
|
|
57
|
-
|
|
58
|
-
# Sessions (list)
|
|
59
|
-
client.sessions.list # GET /sessions
|
|
60
|
-
|
|
61
|
-
# Session proxy — operations on a specific session
|
|
62
|
-
session = client.services.session("uuid-here")
|
|
63
|
-
session.info # GET /services/:uuid/info
|
|
64
|
-
session.logs # GET /services/:uuid/logs
|
|
65
|
-
session.logs(recent: true) # GET /services/:uuid/logs?recent=true for finished sessions
|
|
66
|
-
session.stop(score: 5) # POST /services/:uuid/stop
|
|
67
|
-
|
|
68
|
-
# Services
|
|
69
|
-
client.services.mr.list # GET /services/mr (marketplace machine catalog)
|
|
70
|
-
client.services.mr.create(
|
|
71
|
-
node_id: 1,
|
|
72
|
-
disk_size: 10,
|
|
73
|
-
image: "ubuntu:24.04",
|
|
74
|
-
app: "249b4cb3-3db1-4c06-98a4-772ba88cd81c"
|
|
75
|
-
) # POST /services/mr
|
|
76
|
-
client.services.vpn.list # GET /services/vpn (VPN relay catalog)
|
|
77
|
-
client.services.vpn.create(node_id: 1, subkind: "wg") # POST /services/vpn
|
|
78
|
-
client.services.render.list # GET /services/render
|
|
79
|
-
client.services.render.create(node_id: 1, disk_size: 100) # POST /services/render
|
|
80
|
-
|
|
81
|
-
# Apps
|
|
82
|
-
client.apps.list # GET /apps
|
|
83
|
-
|
|
84
|
-
# Note: live API may serialize app port lists as JSON strings
|
|
85
|
-
# (for example "[]"). The raw response is preserved by the SDK.
|
|
86
|
-
|
|
87
|
-
# Network
|
|
88
|
-
client.network.info # GET /network
|
|
89
|
-
|
|
90
|
-
# Idle Jobs
|
|
91
|
-
client.idle_jobs.find(node_id: 69, job_id: 42) # GET /idle_jobs/:node_id/:job_id
|
|
92
|
-
client.idle_jobs.logs(node_id: 69, job_id: 42) # GET /idle_jobs/:node_id/:job_id/logs
|
|
93
|
-
```
|
|
33
|
+
2. Run this program:
|
|
94
34
|
|
|
95
|
-
|
|
35
|
+
```ruby
|
|
36
|
+
require "octaspace"
|
|
96
37
|
|
|
97
|
-
|
|
38
|
+
client = OctaSpace::Client.new(api_key: ENV["OCTA_API_KEY"])
|
|
98
39
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
config.api_key = ENV["OCTA_API_KEY"]
|
|
103
|
-
config.keep_alive = true
|
|
104
|
-
config.pool_size = ENV.fetch("RAILS_MAX_THREADS", 5).to_i
|
|
105
|
-
config.logger = Rails.logger
|
|
106
|
-
end
|
|
107
|
-
```
|
|
40
|
+
begin
|
|
41
|
+
balance = client.accounts.balance
|
|
42
|
+
puts "Balance: #{balance.formatted}" # Balance: $12.500000
|
|
108
43
|
|
|
109
|
-
|
|
44
|
+
client.compute.list.each do |m|
|
|
45
|
+
puts "#{m.node_number} #{m.city} #{OctaSpace::Money.format(m.base_price)} per hour"
|
|
46
|
+
end
|
|
47
|
+
rescue OctaSpace::Error => e
|
|
48
|
+
abort e.message
|
|
49
|
+
end
|
|
50
|
+
```
|
|
110
51
|
|
|
111
|
-
|
|
52
|
+
Create one client and reuse it: it is safe to share between threads.
|
|
112
53
|
|
|
113
|
-
|
|
114
|
-
# app/controllers/application_controller.rb
|
|
115
|
-
def octa_client
|
|
116
|
-
OctaSpace.client # returns the same instance each time — no new connections
|
|
117
|
-
end
|
|
118
|
-
```
|
|
54
|
+
## Authentication
|
|
119
55
|
|
|
120
|
-
|
|
56
|
+
The SDK authenticates with an **API key** of your OctaSpace account. You create
|
|
57
|
+
and delete API keys in the OctaSpace dashboard:
|
|
121
58
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
59
|
+
1. Sign in to the [OctaSpace dashboard](https://console.octa.space).
|
|
60
|
+
2. In the sidebar, open **Account → Credentials**.
|
|
61
|
+
3. In the **API Keys** section, click **Add API Key**.
|
|
62
|
+
4. Enter a **Label** that tells you where the key is used, for example
|
|
63
|
+
`billing-service`, and click **Create key**.
|
|
64
|
+
5. Copy the key. It starts with `octa_ak_`. You can copy it again later from
|
|
65
|
+
the **API Keys** list.
|
|
125
66
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
## Configuration Reference
|
|
131
|
-
|
|
132
|
-
| Option | Default | Description |
|
|
133
|
-
|---|---|---|
|
|
134
|
-
| `api_key` | `nil` | API key sent as `Authorization` header (optional for public endpoints) |
|
|
135
|
-
| `base_url` | `https://api.octa.space` | Single API endpoint |
|
|
136
|
-
| `base_urls` | `nil` | Multiple endpoints — enables URL rotation |
|
|
137
|
-
| `keep_alive` | `false` | Persistent HTTP connections + pool |
|
|
138
|
-
| `pool_size` | `5` | Connection pool size (keep-alive mode) |
|
|
139
|
-
| `pool_timeout` | `5` | Seconds to wait for a pool slot |
|
|
140
|
-
| `idle_timeout` | `60` | Seconds before an idle connection closes |
|
|
141
|
-
| `open_timeout` | `10` | Seconds to open TCP connection |
|
|
142
|
-
| `read_timeout` | `30` | Seconds to read response |
|
|
143
|
-
| `write_timeout` | `30` | Seconds to write request body |
|
|
144
|
-
| `max_retries` | `2` | Retry attempts on transient failures |
|
|
145
|
-
| `retry_interval` | `0.5` | Base retry interval in seconds |
|
|
146
|
-
| `backoff_factor` | `2.0` | Exponential backoff multiplier |
|
|
147
|
-
| `ssl_verify` | `true` | Verify SSL certificates |
|
|
148
|
-
| `on_request` | `nil` | `callable(req_hash)` — before each request |
|
|
149
|
-
| `on_response` | `nil` | `callable(response)` — after each response |
|
|
150
|
-
| `logger` | `nil` | Ruby `Logger` instance |
|
|
151
|
-
| `log_level` | `:info` | Log level |
|
|
152
|
-
| `user_agent` | auto | `User-Agent` header value |
|
|
153
|
-
|
|
154
|
-
`persistent` is an alias for `keep_alive` for compatibility with Cube internals.
|
|
155
|
-
|
|
156
|
-
## Keep-Alive Mode
|
|
157
|
-
|
|
158
|
-
Requires `faraday-net_http_persistent` and `connection_pool` in your Gemfile.
|
|
67
|
+
Pass the key to `OctaSpace::Client.new`, or set the `OCTA_API_KEY` environment
|
|
68
|
+
variable: a client created without `api_key:` reads it. The SDK sends the key in
|
|
69
|
+
the `Authorization: Bearer <key>` header.
|
|
159
70
|
|
|
160
71
|
```ruby
|
|
161
|
-
client = OctaSpace::Client.new(
|
|
162
|
-
api_key: ENV["OCTA_API_KEY"],
|
|
163
|
-
keep_alive: true,
|
|
164
|
-
pool_size: ENV.fetch("RAILS_MAX_THREADS", 5).to_i,
|
|
165
|
-
idle_timeout: 120
|
|
166
|
-
)
|
|
167
|
-
|
|
168
|
-
# Diagnostics
|
|
169
|
-
client.transport_stats
|
|
170
|
-
# => { mode: :persistent, pools: { "https://api.octa.space" => { size: 5, available: 4 } } }
|
|
171
|
-
|
|
172
|
-
# Explicit shutdown (optional — Railtie does this automatically in Rails)
|
|
173
|
-
client.shutdown
|
|
72
|
+
client = OctaSpace::Client.new(api_key: ENV["OCTA_API_KEY"])
|
|
174
73
|
```
|
|
175
74
|
|
|
176
|
-
|
|
75
|
+
> [!WARNING]
|
|
76
|
+
> An API key acts on behalf of your account: it can start sessions that are
|
|
77
|
+
> charged to your balance. Keep it out of source code and version control. If
|
|
78
|
+
> a key leaks, delete it under **Account → Credentials → API Keys**; every
|
|
79
|
+
> program that uses it stops working at once.
|
|
177
80
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
)
|
|
183
|
-
```
|
|
81
|
+
The **API Keys** list shows each key's label, its first characters and when it
|
|
82
|
+
was last used. Use a separate key for each program or machine, so that you can
|
|
83
|
+
delete one without affecting the others. The number of keys per account is
|
|
84
|
+
limited; the counter next to **API Keys** shows how many you have.
|
|
184
85
|
|
|
185
|
-
|
|
186
|
-
- If an endpoint raises a connection or timeout error, it enters a **30-second cooldown** and traffic shifts to the remaining endpoints.
|
|
187
|
-
- After cooldown, the endpoint is re-admitted automatically.
|
|
86
|
+
### Calls without an API key
|
|
188
87
|
|
|
189
|
-
|
|
88
|
+
These methods also work without an API key. To call them without one, create
|
|
89
|
+
the client with `api_key: ""` (or without `api_key:` when `OCTA_API_KEY` is not
|
|
90
|
+
set):
|
|
190
91
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
92
|
+
| Method | Without a key |
|
|
93
|
+
| --- | --- |
|
|
94
|
+
| `network.info`, `network.history` | Same result |
|
|
95
|
+
| `stats.gpu_current`, `stats.gpu_history`, `stats.gpu_locations`, `stats.mining` | Same result |
|
|
96
|
+
| `compute.list`, `render.list`, `vpn.list` | Refreshed about once an hour instead of every 10 seconds |
|
|
97
|
+
| `compute.apps` | Official apps only, without your own |
|
|
98
|
+
|
|
99
|
+
Every other method requires an API key and raises
|
|
100
|
+
`OctaSpace::AuthenticationError` without one, before any request is sent.
|
|
197
101
|
|
|
198
|
-
|
|
199
|
-
`on_response` receives an `OctaSpace::Response` instance.
|
|
102
|
+
## Handling errors
|
|
200
103
|
|
|
201
|
-
|
|
104
|
+
Every error the SDK raises is an `OctaSpace::Error`. Rescue the specific class
|
|
105
|
+
you can handle:
|
|
202
106
|
|
|
203
107
|
```ruby
|
|
204
108
|
begin
|
|
205
|
-
client.
|
|
206
|
-
rescue OctaSpace::NotFoundError => e
|
|
207
|
-
puts "Not found — request_id: #{e.request_id}"
|
|
109
|
+
uuid = client.compute.start(node_number: "7KQ4-M2XD-4", image: "ubuntu:24.04")
|
|
208
110
|
rescue OctaSpace::AuthenticationError
|
|
209
|
-
|
|
111
|
+
# the API key is missing, wrong or deleted
|
|
112
|
+
rescue OctaSpace::ValidationError => e
|
|
113
|
+
# the request was rejected; e.message says why
|
|
210
114
|
rescue OctaSpace::RateLimitError => e
|
|
211
|
-
|
|
212
|
-
retry
|
|
213
|
-
rescue OctaSpace::ConnectionError, OctaSpace::TimeoutError => e
|
|
214
|
-
puts "Network error: #{e.message}"
|
|
215
|
-
rescue OctaSpace::Error => e
|
|
216
|
-
puts "API error #{e.status}: #{e.message}"
|
|
115
|
+
# too many requests; wait e.retry_after seconds
|
|
217
116
|
end
|
|
218
117
|
```
|
|
219
118
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
```
|
|
223
|
-
OctaSpace::Error
|
|
224
|
-
├── ConfigurationError — missing gems, invalid config
|
|
225
|
-
├── NetworkError — no HTTP response received
|
|
226
|
-
│ ├── ConnectionError — TCP connection refused / failed
|
|
227
|
-
│ └── TimeoutError — open/read timeout
|
|
228
|
-
└── ApiError — HTTP response received with error status
|
|
229
|
-
├── AuthenticationError 401
|
|
230
|
-
├── PermissionError 403
|
|
231
|
-
├── NotFoundError 404
|
|
232
|
-
├── ValidationError 422
|
|
233
|
-
├── RateLimitError 429 → #retry_after (seconds)
|
|
234
|
-
└── ServerError 5xx
|
|
235
|
-
├── BadGatewayError 502
|
|
236
|
-
├── ServiceUnavailableError 503
|
|
237
|
-
└── GatewayTimeoutError 504
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
All `ApiError` subclasses expose:
|
|
119
|
+
See [Errors, rate limits and retries](docs/errors-and-reliability.md).
|
|
241
120
|
|
|
242
|
-
|
|
243
|
-
- `#request_id` — value of `X-Request-Id` response header
|
|
244
|
-
- `#response` — the raw `OctaSpace::Response` object
|
|
121
|
+
## API overview
|
|
245
122
|
|
|
246
|
-
|
|
123
|
+
| Resource | Dashboard section | Operations | Guide |
|
|
124
|
+
| --- | --- | --- | --- |
|
|
125
|
+
| `client.compute` | Marketplace → Compute, Applications | List machines and apps, start, batch start, restart | [Compute](docs/resources.md#compute) |
|
|
126
|
+
| `client.vpn` | Marketplace → VPN | List VPN nodes, start | [VPN](docs/resources.md#vpn) |
|
|
127
|
+
| `client.render` | Render → Launch Nodes | List render nodes, start, batch start | [Render](docs/resources.md#render) |
|
|
128
|
+
| `client.sessions` | Marketplace → Sessions, Render → Render Nodes | List, get, logs, stop, wait until ready or stopped | [Sessions](docs/sessions.md) |
|
|
129
|
+
| `client.hosting` | Hosting → Nodes | Your nodes, one node, set prices, maintenance | [Hosting](docs/resources.md#hosting) |
|
|
130
|
+
| `client.accounts` | Account → Billing | Balance | [Accounts](docs/resources.md#accounts) |
|
|
131
|
+
| `client.network` | — | Platform statistics now and over time | [Network](docs/resources.md#network) |
|
|
132
|
+
| `client.stats` | Marketplace → Mining | GPU market: current, history, locations; mining | [Stats](docs/resources.md#stats) |
|
|
247
133
|
|
|
248
|
-
|
|
134
|
+
Every class and method is documented on
|
|
135
|
+
[RubyDoc.info](https://rubydoc.info/gems/octaspace).
|
|
249
136
|
|
|
250
|
-
|
|
251
|
-
response = client.nodes.find(123)
|
|
252
|
-
node = OctaSpace::Types::Node.new(**response.data.transform_keys(&:to_sym))
|
|
253
|
-
|
|
254
|
-
node.online? # => true / false
|
|
255
|
-
node.state # => "online"
|
|
256
|
-
node.id # => 123
|
|
257
|
-
```
|
|
258
|
-
|
|
259
|
-
Available types: `Node`, `Account`, `Balance`, `Session`.
|
|
260
|
-
|
|
261
|
-
## Playground App
|
|
262
|
-
|
|
263
|
-
Interactive demo for manual testing against a real API key:
|
|
264
|
-
|
|
265
|
-
```bash
|
|
266
|
-
OCTA_API_KEY=your_key bin/playground
|
|
267
|
-
# → http://localhost:3000
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
Pages:
|
|
271
|
-
|
|
272
|
-
| Route | Content |
|
|
273
|
-
|---|---|
|
|
274
|
-
| `/playground/account` | Profile + balance |
|
|
275
|
-
| `/playground/nodes` | Node list with state badges |
|
|
276
|
-
| `/playground/sessions` | Current + recent sessions, including live-format quirks |
|
|
277
|
-
| `/playground/services` | Marketplace catalogs for MR, Render, and VPN |
|
|
278
|
-
| `/playground/diagnostics` | Direct SDK method runner for contracts, payloads, transport mode, and pool stats |
|
|
279
|
-
|
|
280
|
-
## Development
|
|
281
|
-
|
|
282
|
-
### Gem Development
|
|
283
|
-
|
|
284
|
-
```bash
|
|
285
|
-
bin/console # IRB with gem loaded
|
|
286
|
-
bundle exec standardrb # lint (StandardRB)
|
|
287
|
-
bundle exec rake test # tests only
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
### Local Standalone Testing
|
|
291
|
-
|
|
292
|
-
You can verify the gem in a clean Ruby environment without Rails:
|
|
293
|
-
|
|
294
|
-
1. Build the gem: `gem build octaspace.gemspec`
|
|
295
|
-
2. Install it locally: `gem install ./octaspace-0.2.0.gem`
|
|
296
|
-
3. Test in IRB:
|
|
297
|
-
|
|
298
|
-
```ruby
|
|
299
|
-
irb
|
|
300
|
-
> require 'octaspace'
|
|
301
|
-
> client = OctaSpace::Client.new # Test public endpoints
|
|
302
|
-
> client.network.info
|
|
303
|
-
> client_auth = OctaSpace::Client.new(api_key: "token") # Test authenticated client
|
|
304
|
-
> client_auth.accounts.profile.data # Retrieving profile data (email, ID, etc.)
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
### Running tests against multiple Rails versions
|
|
308
|
-
|
|
309
|
-
```bash
|
|
310
|
-
bundle exec appraisal rails-7-1 rake test
|
|
311
|
-
bundle exec appraisal rails-7-2 rake test
|
|
312
|
-
bundle exec appraisal rails-8-0 rake test
|
|
313
|
-
```
|
|
314
|
-
|
|
315
|
-
### Dummy Application (Playground)
|
|
316
|
-
|
|
317
|
-
The repository includes a Rails "Dummy" application for manual testing and UI prototyping. It is located in `test/dummy`.
|
|
318
|
-
|
|
319
|
-
To run the dummy app:
|
|
320
|
-
|
|
321
|
-
1. Ensure you have an API key: `export OCTA_API_KEY=your_key`
|
|
322
|
-
2. Run the playground script: `bin/playground` (starts Puma on port 3000)
|
|
323
|
-
3. Visit `http://localhost:3000/playground/diagnostics`
|
|
324
|
-
|
|
325
|
-
You can also run it manually from the directory:
|
|
326
|
-
|
|
327
|
-
```bash
|
|
328
|
-
cd test/dummy
|
|
329
|
-
bin/rails server
|
|
330
|
-
```
|
|
137
|
+
## Documentation
|
|
331
138
|
|
|
332
|
-
|
|
139
|
+
| Guide | Covers |
|
|
140
|
+
| --- | --- |
|
|
141
|
+
| [Client configuration](docs/getting-started.md) | Options and defaults, timeouts, logging, Rails, keep-alive connections |
|
|
142
|
+
| [Resources](docs/resources.md) | Compute, VPN, render, hosting, balance, network, GPU and mining statistics |
|
|
143
|
+
| [Sessions](docs/sessions.md) | Waiting until ready, connecting, logs, stopping |
|
|
144
|
+
| [Errors, rate limits and retries](docs/errors-and-reliability.md) | Error classes, limits, automatic retries |
|
|
145
|
+
| [Changelog](CHANGELOG.md) | Changes in each release |
|
|
333
146
|
|
|
334
|
-
##
|
|
147
|
+
## Versioning
|
|
335
148
|
|
|
336
|
-
|
|
149
|
+
The library follows [Semantic Versioning](https://semver.org). Until version
|
|
150
|
+
1.0, a minor release can contain breaking changes; the
|
|
151
|
+
[changelog](CHANGELOG.md) marks them as **Breaking**.
|
|
337
152
|
|
|
338
153
|
## License
|
|
339
154
|
|
|
340
|
-
[MIT](
|
|
155
|
+
[MIT](LICENSE)
|