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. 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 fields except name and image are optional; omitted values take the platform defaults.
| Parameter | Type | Default | Description |
|---|---|---|---|
name | str | — | Per-project unique name; [a-z0-9]([a-z0-9-]*[a-z0-9])?, 1–64 chars. |
image | str | — | Registry reference to boot the handler from. |
handler | List[str] | image entrypoint | Argv that starts the HTTP server on port. |
port | int | 8080 | Port the handler listens on (RLP_FN_PORT). |
vcpus | int | 1 | Provisioned vCPUs (≥ 1). |
mem_mib | int | 512 | Provisioned memory in MiB (≥ 128). |
scratch_mib | int | 512 | Scratch disk in MiB (≥ 64). |
timeout_s | int | 300 | Max seconds per invocation (1–172800). |
scaledown_window_s | int | 60 | Idle seconds before scale-to-zero (≥ 2). |
max_concurrency | int | 1 | Invocations one instance serves at once (≥ 1). |
max_instances | int | unbounded | Spend guard capping concurrent instances. |
env | Dict[str, str] | {} | Environment variables for the handler. |
snapshot_kind | str | pre_entrypoint | Cold-start template: pre_entrypoint or fn_ready. |
Returns: a dict with the new version's details (including version and image_ref).
list()
Lists the project's functions, each with its current version and template state.
Returns: a list of function summary dicts.
get()
Fetches one function's detail, including its current version and configuration.
Raises: DaytonaNotFoundError if the function does not exist.
invoke()
Synchronous invoke: sends payload as the JSON body and blocks until the handler responds, returning its response body. Blocks 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.
| Parameter | Type | Default | Description |
|---|---|---|---|
name | str | — | Function name. |
payload | Any | {} | JSON body forwarded to the handler's POST /. |
Returns: the handler's response body (JSON-decoded).
spawn()
Async invoke: returns an invocation id immediately and runs the work in the background. Poll the returned id with get_invocation until it is done. See invoking for the async result-size limit.
| Parameter | Type | Default | Description |
|---|---|---|---|
name | str | — | Function name. |
payload | Any | {} | JSON body forwarded to the handler. |
Returns: a dict with invocation_id and status.
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.
| Parameter | Type | Default | Description |
|---|---|---|---|
name | str | — | Function name. |
payloads | List[Any] | — | One entry per parallel invocation (≤ 1000). |
Returns: a dict with invocation_ids and count.
get_invocation()
Polls a single invocation (from spawn, map, or a schedule) for its status and result.
Returns: a dict 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.
Raises: 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.
| Parameter | Type | Default | Description |
|---|---|---|---|
name | str | — | Function name. |
cron | str | — | 5-field cron expression, UTC. |
payload | Any | null | JSON body forwarded on each fire. |
Returns: a dict with the schedule id and next_run_at.
set_public()
Enables or disables the function's public web endpoint. With require_token=True, a bearer token is minted and returned once; store it. See public endpoints.
| Parameter | Type | Default | Description |
|---|---|---|---|
name | str | — | Function name. |
enabled | bool | — | Whether the public endpoint is on. |
require_token | bool | False | Require a per-function bearer token. |
Returns: a dict with url, requires_token, and (once) token.