Skip to Content
CLI & APICommand reference

stackblaze functions

Manage functions - one TypeScript file run on Bun

Usage: stackblaze functions|function [options] [command]

Manage functions: one TypeScript file run on Bun

Options:
  -h, --help                   Print help

Commands:
  list [options]               List functions in a project environment
  get [options] <name>         Show a function: how it runs, its URL and status
                               (--code prints its file)
  deploy|new [options] [name]  Create a function, or update its code, schedule
                               or port
  invoke [options] <name>      Call a function's URL and print the answer
  delete [options] <name>      Delete a function
  help [command]               Print this message or the help of the given
                               subcommand(s)

functions list

Usage: stackblaze functions list [options]

List functions in a project environment

Options:
  --api-url <url>        StackBlaze API base URL (env STACKBLAZE_API_URL)
  --token <token>        API token, sb_pat_... (env STACKBLAZE_TOKEN)
  -p, --project <name>   Project name
  -e, --env <name>       Environment name (default: production)
  -a, --app <name>       App name
  --json                 Output JSON (same as -o json) (default: false)
  -o, --output <format>  Output format: text or json (choices: "text", "json")
  -h, --help             Print help

Example

List the functions in an environment, how each one runs and its URL.

stackblaze functions list -p github-demo-cw8z -e dev
┌───────┬────────────┬───────────────────────────────────────────────────────┐
│ Name  │ Runs       │ URL                                                   │
├───────┼────────────┼───────────────────────────────────────────────────────┤
│ hello │ on request │ https://hello-4qcf.cloud-dev-central-1.stackblaze.app │
└───────┴────────────┴───────────────────────────────────────────────────────┘

functions get

Usage: stackblaze functions get [options] <name>

Show a function: how it runs, its URL and status (--code prints its file)

Options:
  --api-url <url>        StackBlaze API base URL (env STACKBLAZE_API_URL)
  --token <token>        API token, sb_pat_... (env STACKBLAZE_TOKEN)
  -p, --project <name>   Project name
  -e, --env <name>       Environment name (default: production)
  -a, --app <name>       App name
  --json                 Output JSON (same as -o json) (default: false)
  --code                 Print the function's TypeScript file (default: false)
  -o, --output <format>  Output format: text or json (choices: "text", "json")
  -h, --help             Print help

Example

Show how a function runs and whether it is awake, then print its code.

stackblaze functions get hello -p github-demo-cw8z -e dev
stackblaze functions get hello -p github-demo-cw8z -e dev --code
OK github-demo-cw8z/dev/hello
runs:   on request (TypeScript on Bun)
url:    https://hello-4qcf.cloud-dev-central-1.stackblaze.app
status: sleeping (wakes on the next request)
code:   242 bytes (print it with --code)
Bun.serve({
  port: Number(process.env.PORT ?? 8080),
  async fetch(req) {
    const name = req.method === "POST" ? (await req.text()) || "world" : "world";
    return Response.json({ hello: name, path: new URL(req.url).pathname });
  },
});

functions deploy

Usage: stackblaze functions deploy|new [options] [name]

Create a function, or update its code, schedule or port

Options:
  --api-url <url>        StackBlaze API base URL (env STACKBLAZE_API_URL)
  --token <token>        API token, sb_pat_... (env STACKBLAZE_TOKEN)
  -p, --project <name>   Project name
  -e, --env <name>       Environment name (default: production)
  -a, --app <name>       App name
  --json                 Output JSON (same as -o json) (default: false)
  --name <name>          Function name (or pass it positionally)
  -f, --file <path>      The TypeScript file to run (up to 96 KB)
  --schedule <cron>      Run on a cron schedule (five fields) instead of on
                         request
  --no-schedule          Run on request again (remove the schedule)
  --port <n>             Port the function listens on (default 8080)
  --wait                 Wait until the function is ready (default: false)
  --timeout <seconds>    Max time for --wait, default 300
  -o, --output <format>  Output format: text or json (choices: "text", "json")
  -h, --help             Print help

Examples:
  stackblaze functions deploy hello --file index.ts --wait
  stackblaze functions deploy hello --file index.ts           # update the code
  stackblaze functions deploy report --file report.ts --schedule "0 2 * * *"
  stackblaze functions deploy report --no-schedule            # run on request again

A function is one TypeScript file run by Bun, with no build step. Import npm
packages by name (import { Hono } from "hono@4"); Bun installs them when the
function starts. Read the port from process.env.PORT.

Without a schedule the function gets a URL, sleeps when idle and wakes on the
next request. With --schedule it runs at those times and has no URL.

An existing function keeps its variables and settings; only what you pass
changes. Its logs (a scheduled function: its runs): stackblaze logs -a <name>.

Example

Create a function from one TypeScript file and wait until it is ready. Running the same command again with a changed file updates its code.

cat hello.ts
stackblaze functions deploy hello --file hello.ts --wait -p github-demo-cw8z -e dev
Bun.serve({
  port: Number(process.env.PORT ?? 8080),
  async fetch(req) {
    const name = req.method === "POST" ? (await req.text()) || "world" : "world";
    return Response.json({ hello: name, path: new URL(req.url).pathname });
  },
});
Waiting for function hello-4qcf…
  hello-4qcf: Waiting for hello-4qcf-kuberoapp-web deployment
OK Function hello is ready
url: https://hello-4qcf.cloud-dev-central-1.stackblaze.app

functions invoke

Usage: stackblaze functions invoke [options] <name>

Call a function's URL and print the answer

Options:
  --api-url <url>        StackBlaze API base URL (env STACKBLAZE_API_URL)
  --token <token>        API token, sb_pat_... (env STACKBLAZE_TOKEN)
  -p, --project <name>   Project name
  -e, --env <name>       Environment name (default: production)
  -a, --app <name>       App name
  --json                 Output JSON (same as -o json) (default: false)
  --method <http>        HTTP method (default: "POST")
  --body <text>          Request body
  --path <path>          Path to call (default /)
  -o, --output <format>  Output format: text or json (choices: "text", "json")
  -h, --help             Print help

Example

Call a function with a request body (POST by default), then with a GET on another path. A sleeping function wakes for the call.

stackblaze functions invoke hello -p github-demo-cw8z -e dev --body Ada
stackblaze functions invoke hello -p github-demo-cw8z -e dev --method GET --path /status
OK Invoked hello (HTTP 200)
{"hello":"Ada","path":"/"}
OK Invoked hello (HTTP 200)
{"hello":"world","path":"/status"}

functions delete

Usage: stackblaze functions delete [options] <name>

Delete a function

Options:
  --api-url <url>        StackBlaze API base URL (env STACKBLAZE_API_URL)
  --token <token>        API token, sb_pat_... (env STACKBLAZE_TOKEN)
  -p, --project <name>   Project name
  -e, --env <name>       Environment name (default: production)
  -a, --app <name>       App name
  --json                 Output JSON (same as -o json) (default: false)
  -y, --yes              Skip confirmation (default: false)
  -o, --output <format>  Output format: text or json (choices: "text", "json")
  -h, --help             Print help

Example

Delete a function. Type the function name to confirm, or pass -y.

stackblaze functions delete hello -p github-demo-cw8z -e dev
!  This will DELETE function hello in github-demo-cw8z/dev.
Type the function name to confirm: hello
OK Deleted function hello from github-demo-cw8z/dev

On this page