DaytonaDocs

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.

TypeScript
deploy(params: DeployFunctionParams): Promise<{ version: number; image_ref: string }>
ParamTypeDefaultDescription
namestringPer-project unique name; [a-z0-9]([a-z0-9-]*[a-z0-9])?, 1–64 chars.
imagestringRegistry reference to boot the handler from.
handlerstring[]image entrypointArgv that starts the HTTP server on port.
portnumber8080Port the handler listens on (RLP_FN_PORT).
vcpusnumber1Provisioned vCPUs (≥ 1).
memMibnumber512Provisioned memory in MiB (≥ 128).
scratchMibnumber512Scratch disk in MiB (≥ 64).
timeoutSnumber300Max seconds per invocation (1–172800).
scaledownWindowSnumber60Idle seconds before scale-to-zero (≥ 2).
maxConcurrencynumber1Invocations one instance serves at once (≥ 1).
maxInstancesnumberunboundedSpend guard capping concurrent instances.
envRecord<string, string>{}Environment variables for the handler.
snapshotKind'pre_entrypoint' | 'fn_ready'pre_entrypointCold-start template.

Returns: an object with the new version's version and image_ref.

TypeScript
await daytona.fn.deploy({
  name: 'greet',
  image: 'ghcr.io/acme/greet:latest',
  memMib: 512,
  timeoutS: 30,
  env: { LOG_LEVEL: 'info' },
})

list()

Lists the project's functions, each with its current version and template state.

TypeScript
list(): Promise<unknown[]>

Returns: an array of function summaries.

get()

Fetches one function's detail, including its current version and configuration.

TypeScript
get(name: string): Promise<unknown>

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.

TypeScript
invoke<T = unknown>(name: string, payload?: unknown): Promise<T>
ParamTypeDefaultDescription
namestringFunction name.
payloadunknown{}JSON body forwarded to the handler's POST /.

Returns: the handler's response body, typed as T.

TypeScript
const result = await daytona.fn.invoke<{ greeting: string }>('greet', { name: 'Ada' })

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.

TypeScript
spawn(name: string, payload?: unknown): Promise<{ invocation_id: string }>
ParamTypeDefaultDescription
namestringFunction name.
payloadunknown{}JSON body forwarded to the handler.

Returns: an object with invocation_id.

TypeScript
const { invocation_id } = await daytona.fn.spawn('greet', { name: 'Ada' })
const inv = await daytona.fn.getInvocation(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.

TypeScript
map(name: string, payloads: unknown[]): Promise<{ invocation_ids: string[]; count: number }>
ParamTypeDefaultDescription
namestringFunction name.
payloadsunknown[]One entry per parallel invocation (≤ 1000).

Returns: an object with invocation_ids and count.

TypeScript
const { invocation_ids } = await daytona.fn.map('greet', [{ name: 'Ada' }, { name: 'Alan' }])

getInvocation()

Polls a single invocation (from spawn, map, or a schedule) for its status and result.

TypeScript
getInvocation(id: string): Promise<Invocation>

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.

TypeScript
schedule(name: string, cron: string, payload?: unknown): Promise<{ id: string; next_run_at: string }>
ParamTypeDefaultDescription
namestringFunction name.
cronstring5-field cron expression, UTC.
payloadunknownnullJSON body forwarded on each fire.

Returns: an object with the schedule id and next_run_at.

TypeScript
await daytona.fn.schedule('nightly-etl', '0 2 * * *', { mode: 'full' })

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.

TypeScript
setPublic(
  name: string,
  enabled: boolean,
  requireToken?: boolean,
): Promise<{ url: string; requires_token: boolean; token: string | null }>
ParamTypeDefaultDescription
namestringFunction name.
enabledbooleanWhether the public endpoint is on.
requireTokenbooleanfalseRequire a per-function bearer token.

Returns: an object with url, requires_token, and (once) token.

TypeScript
const result = await daytona.fn.setPublic('webhook', true, true)
console.log(result.url, result.token)

On this page