Cordium documentation · Latest
APIs and SDKs
The complete Cordium API is exposed over gRPC. This is the interface used by the cordium CLI and the web portal. Cordium provides SDKs for Golang, Python, Rust and TypeScript/JavaScript that handle authentication, Workspace lifecycle operations, command execution and file transfers.
The SDKs also support managing resources such as Spaces, Templates, Snapshots, Volumes and Secrets. They share the same Octelium authentication and authorization model as the CLI and the web portal.
Authentication
The examples below read the Cluster domain and credentials from the environment:
OCTELIUM_DOMAIN can also be used for the Cluster domain. For workload identity federation, set OCTELIUM_ASSERTION_FILE to the path of an assertion file. An existing access token can be supplied through OCTELIUM_ACCESS_TOKEN. The authenticated User must have a Policy that permits the requested operations. Read more about authentication-token Credentials here and Policies here.
Workspace Example
The following example creates a client and runs a Workspace with a container image, a Git repository, environment variables, resource limits and lifecycle Tasks. An ON_CREATE Task installs dependencies, while a background POST_START Task starts a development server exposed through a Workspace application.
Once the Workspace is running, the example writes a configuration file, uploads a local file, runs tests and builds the application, then downloads the build artifact and deletes the Workspace.
Replace the repository URL and npm commands with those used by your application. This example assumes a repository with a lockfile, test, build and dev scripts, a development server on port 3000 and build output in dist/. Create a local input.json file before running it. Resource limits use CPU millicores and megabytes for memory and storage. Read more about Workspace configuration here.
The cordium-go SDK uses composable options and context-based cancellation. Install the module in your Go application as follows:
Here is a complete example:
Run/run() creates the Workspace, starts it and waits for RUNNING, when foreground initialization Tasks have completed. Use Create/create() to create a stopped Workspace and start it later. Background Tasks do not delay readiness; an application may still need a health check before it is ready to serve requests.
An ephemeral Workspace discards its storage when stopped, but its resource object remains until explicitly deleted. Closing a client releases its connections without stopping or deleting Workspaces. The examples delete a successfully started Workspace even when a subsequent command or file transfer fails.
Startup failures retain the Workspace for inspection. Golang returns its handle alongside the error, Python and TypeScript expose the resource through error.workspace, and Rust uses Error::RunFailed with a Workspace handle. Inspect the failed Workspace and delete it when it is no longer needed.
Forking Workspaces from a Snapshot
WorkspaceSnapshots make it cheap to fork the exact state of a Workspace (e.g. a repository with its dependencies installed and its build cache warm) into several brand new Workspaces that run in parallel, which is useful for sharding test suites, trying several fixes at once, or best-of-N AI agent attempts. The following example snapshots the running Workspace k3x9, waits for the snapshot to be ready, restores it into three Workspaces in parallel, runs a different test shard in each of them and deletes them afterwards (read more about snapshots here):
Snapshots require a storage backend that supports Kubernetes CSI volume snapshots. Restored Workspaces are created from the Template of the snapshotted Workspace and run in the Region that holds the snapshot.
Other SDK Capabilities
The same clients can be used for interactive sessions, application access and resource management. See each SDK's README and examples for complete usage:
| Capability | Usage |
| Commands | Capture stdout, stderr and exit status, or stream output as a command runs. Set a working directory, environment variables and a deadline. |
| Files | Read and write text or binary data in memory, or stream uploads and downloads between the local filesystem and the Workspace. |
| Terminals and logs | Create and attach to persistent terminals, stream initialization logs and watch Workspace changes. |
| Applications | Obtain authenticated application URLs and share ports with Space members or authenticated Cluster Users. |
| Templates and storage | Build Templates, create and restore Snapshots, and manage persistent Volumes. |
| Resource management | List and manage Spaces, Secrets, UserSecrets, GitProviders and memberships. |
Command strings are interpreted by the Workspace shell. For literal arguments, use cordium.Argv in Golang, a list of strings in Python, Command::argv in Rust or argv in TypeScript. Nonzero exit codes are returned in the command result by default; result.Err() in Golang and the check option in the other SDKs turn them into errors.
File transfers use the command execution API and require standard POSIX tools such as sh, base64 and head in the Workspace image. Read more about Workspace applications and port sharing here.
Full API and Resource Schemas
Each SDK also exposes the generated gRPC APIs for operations and configuration fields outside its convenience helpers. Use MainService(), WorkspaceService() and ManagementService() in Golang, AsyncCordium.raw and the cordium.proto module in Python, main_service(), workspace_service() and management_service() with cordium::proto in Rust, or client.raw and @octelium/cordium/proto in TypeScript. The blocking Python client provides client.call() for advanced async operations.
Cordium resource JSON Schemas are published under /schemas/cordium/latest/, with filenames such as cordium.v1.Workspace.schema.json. Use them to look up exact fields, types and enum values, for example the Workspace JSON Schema and Template JSON Schema. The resource concepts and Cluster configuration pages include interactive schema viewers.