SDKs
Lists the methods of the Python, TypeScript, Go, Ruby, and Java clients.
Last updated
On this page
Install and import
| Language | Install from the registry | Or copy the source | Requires | Import | Construct |
|---|---|---|---|---|---|
| Python | pip install kode-sdk | python/kloudlite.py, one file | Python 3.9 or later | from kloudlite import Kode, ApiError | Kloudlite() |
| TypeScript | npm install @kloudlite/sdk | typescript/index.ts, no build step | Node 20.16 or later, or Bun; ESM | import { Kode } from "@kloudlite/sdk" | new Kloudlite() |
| Go | go get github.com/kloudlite/sdk/go | source | Go 1.24 or later | import kloudlite "github.com/kloudlite/sdk/go" | kloudlite.New(kloudlite.Options{}) |
| Ruby | gem install kode-sdk | ruby/kloudlite.rb, one file | Ruby 3.0 or later | require "kode" | Kloudlite::Client.new |
| Java | Maven dependency io.kloudlite:kode-sdk:0.2.2 | java/Kloudlite.java, one file | Java 11 or later | import io.kloudlite.Kode; | new Kloudlite() |
A copied TypeScript file is imported as ./index.ts, and a copied Ruby file as require_relative "kloudlite".
The distribution of the Python package is kode-sdk, and its import name is kode. The command pip install kloudlite installs a different package, the client of the model and dataset hub.
Secret references
An environment value refers to a secret of the owner as ${{ secrets.NAME }}. With the team as the owner, the secrets calls work on your own secrets in that team; give the scope team for the secrets of the team. The secrets API lists the routes that take a reference.
Pipeline definitions
The definition of pipelines.create and pipelines.update is plain data in the shape of Pipeline definition. Python takes a dict, Ruby a hash, and TypeScript an object. Go takes PipelineDefinition, which is raw JSON bytes, and Java takes a JSON string.
The order of jobs, inputs, and each matrix is part of the definition. Python, Ruby, and TypeScript keep the order that you write. Go and Java send the bytes that you give, so write the keys in the order that you want.
A save returns the pipeline with its version. rotate_webhook returns the new URL, which no later call shows.
Authentication and base URL
The SDK uses the login of kode, so a client needs no arguments. It takes the API origin and the token from the first source that has each, adds /v1 to the origin, and sends the token as Authorization: Bearer.
| Order | Source | Origin | Token |
|---|---|---|---|
| 1 | The argument in code | base_url (baseUrl, BaseURL) | token (Token) |
| 2 | The environment | KODE_URL | KODE_TOKEN |
| 3 | The kode login | api in config.json | token in config.json |
config.json is in KODE_CONFIG_DIR, or in ~/.config/kode. For a CI job or a server with no kode, set KODE_URL and KODE_TOKEN. The token is a CLI login or an API token. An API token opens only the routes within its reach and grants. A pipeline run or a capsule that it starts is recorded under the name of the token.
With no token, the SDK stops with no Kode login: pass token=, set KODE_TOKEN, or run kode login. With a token and no origin, the sentence is no Kode API URL: …. The error type differs by language:
- Python:
RuntimeError, raised byKloudlite(). - TypeScript:
Error, thrown bynew Kloudlite(). - Go:
kloudlite.Newreturns no error. The first call returns it, andClient.Err()returns it at once. - Ruby:
RuntimeError, raised byKloudlite::Client.new. - Java:
IllegalStateException, thrown bynew Kloudlite().
Every request times out after 30 seconds. Set the limit with timeout (Python, Ruby), timeoutMs (TypeScript), or Options.Timeout (Go). Java has no setting for it.
Inputs, results, and errors
Every input is named. Python takes keyword-only arguments, Ruby keywords, TypeScript one options object, Go one request struct (kloudlite.CreateWorkspace{Workspace: …}), and Java a nested params class (new Kloudlite.CreateWorkspace().workspace(…)).
A workspace, environment, or desk is "name" for your own or "team/name" for a team's, or its id. Something new made from an existing one is to.
Every method returns the decoded JSON of the route, except the capsule and pipeline handles below. Java returns the raw JSON string from every method, except those two.
Errors, one per SDK:
- Python:
ApiErrorwithstatusandmessage;CapsuleTerminated, a subclass, when a capsule that you wait for has ended. - TypeScript:
ApiErrorwithstatusandmessage;TimeoutErrorwhen a client-side wait runs out. A terminated capsule is anApiErrorwith status 409. - Go:
*ApiErrorwithStatusandMessage;ErrTimeout, tested witherrors.Is, when a wait runs out. A terminated capsule is an*ApiErrorwith status 409. - Ruby:
Kode::ApiErrorwithstatusandmessage;CapsuleTerminated < ApiError;TimeoutErrorwhen a wait runs out. - Java:
Kode.ApiException, anIOException, with publicstatusandmessage.
A missing required field is refused before anything is sent: ValueError in Python, an IllegalArgumentException in Java.
Methods
Resources hang off the client under these names: workspaces, environments, desks, volumes, secrets, connectors, capsules, and pipelines. Java reaches them as a call, kl.workspaces() and Go as the field kl.Workspaces. The ide, capsule, process, and run rows are on objects that those methods return. workspaces.ide returns the tool-server client. capsules.create, get, and list return capsule handles. pipelines.run and get_run return a run handle.
Python also has an .aio form of its calls for asyncio. Every cell is the method name in that language.
The tool-server rows call the tool server directly with the workspace's token, so they take the tool's own arguments. The SDKs have no method for these resources: teams, invites, keys, tokens, container images, requests, and regions.
| Resource.method | python | typescript | go | ruby | java | Route |
|---|---|---|---|---|---|---|
| client.quota | quota | quota | Quota | quota | quota | GET /v1/quota |
| client.request | request | request | Request | request | request | any route, your method and path |
| workspaces.create | create | create | Create | create | create | POST /v1/workspaces |
| workspaces.list | list | list | List | list | list | GET /v1/workspaces |
| workspaces.get | get | get | Get | get | get | GET /v1/workspaces/{id} |
| workspaces.delete | delete | delete | Delete | delete | delete | DELETE /v1/workspaces/{id} |
| workspaces.start | start | start | Start | start | start | POST /v1/workspaces/{id}/start |
| workspaces.stop | stop | stop | Stop | stop | stop | POST /v1/workspaces/{id}/stop |
| workspaces.restart | restart | restart | Restart | restart | restart | POST /v1/workspaces/{id}/restart |
| workspaces.take_snapshot | take_snapshot | takeSnapshot | TakeSnapshot | take_snapshot | takeSnapshot | POST /v1/workspaces/{id}/snapshots |
| workspaces.clone | clone | clone | Clone | clone | clone | POST /v1/workspaces/{id}/clone |
| workspaces.restore | restore | restore | Restore | restore | restore | POST /v1/workspaces/restore |
| workspaces.set_packages | set_packages | setPackages | SetPackages | set_packages | setPackages | PATCH /v1/workspaces/{id} |
| workspaces.set_ttl | set_ttl | setTtl | SetTTL | set_ttl | setTtl | PUT /v1/workspaces/{id}/ttl |
| workspaces.set_env | set_env | setEnv | SetEnv | set_env | setEnv | PUT /v1/workspaces/{id}/env |
| workspaces.update_packages | update_packages | updatePackages | UpdatePackages | update_packages | updatePackages | POST /v1/workspaces/{id}/packages/update |
| workspaces.tools | tools | tools | Tools | tools | tools | GET /v1/workspaces/{id}/tools |
| workspaces.ide | ide | ide | Ide | ide | ide | GET /v1/workspaces/{id}/tools, then a client for the tool server |
| ide.list | list | list | List | list | list | GET /tools |
| ide.call | call | call | Call | call | call | POST /tools/{tool} |
| ide.read | read | read | Read | read | read | POST /tools/read |
| ide.write | write | write | Write | write | write | POST /tools/write |
| ide.edit | edit | edit | Edit | edit | edit | POST /tools/edit |
| ide.patch | patch | patch | Patch | patch | patch | POST /tools/patch |
| ide.glob | glob | glob | Glob | glob | glob | POST /tools/glob |
| ide.grep | grep | grep | Grep | grep | grep | POST /tools/grep |
| ide.exec | exec | exec | Exec | exec | exec | POST /tools/exec |
| ide.process_list | process_list | processList | ProcessList | process_list | processList | POST /tools/process_list |
| ide.process_output | process_output | processOutput | ProcessOutput | process_output | processOutput | POST /tools/process_output |
| ide.process_write | process_write | processWrite | ProcessWrite | process_write | processWrite | POST /tools/process_write |
| ide.process_kill | process_kill | processKill | ProcessKill | process_kill | processKill | POST /tools/process_kill |
| ide.watch | watch | watch | Watch | watch | watch | POST /tools/watch |
| ide.watch_poll | watch_poll | watchPoll | WatchPoll | watch_poll | watchPoll | POST /tools/watch_poll |
| ide.watch_stop | watch_stop | watchStop | WatchStop | watch_stop | watchStop | POST /tools/watch_stop |
| ide.container_build | container_build | containerBuild | ContainerBuild | container_build | containerBuild | POST /tools/container_build |
| ide.container_push | container_push | containerPush | ContainerPush | container_push | containerPush | POST /tools/container_push |
| environments.create | create | create | Create | create | create | POST /v1/environments |
| environments.list | list | list | List | list | list | GET /v1/environments |
| environments.get | get | get | Get | get | get | GET /v1/environments/{id} |
| environments.set_services | set_services | setServices | SetServices | set_services | setServices | PATCH /v1/environments/{id} |
| environments.start | start | start | Start | start | start | POST /v1/environments/{id}/start |
| environments.stop | stop | stop | Stop | stop | stop | POST /v1/environments/{id}/stop |
| environments.restart | restart | restart | Restart | restart | restart | POST /v1/environments/{id}/services/{service}/restart |
| environments.set_ttl | set_ttl | setTtl | SetTTL | set_ttl | setTtl | PUT /v1/environments/{id}/ttl |
| environments.delete | delete | delete | Delete | delete | delete | DELETE /v1/environments/{id} |
| environments.take_snapshot | take_snapshot | takeSnapshot | TakeSnapshot | take_snapshot | takeSnapshot | POST /v1/environments/{id}/snapshots |
| environments.clone | clone | clone | Clone | clone | clone | POST /v1/environments/{id}/clone |
| environments.restore | restore | restore | Restore | restore | restore | POST /v1/environments/{id}/restore |
| desks.create | create | create | Create | create | create | POST /v1/desks |
| desks.set_ttl | set_ttl | setTtl | SetTTL | set_ttl | setTtl | PUT /v1/desks/{id}/ttl |
| desks.list | list | list | List | list | list | GET /v1/desks |
| desks.get | get | get | Get | get | get | GET /v1/desks/{id} |
| desks.delete | delete | delete | Delete | delete | delete | DELETE /v1/desks/{id} |
| desks.stop | stop | stop | Stop | stop | stop | POST /v1/desks/{id}/stop |
| desks.start | start | start | Start | start | start | POST /v1/desks/{id}/start |
| desks.connect | connect | connect | Connect | connect | connect | PUT /v1/desks/{id}/environment |
| desks.create_workspace | create_workspace | createWorkspace | CreateWorkspace | create_workspace | createWorkspace | POST /v1/desks/{id}/workspaces |
| desks.create_capsule | create_capsule | createCapsule | CreateCapsule | create_capsule | createCapsule | POST /v1/desks/{id}/capsules |
| desks.delete_workspace | delete_workspace | deleteWorkspace | DeleteWorkspace | delete_workspace | deleteWorkspace | DELETE /v1/desks/{id}/workspaces/{workspace} |
| desks.intercept | intercept | intercept | Intercept | intercept | intercept | POST /v1/desks/{id}/intercepts |
| desks.release | release | release | Release | release | release | DELETE /v1/desks/{id}/intercepts/{service} |
| volumes.list | list | list | List | list | list | GET /v1/volumes |
| volumes.history | history | history | History | history | history | GET /v1/volumes/{key}/history |
| volumes.refs | refs | refs | Refs | refs | refs | GET /v1/volumes/{key}/refs |
| volumes.delete_snapshot | delete_snapshot | deleteSnapshot | DeleteSnapshot | delete_snapshot | deleteSnapshot | DELETE /v1/volumes/{key}/snapshots/{snapshot} |
| volumes.delete_by_id | delete_by_id | deleteById | DeleteByID | delete_by_id | deleteById | DELETE /v1/volumes/{key} |
| volumes.get | get | get | Get | get | get | GET /v1/volumes/{key}/{name} |
| volumes.versions | versions | versions | Versions | versions | versions | GET /v1/volumes/{key}/{name}/versions |
| volumes.delete | delete | delete | Delete | delete | delete | DELETE /v1/volumes/{key}/{name} |
| volumes.delete_version | delete_version | deleteVersion | DeleteVersion | delete_version | deleteVersion | DELETE /v1/volumes/{key}/{name}/versions/{n} |
| secrets.set | set | set | Set | set | set | PUT /v1/secrets/{owner}/mine/{name} |
| secrets.list | list | list | List | list | list | GET /v1/secrets/{owner}/mine |
| secrets.delete | delete | delete | Delete | delete | delete | DELETE /v1/secrets/{owner}/mine/{name} |
| connectors.list | list | list | List | list | list | GET /v1/connectors |
| connectors.delete | delete | delete | Delete | delete | delete | DELETE /v1/connectors/{name} |
| capsules.create | create | create | Create | create | create | POST /v1/capsules |
| capsules.get | get | get | Get | get | get | GET /v1/capsules/{id} |
| capsules.list | list | list | List | list | list | GET /v1/capsules; one page, limit, and cursor pick it |
| capsules.list_page | list_page | listPage | ListPage | list_page | listPage | the page and the cursor of the next one |
| capsules.run | run | run | Run | run | run | create, wait, logs, and terminate in one call; answers exit_code, stdout, stderr, and capsule |
| capsule handle.refresh | refresh | refresh | Refresh | refresh | refresh | GET /v1/capsules/{id} |
| capsule handle.wait_running | wait_running | waitRunning | WaitRunning | wait_running | waitRunning | polls GET /v1/capsules/{id} |
| capsule handle.logs | logs | logs | Logs | logs | logs | GET /v1/capsules/{id}/logs; follow holds until the process ends |
| capsule handle.exit_code | exit_code | exitCode | ExitCode | exit_code | exitCode | the exit code once the command has ended; a property or field in Python, TypeScript, and Go |
| capsule handle.terminate | terminate | terminate | Terminate | terminate | terminate | POST /v1/capsules/{id}/terminate |
| capsule handle.wait | wait | wait | Wait | wait | waitFor | POST /v1/capsules/{id}/wait; answers the exit code |
| capsule handle.delete | delete | delete | Delete | delete | delete | DELETE /v1/capsules/{id} |
| pipelines.create | create | create | Create | create | create | POST /v1/pipelines/{owner} |
| pipelines.update | update | update | Update | update | update | PUT /v1/pipelines/{owner}/{name} |
| pipelines.list | list | list | List | list | list | GET /v1/pipelines/{owner} |
| pipelines.get | get | get | Get | get | get | GET /v1/pipelines/{owner}/{name} |
| pipelines.versions | versions | versions | Versions | versions | versions | GET /v1/pipelines/{owner}/{name}/versions |
| pipelines.delete | delete | delete | Delete | delete | delete | DELETE /v1/pipelines/{owner}/{name} |
| pipelines.run | run | run | Run | run | run | POST /v1/pipelines/{owner}/{name}/runs |
| pipelines.rotate_webhook | rotate_webhook | rotateWebhook | RotateWebhook | rotate_webhook | rotateWebhook | POST /v1/pipelines/{owner}/{name}/webhook/rotate |
| pipelines.runs | runs | runs | Runs | runs | runs | GET /v1/pipelines/{owner}/{pipeline}/runs |
| pipelines.get_run | get_run | getRun | GetRun | get_run | getRun | GET /v1/pipelines/{owner}/{pipeline}/runs/{run} |
| run handle.refresh | refresh | refresh | Refresh | refresh | refresh | GET /v1/pipelines/{owner}/{pipeline}/runs/{run} |
| run handle.cancel | cancel | cancel | Cancel | cancel | cancel | POST /v1/pipelines/{owner}/{pipeline}/runs/{run}/cancel |
| run handle.wait | wait | wait | Wait | wait | waitFor | polls GET /v1/pipelines/{owner}/{pipeline}/runs/{run} |
| run handle.logs | logs | logs | Logs | logs | logs | GET /v1/pipelines/{owner}/{pipeline}/runs/{run}/jobs/{index}/logs |
| run handle.follow | follow | follow | Follow | follow | follow | GET /v1/pipelines/{owner}/{pipeline}/runs/{run}/jobs/{index}/logs, paged |
| ide.process_close_stdin | — | — | — | — | — | POST /tools/process_close_stdin; reach it with call |
| ide.process_wait | — | — | — | — | — | POST /tools/process_wait; reach it with call |
Two tool-server tools have no typed method, process_close_stdin and process_wait; call reaches them in every language.
The capsule attach is a WebSocket and is not in the SDKs. attach raises an error in every language, so use kode capsules attach. The SDKs have no capsule exec, read, or write, and no process classes. capsules.run answers exit_code, stdout (stdout and stderr together), an empty stderr, and capsule.