Sign in
Developer tools
0%

Libraries

SDKs

Client libraries for Rust, TypeScript, Python, Go, C# and Java. Add one to your project, or generate a client with exactly the calls your credentials may make.

Six libraries, all open source in inorbithr/sdk. Each is a hand-written runtime (the client, credentials, retries, errors, streams) plus the API's operations as typed calls. Four are on their language's registry, at the version the table gives; C# and Java are built and tested but not published yet.

LanguagePackageVersionNeedsWhere
Rustinorbithr0.4.0Rust 1.94crates.io
TypeScript@inorbithr/sdk0.3.1Node 22.12, Bun, Deno, browsersnpm, JSR
Pythoninorbithr0.3.2Python 3.11PyPI
Gogithub.com/inorbithr/sdk/go0.3.1Go 1.26pkg.go.dev
C#InOrbit.Sdk0.4.0, source.NET 8build from source; not on NuGet yet
Javahr.inorbit:inorbit-sdk0.3.1, sourceJava 17build from source; not on Maven Central yet

Every library reads its credential from the environment: an API token in INORBIT_TOKEN (made in the console or with iohr token create), or an API key in INORBIT_KEY_ID and INORBIT_KEY_SECRET with the scopes to ask for in INORBIT_SCOPES, which it exchanges for 15-minute tokens and refreshes itself.

Add a library

iohr sdk add adds the library to the project in the current directory with the package manager the project already uses, so each section below shows it first and the package manager's own command beside it. Without a language it finds the project from the current directory up to the repository root (Cargo.toml, package.json or deno.json, pyproject.toml, requirements.txt or a Python lock file, go.mod); when it finds several or none it exits 2 and names the commands. It picks the manager from the project's files: pnpm, yarn, bun or npm by lock file or packageManager, deno add jsr: for deno.json without package.json; uv, poetry or pdm by lock file, otherwise pip only inside an active virtualenv, and it refuses (exit 2) to install into a system Python. cargo add needs a Cargo.toml and go get a go.mod.

iohr sdk add                         # the language and the package manager from the project's files
iohr sdk add go --version <version>   # that release
iohr sdk add --dry-run               # print the command, run nothing
iohr sdk add ts --json               # {"lang", "manager", "dir", "command", "dry_run"}

It always prints the command first, then runs that one program directly in the project directory: no shell, never sudo, the program found only in absolute PATH entries. The exit code is the package manager's. iohr contacts no host for it; the package manager reaches its own registry. C# and Java are refused (exit 1): they are not on NuGet or Maven Central yet.

Rust

iohr sdk add rust     # or: cargo add inorbithr
use inorbithr::{Client, Error, Method, Operation, Response};

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Error> {
    let client: Client = Client::from_env()?;
    let me: Response<serde_json::Value> = client
        .request(Operation::new(Method::Get, "/v1/me"))
        .await?;
    println!("{} ({})", me.value["subject"], me.value["kind"]);
    Ok(())
}

TypeScript

iohr sdk add typescript     # or: npm install @inorbithr/sdk, pnpm add @inorbithr/sdk, deno add jsr:@inorbithr/sdk
import { Public } from "@inorbithr/sdk";

const api = Public.fromEnv();
const { value: me } = await api.me();
const { value: page } = await api.radar.listDigests({ limit: 3 });

ESM only, no dependencies; runs on Node, Bun, Deno, browsers and Workers. 64-bit integers are bigint.

Python

iohr sdk add python     # or: uv add inorbithr, pip install inorbithr in a virtualenv
from inorbithr import Public

api = Public.from_env()
me = api.me().value
digests = api.radar.list_digests(limit=3).value

AsyncPublic is the same on asyncio.

Go

iohr sdk add go     # or: go get github.com/inorbithr/sdk/go@latest
import (
	inorbit "github.com/inorbithr/sdk/go"
	"github.com/inorbithr/sdk/go/public"
)

api, err := public.FromEnv()
if err != nil {
	return err
}
me, err := api.Me(ctx)
var apiErr *inorbit.APIError
if errors.As(err, &apiErr) && apiErr.Code == inorbit.CodeForbidden {
	// the token lacks identity:read
}

inorbit is the runtime; public is the surface an API token or key may call. OpenTelemetry is a separate module, github.com/inorbithr/sdk/go/otel, so the runtime does not depend on it.

C#

InOrbit.Sdk (net8.0) is built and tested in the open, and its NuGet release has not happened yet. Build from source until then, and reference the project:

git clone https://github.com/inorbithr/sdk
dotnet add reference path/to/sdk/csharp/src/InOrbit.Sdk
using InOrbit.Sdk;
using InOrbit.Sdk.Api;

using var client = Client.FromEnv();
var me = (await client.MeAsync()).Value;

Java

hr.inorbit:inorbit-sdk is built and tested in the open, and its Maven Central release has not happened yet. Build from source until then: put it in your local Maven repository and depend on it by the coordinates it will be published under.

