# Functions

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

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

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

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

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

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

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/
