FunctionService
Deploy and invoke managed serverless functions.
FunctionService deploys and invokes managed functions: you register a container handler once, then call it on demand while Daytona starts, scales, and tears down microVM instances for you and bills per invocation duration. Obtain the service as daytona.fn. All methods are async. For the concepts behind each method, see the functions guides — in particular deploying, invoking, and scaling.
deploy()
Deploys a function, or redeploys it as a new immutable version (upsert by name). image is a registry reference — the SDK wraps it as the version's image source. handler defaults to the image entrypoint and must start an HTTP server on port. All params except name and image are optional; omitted values take the platform defaults.
| Param | Type | Default | Description |
|---|---|---|---|
name | string | — | Per-project unique name; [a-z0-9]([a-z0-9-]*[a-z0-9])?, 1–64 chars. |
image | string | — | Registry reference to boot the handler from. |
handler | string[] | image entrypoint | Argv that starts the HTTP server on port. |
port | number | 8080 | Port the handler listens on (RLP_FN_PORT). |
vcpus | number | 1 | Provisioned vCPUs (≥ 1). |
memMib | number | 512 | Provisioned memory in MiB (≥ 128). |
scratchMib | number | 512 | Scratch disk in MiB (≥ 64). |
timeoutS | number | 300 | Max seconds per invocation (1–172800). |
scaledownWindowS | number | 60 | Idle seconds before scale-to-zero (≥ 2). |
maxConcurrency | number | 1 | Invocations one instance serves at once (≥ 1). |
maxInstances | number | unbounded | Spend guard capping concurrent instances. |
env | Record<string, string> | {} | Environment variables for the handler. |
snapshotKind | 'pre_entrypoint' | 'fn_ready' | pre_entrypoint | Cold-start template. |
Returns: an object with the new version's version and image_ref.
list()
Lists the project's functions, each with its current version and template state.
Returns: an array of function summaries.
get()
Fetches one function's detail, including its current version and configuration.
Throws: DaytonaNotFoundError if the function does not exist.
invoke()
Synchronous invoke: sends payload as the JSON body and resolves with the handler's response body. Waits until the handler answers, the function times out, or — if no capacity is reachable within the queue budget — the call is shed with a 429.
| Param | Type | Default | Description |
|---|---|---|---|
name | string | — | Function name. |
payload | unknown | {} | JSON body forwarded to the handler's POST /. |
Returns: the handler's response body, typed as T.
spawn()
Async invoke: returns an invocation id immediately and runs the work in the background. Poll the returned id with getInvocation until it is done. See invoking for the async result-size limit.
| Param | Type | Default | Description |
|---|---|---|---|
name | string | — | Function name. |
payload | unknown | {} | JSON body forwarded to the handler. |
Returns: an object with invocation_id.
map()
Fan-out: submits many payloads in one call as parallel invocations. Returns the invocation ids to poll individually. A single call accepts up to 1000 payloads.
| Param | Type | Default | Description |
|---|---|---|---|
name | string | — | Function name. |
payloads | unknown[] | — | One entry per parallel invocation (≤ 1000). |
Returns: an object with invocation_ids and count.
getInvocation()
Polls a single invocation (from spawn, map, or a schedule) for its status and result.
Returns: an Invocation with status, done, cold, duration_ms, error, and result. status is one of pending, running, succeeded, failed, timeout, or shed; done is true once terminal.
Throws: DaytonaNotFoundError if the invocation does not exist.
schedule()
Creates a cron schedule that invokes the function on a recurring cadence with an optional fixed payload. The expression is a 5-field cron string in UTC. See scheduling.
| Param | Type | Default | Description |
|---|---|---|---|
name | string | — | Function name. |
cron | string | — | 5-field cron expression, UTC. |
payload | unknown | null | JSON body forwarded on each fire. |
Returns: an object with the schedule id and next_run_at.
setPublic()
Enables or disables the function's public web endpoint. With requireToken set, a bearer token is minted and returned once; store it. See public endpoints.
| Param | Type | Default | Description |
|---|---|---|---|
name | string | — | Function name. |
enabled | boolean | — | Whether the public endpoint is on. |
requireToken | boolean | false | Require a per-function bearer token. |
Returns: an object with url, requires_token, and (once) token.