git clone https://github.com/inorbithr/sdk && cd sdk
mvn -f java install
<dependency>
  <groupId>hr.inorbit</groupId>
  <artifactId>inorbit-sdk</artifactId>
  <version>VERSION</version> <!-- the version in java/pom.xml -->
</dependency>
Public api = Public.fromEnv();
Me me = api.me().value();

What every library does

  • Authenticates with an API token, or exchanges an API key for a short-lived token, caches it and refreshes it.
  • Returns typed results and one error type per language, carrying the API's error code and details; a code the library does not know yet is kept, not dropped.
  • Retries what is safe to retry (429, 503, 504, connection failures), honouring Retry-After; a write is retried only when the operation is marked safe to repeat.
  • Reads streams over server-sent events or one /v1/ws socket.
  • Behaves the same in every language: one set of conformance cases runs against all six.

Configuration and middleware

Every library has the same configuration and middleware:

  • load (Client::load, Client.load, inorbit.Load, Client.Load) reads settings in one order: code, then INORBIT_* environment variables, then the iohr config file, then defaults. describe() shows each value and where it came from, with secrets redacted; iohr sdk config prints the same for a program on your machine.
  • The credential chain: environment, token and key secret files, then your iohr login (iohr auth token).
  • Proxy, CA bundle, mTLS, key pinning and connect timeout, or your own HTTP client.
  • A named middleware pipeline with built-ins for logging, OpenTelemetry, rate limits and a retry budget.

Writes whose operation takes an Idempotency-Key are retried, with one key per call sent on every attempt, and calls have a 120 s total deadline by default, every attempt and wait included. The settings are in docs/config.md, worked examples in docs/recipes.md.

Generate a client for your account

The API serves each credential its own document: the routes its plan has, narrowed to the scopes it holds. iohr sdk generate turns that document into a client in your repository. The client holds exactly the operations each of your profiles may call, so a call a profile may not make does not compile, and iohr sdk check fails in CI when the set has moved. It writes Rust, TypeScript (and plain JavaScript), Go, Python, C# and Java.

1. Sign in, one profile per account

Install the command line, then sign in once per credential the client will use. A person's sign-in reads their own account; an API token stands for the account it was made in:

iohr login                                      # you, as a person: profile "default"
iohr login --with-token --profile ci < token.txt # an API token for CI, as profile "ci"

A person belongs to several accounts. Point the profile at the team the client is for; a team's id or its slug works, and only a team you belong to is accepted:

iohr accounts list
iohr profile account default acme

2. Generate

iohr sdk generate --lang rust --for default --for ci --out src/iohr

Commit the output directory and the iohr.lock written beside it.

--for names a profile; repeat it to put several accounts in one client. The command fetches each profile's document, writes the client into --out, and writes iohr.lock beside the directory. Nothing in either is a secret: the lock holds profile names, each cut's plan, scopes and hash, and the operations it held.

# iohr.lock: what this surface was generated from. Commit it beside the surface;
# `iohr sdk check` compares it with what the API serves now and says what moved.

generator = "<the iohr version that generated it>"
lang = "rust"
out = "iohr"
api_version = "0.1.0"

[profiles.ci]
cut = "sha256:…"
plan = "free"
scopes = ["radar:read"]
operations = ["GET /v1/radar/digests", "GET /v1/radar/digests/{id}", "GET /v1/radar/items"]

[profiles.default]
cut = "sha256:…"
plan = "free"
account = "…"
operations = ["GET /v1/accounts/me", "GET /v1/me", "GET /v1/radar/digests", "…"]

The output is the same for the same document and the same iohr version, so a regeneration shows as a real diff in review. Regenerate it, never edit it. To work offline, save a document with iohr openapi pull and pass it as --from NAME=FILE.

3. Use it

The generated code sits on each language's library (0.2.0 or later, added as Add a library shows), which does the credentials, retries and errors. Each profile is its own type. Its from_env reads INORBIT_CI_TOKEN, or INORBIT_CI_KEY_ID, INORBIT_CI_KEY_SECRET and INORBIT_CI_SCOPES for an API key, and nothing else, so a client never calls the wrong account:

mod iohr;
use iohr::prelude::*;
use iohr::RadarListDigestsParams;

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Error> {
    let ci = Client::<Ci>::from_env()?;
    let digests = ci.radar().list_digests(&RadarListDigestsParams::default()).await?;
    println!("{} digests, request id {}", digests.value.digests.len(), digests.raw.request_id);
    Ok(())
}

Operations hang off one handle per area (radar, accounts, events), and GET /v1/me is me() on the client. Every answer carries the typed body (value) and the raw answer: status, headers and request ids. Python also has an asyncio class per profile (AsyncCi), Java an ...Async twin of every call, and C# and TypeScript are async throughout.

A call the profile may not make

The ci profile above holds radar:read only, so asking it for the account is refused before the program runs, not with a 403 at run time:

