Functions
20 endpoints at https://api.kosa8.com, sent with Authorization: Bearer $KOSA8_API_KEY. Generated from the API's own OpenAPI description, which a test holds to the router.
List functions#
GET
Responses/v1/functionsscope functions:invoke200401403
curl -s -X GET https://api.kosa8.com/v1/functions \ -H "Authorization: Bearer $KOSA8_API_KEY"
Deploy or replace a function (bumps version)#
PUT
/v1/functions/{name}scope functions:deploy201 when the name is new (version 1); 200 when it replaces a deployed function. Give code, or repo {name, ref?, path} to deploy that file of a GitHub repository; the function's source then says which commit.
Parametersnamerequiredpath · stringFunction name
runtimerequired"python3.12" | "node22"—
coderequiredstringThe source, at most 1 MiB
envobjectNames not starting with K8_; 16 KiB in all
timeout_sintegerDefault
30. Min 1. Max 90.web"off" | "public" | "key"Default
"off".schedulestring | nullA five-field cron expression (UTC), or null for none
repostring | objectA GitHub repository of the organization's connection to take the function's code from: "owner/name", "owner/name@ref", or {name, ref, path}. path is the file inside the repository, such as src/handler.py (required). Read by kosa8 at one commit with a read-only token for that one repository, revoked right after (audited as github.token and github.read); the answer's source (or repo) says which commit. Errors as for sandboxes: 409 github_not_connected, 404 repo_not_found, 404 ref_not_found, 404 path_not_found, 409 github_permissions, 413 too_large.
200201400401403413
curl -s -X PUT https://api.kosa8.com/v1/functions/$NAME \ -H "Authorization: Bearer $KOSA8_API_KEY" \ -H 'Content-Type: application/json' -d @body.json
Get a function with its code#
GET
Parameters/v1/functions/{name}scope functions:deploynamerequiredpath · stringFunction name
200401403404
curl -s -X GET https://api.kosa8.com/v1/functions/$NAME \ -H "Authorization: Bearer $KOSA8_API_KEY"
Delete a function#
DELETE
Parameters/v1/functions/{name}scope functions:deploynamerequiredpath · stringFunction name
200401403404
curl -s -X DELETE https://api.kosa8.com/v1/functions/$NAME \ -H "Authorization: Bearer $KOSA8_API_KEY"
Call a function: {event} → result, logs, timings#
POST
Parameters/v1/functions/{name}/invokescope functions:invokenamerequiredpath · stringFunction name
eventobject—
200401402403404
curl -s -X POST https://api.kosa8.com/v1/functions/$NAME/invoke \ -H "Authorization: Bearer $KOSA8_API_KEY" \ -H 'Content-Type: application/json' -d @body.json
Call a function on up to 100 events#
POST
Parameters/v1/functions/{name}/mapscope functions:invokenamerequiredpath · stringFunction name
eventsrequiredarray of object—
concurrencyintegerMax 16.
200401402403404
curl -s -X POST https://api.kosa8.com/v1/functions/$NAME/map \ -H "Authorization: Bearer $KOSA8_API_KEY" \ -H 'Content-Type: application/json' -d @body.json
Recent calls, newest first#
GET
Parameters/v1/functions/{name}/invocationsscope functions:invokenamerequiredpath · stringFunction name
limitquery · integerHow many
200401403
curl -s -X GET https://api.kosa8.com/v1/functions/$NAME/invocations \ -H "Authorization: Bearer $KOSA8_API_KEY"
The versions kept (the last 20), newest first, without code; env names only#
GET
Parameters/v1/functions/{name}/versionsscope functions:deploynamerequiredpath · stringFunction name
200401403404
curl -s -X GET https://api.kosa8.com/v1/functions/$NAME/versions \ -H "Authorization: Bearer $KOSA8_API_KEY"
One kept version, with its code#
GET
Parameters/v1/functions/{name}/versions/{version}scope functions:deploynamerequiredpath · stringFunction name
versionrequiredpath · stringVersion number
200401403404
curl -s -X GET https://api.kosa8.com/v1/functions/$NAME/versions/$VERSION \ -H "Authorization: Bearer $KOSA8_API_KEY"
Deploy a kept version again (its code, runtime, env, timeout, web and schedule) as a new version#
POST
Parameters/v1/functions/{name}/rollbackscope functions:deploynamerequiredpath · stringFunction name
versionrequiredintegerMin 1.
200400401403404409
curl -s -X POST https://api.kosa8.com/v1/functions/$NAME/rollback \ -H "Authorization: Bearer $KOSA8_API_KEY" \ -H 'Content-Type: application/json' -d @body.json
Run code or a command in a fresh sandbox, one call: output, exit code and files back, sandbox deleted#
POST
/v1/runscope sandboxes:writeBilled per second like any sandbox. A command that exits non-zero is a 200 with status failed; 4xx/5xx carry hint (the next step) and docs.
JSON bodycodestringSource to run; written to filename (main.<ext>) in /workspace
commandstring | array of stringA shell string, or a list of strings; with code, runs instead of the language's own command
language"python" | "node" | "typescript" | "bash" | "sh"Default: from filename, else python
filenamestring—
templatestringDefault: the language's (python, node, base)
filesobject | array of object{path: text} or [{path, content, encoding: utf8|base64}]; paths are under /workspace
envobject—
sizestring—
timeout_sintegerDefault
60. Min 1. Max 3600.streamboolean | "ndjson" | "sse"true or ndjson: NDJSON frames as it prints; sse: server-sent events (or send Accept: text/event-stream)
outputsarray of stringFiles to send back, base64, 4 MiB together
shareboolean | objecttrue: a public read-only run card (command, output, duration; never env or files). {public, code} also shows the code.
repostring | objectA GitHub repository of the organization's connection (GET /v1/github/repos) to clone into the sandbox: "owner/name", "owner/name@ref" (branch, tag or 40-character sha), or {name, ref, path, depth}, or {name, pr} to continue pull request pr (its head branch, or for a fork its head commit; a fork's head is read only: push and pull-request answer 409 fork_pull_request; for one of the repository's own, push goes to the pull request's branch by default). path defaults to /workspace/<name>; depth to 1 (0: the whole history). Checked before anything is made (409 github_not_connected, 404 repo_not_found, 409 github_permissions). git in the sandbox clones through kosa8's git proxy with a read-only capability for that one repository and that one command; the proxy adds the GitHub token on kosa8's side, so no GitHub token ever enters the sandbox, and the sandbox needs to reach only kosa8's API host (added to its egress for the clone alone), never github.com.
github_checkboolean | stringWith repo: true (named kosa8/run) or a check name. When the run ends its result goes on the cloned commit as a GitHub check run (or a commit status), linking to the run's page; shows on the pull request of that branch.
200400401402403413429
curl -s -X POST https://api.kosa8.com/v1/run \ -H "Authorization: Bearer $KOSA8_API_KEY" \ -H 'Content-Type: application/json' -d @body.json
Run it: this visitor's free time left (15 minutes of run time per 24 hours by default)#
GET
Responses/v1/trypublic200
curl -s -X GET https://api.kosa8.com/v1/try
Run it with no account: up to 8 KiB of code, 60 s a run, no network, 15 free minutes per 24 hours; a public run card and a claim token back#
POST
JSON body/v1/trypubliclanguage"python" | "node" | "bash"Default
"python".coderequiredstringMax length 8192.
turnstile_tokenstringSent when a 403 challenge_required asked for it
claim_tokenstringThe last run's claim token, echoed into signup_url when the free minutes are used up
200400402403413429503
curl -s -X POST https://api.kosa8.com/v1/try \ -H 'Content-Type: application/json' -d @body.json
Move a run made with Run it (POST /v1/try) into this org, by its claim token#
POST
JSON body/v1/try/claimscope sandboxes:writetokenrequiredstringThe claim token (k8t_…), valid 7 days
200400401403404
curl -s -X POST https://api.kosa8.com/v1/try/claim \ -H "Authorization: Bearer $KOSA8_API_KEY" \ -H 'Content-Type: application/json' -d @body.json
The org's recent runs, newest first (kept 30 days)#
GET
Parameters/v1/runsscope sandboxes:readlimitquery · integerHow many, up to 100
repoquery · stringowner/name: only runs that cloned it
200401403
curl -s -X GET https://api.kosa8.com/v1/runs \ -H "Authorization: Bearer $KOSA8_API_KEY"
One run, with the saved tail of its output#
GET
Parameters/v1/runs/{id}scope sandboxes:readidrequiredpath · stringRun id (sr_…)
200401403404
curl -s -X GET https://api.kosa8.com/v1/runs/$SBX \ -H "Authorization: Bearer $KOSA8_API_KEY"
Publish or unpublish a run's read-only card#
POST
Parameters/v1/runs/{id}/sharescope sandboxes:writeidrequiredpath · stringRun id (sr_…)
publicrequiredboolean—
codeboolean—
200400401403404
curl -s -X POST https://api.kosa8.com/v1/runs/$SBX/share \ -H "Authorization: Bearer $KOSA8_API_KEY" \ -H 'Content-Type: application/json' -d @body.json
A run card's model (serverless run, job or RL run) for the org's members#
GET
Parameters/v1/cards/{id}scope sandboxes:readidrequiredpath · stringsr_…, job_… or run_…
200401403404
curl -s -X GET https://api.kosa8.com/v1/cards/$SBX \ -H "Authorization: Bearer $KOSA8_API_KEY"
Publish or unpublish a job's read-only card#
POST
Parameters/v1/jobs/{id}/sharescope sandboxes:writeidrequiredpath · stringJob id
publicrequiredboolean—
200400401403404
curl -s -X POST https://api.kosa8.com/v1/jobs/$SBX/share \ -H "Authorization: Bearer $KOSA8_API_KEY" \ -H 'Content-Type: application/json' -d @body.json
Publish or unpublish an RL run's read-only card#
POST
Parameters/v1/rl/runs/{id}/sharescope sandboxes:writeidrequiredpath · stringRL run id
publicrequiredboolean—
200400401403404
curl -s -X POST https://api.kosa8.com/v1/rl/runs/$SBX/share \ -H "Authorization: Bearer $KOSA8_API_KEY" \ -H 'Content-Type: application/json' -d @body.json