# Functions

20 endpoints at `https://api.kosa8.com`, sent with `Authorization: Bearer $KOSA8_API_KEY`. Generated from the API's own [OpenAPI description](https://api.kosa8.com/openapi.json), which a test holds to the router.

## List functions[#]

GET`/v1/functions`scope functions:invoke

Responses

200401403

```
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:deploy

201 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.

Parameters

`name`requiredpath · string

Function name

JSON body

`runtime`required"python3.12" | "node22"

—

`code`requiredstring

The source, at most 1 MiB

`env`object

Names not starting with K8_; 16 KiB in all

`timeout_s`integer

Default `30`. Min 1. Max 90.

`web`"off" | "public" | "key"

Default `"off"`.

`schedule`string | null

A five-field cron expression (UTC), or null for none

`repo`string | object

A 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.

Responses

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`/v1/functions/{name}`scope functions:deploy

Parameters

`name`requiredpath · string

Function name

Responses

200401403404

```
curl -s -X GET https://api.kosa8.com/v1/functions/$NAME \
  -H "Authorization: Bearer $KOSA8_API_KEY"
```

## Delete a function[#]

DELETE`/v1/functions/{name}`scope functions:deploy

Parameters

`name`requiredpath · string

Function name

Responses

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`/v1/functions/{name}/invoke`scope functions:invoke

Parameters

`name`requiredpath · string

Function name

JSON body

`event`object

—

Responses

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`/v1/functions/{name}/map`scope functions:invoke

Parameters

`name`requiredpath · string

Function name

JSON body

`events`requiredarray of object

—

`concurrency`integer

Max 16.

Responses

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`/v1/functions/{name}/invocations`scope functions:invoke

Parameters

`name`requiredpath · string

Function name

`limit`query · integer

How many

Responses

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`/v1/functions/{name}/versions`scope functions:deploy

Parameters

`name`requiredpath · string

Function name

Responses

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`/v1/functions/{name}/versions/{version}`scope functions:deploy

Parameters

`name`requiredpath · string

Function name

`version`requiredpath · string

Version number

Responses

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`/v1/functions/{name}/rollback`scope functions:deploy

Parameters

`name`requiredpath · string

Function name

JSON body

`version`requiredinteger

Min 1.

Responses

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/run`scope sandboxes:write

Billed 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 body

`code`string

Source to run; written to filename (main.<ext>) in /workspace

`command`string | array of string

A 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

`filename`string

—

`template`string

Default: the language's (python, node, base)

`files`object | array of object

{path: text} or [{path, content, encoding: utf8|base64}]; paths are under /workspace

`env`object

—

`size`string

—

`timeout_s`integer

Default `60`. Min 1. Max 3600.

`stream`boolean | "ndjson" | "sse"

true or ndjson: NDJSON frames as it prints; sse: server-sent events (or send Accept: text/event-stream)

`outputs`array of string

Files to send back, base64, 4 MiB together

`share`boolean | object

true: a public read-only run card (command, output, duration; never env or files). {public, code} also shows the code.

`repo`string | object

A 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_check`boolean | string

With 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.

Responses

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`/v1/try`public

Responses

200

```
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`/v1/try`public

JSON body

`language`"python" | "node" | "bash"

Default `"python"`.

`code`requiredstring

Max length 8192.

`turnstile_token`string

Sent when a 403 challenge_required asked for it

`claim_token`string

The last run's claim token, echoed into signup_url when the free minutes are used up

Responses

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`/v1/try/claim`scope sandboxes:write

JSON body

`token`requiredstring

The claim token (k8t_…), valid 7 days

Responses

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`/v1/runs`scope sandboxes:read

Parameters

`limit`query · integer

How many, up to 100

`repo`query · string

owner/name: only runs that cloned it

Responses

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`/v1/runs/{id}`scope sandboxes:read

Parameters

`id`requiredpath · string

Run id (sr_…)

Responses

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`/v1/runs/{id}/share`scope sandboxes:write

Parameters

`id`requiredpath · string

Run id (sr_…)

JSON body

`public`requiredboolean

—

`code`boolean

—

Responses

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`/v1/cards/{id}`scope sandboxes:read

Parameters

`id`requiredpath · string

sr_…, job_… or run_…

Responses

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`/v1/jobs/{id}/share`scope sandboxes:write

Parameters

`id`requiredpath · string

Job id

JSON body

`public`requiredboolean

—

Responses

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`/v1/rl/runs/{id}/share`scope sandboxes:write

Parameters

`id`requiredpath · string

RL run id

JSON body

`public`requiredboolean

—

Responses

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
```

---
Source: https://docs.kosa8.com/api/functions/