LanguageWhat refuses ci.accounts.get_me()
Rustthe compiler: the profile does not implement the operation's trait
TypeScripttsc: the property does not exist on type Ci (plain JavaScript has no check)
Gothe compiler: the profile's package has no such method
Pythonpyright or mypy: the attribute does not exist on Ci
C#the compiler: Ci does not implement the operation's interface (CS0311)
Javajavac: the method does not exist on the profile's class

The default profile, a person, has it.

Every item of a paged list

A list operation has an iterator beside its page method that follows the next-page token, fetches nothing more once you stop, and stops at the first error (paging):

let mut pages = ci.radar().all_list_digests(&RadarListDigestsParams::default());
while let Some(digest) = pages.next().await {
    // ...
}

Requests, answers and timestamps

The generated types follow the API's document. Every field of a request is optional: set what you need, and an unset field is left out of the body, so the API uses its default. A field of an answer is typed as always present exactly when the document marks it required; a field that may be absent (a nested message, an optional field) is optional. Timestamps are RFC 3339 strings, and an unset one is ""; each runtime has one helper that reads a timestamp and gives no value for "":

LanguageRequest field set byTimestamp helper
Rust..Default::default()inorbithr::parse_timestamp (None for "")
TypeScriptleaving the property outparseTimestamp (undefined for "")
Goinorbit.Ptr(v) on a pointerinorbit.ParseTimestamp (the zero time.Time)
Pythonkeyword argumentsparse_timestamp (None for "")
C#object initializersTimestamps.Parse (null for "")
Javathe builderTimestamps.parse (an empty Optional for "")

A stream of events

A streaming operation is a method of the same name that yields one model per event: the account's events (events.stream_events, scope events:read) as they happen. It opens as server-sent events; a client set to streams: socket carries every stream over one WebSocket instead, and opens it again by itself when the server ends the socket. A revoked key ends the stream with unauthenticated; silence for 45 seconds ends it with a timeout. The limits say how many a key may hold.

let mut events = ci.events().stream_events(&EventsStreamEventsParams::default()).await?;
while let Some(event) = events.next().await {
    let event = event?;
    println!("{} {}", event.type_, event.id);
}

Breaking out of the loop, cancelling, or closing the stream closes it on the server too. Over the socket, browsers cannot send the token on a WebSocket, so the TypeScript client uses server-sent events there.

4. Check it in CI

The API's cut moves when a plan changes or a scope is revoked. iohr sdk check fetches every profile's document again and exits 1 with what moved:

profile ci: the cut moved (sha256:3f… -> sha256:9a…)
  - GET /v1/radar/items
1 profile moved; run `iohr sdk generate` again and commit the result

A person cannot sign in on CI, so give each profile a token there: IOHR_TOKEN_CI for ci, IOHR_TOKEN_DEFAULT for default. A token's cut is its own, so for a person's profile use a token made for the same account with the scopes the client needs, or leave that profile out of the lock.

# .github/workflows/sdk.yml
jobs:
  sdk:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - run: curl -fsSL https://packages.inorbit.hr/install.sh | sh
      - run: ~/.local/bin/iohr sdk check --files
        env:
          IOHR_TOKEN_CI: ${{ secrets.IOHR_TOKEN_CI }}

--files also regenerates into a temporary directory and compares it with what is committed, so a hand edit or a stale generator version fails too. Exit codes are the command line's: 0 nothing moved, 1 the cut or the files moved, 3 a token was refused, 4 the account is not the token's.

A person's client is cut by the team's plan, not by the person's role in it; a write the team refuses by role still answers 403.

Staying current

Every InOrbit client names itself on each request in InOrbit-Client: <type>/<version> (for example sdk-rust/0.2.0). When yours is behind, answers carry InOrbit-Client-Update: latest=…; minimum=…[; grace_until=…]. When it is older than the oldest version still served, the API answers 426 with the code upgrade_required and where to get the update (Errors); the SDKs raise it as their own typed error. A new minimum comes with a grace period first, and your account hears about it through its own channels (the client.update_available and client.upgrade_required events).

GET /v1/clients/versions takes no token and answers every client type's latest version, minimum, grace deadline and where to get it; ?client=sdk-rust narrows it to one.

The Mac app updates itself from its own public feed, also without a token: GET /v1/releases/mac/{channel}/latest.json is the current release of a channel (stable or beta) with its version, notes and signed bundle, .../history.json lists the releases the feed still serves (the current one and the two before it, for rollback), .../drift answers 200 while the feed matches the newest published release and 503 once it has lagged behind for 30 minutes, and GET /v1/releases/mac/releases/{version}/{file} streams one release's bundle, signature or manifest. A channel with no release yet answers 404.

Checking a package

RegistryHow
npmnpm audit signatures checks registry signatures and provenance
PyPIeach file carries a PEP 740 attestation; pypi-attestations verify pypi --repository https://github.com/inorbithr/sdk <file>
Gothe toolchain checks every module against sum.golang.org
JSRprovenance on the package page, linked to the transparency log
crates.ioCargo checks every download against the index's checksum

The details are in the SDK repository's verifying releases.