RimbraDocsDashboard

Functions

Small JavaScript or TypeScript handlers that answer HTTP requests at their own address or run before your app.

Create a function

  1. Open Functions in the dashboard sidebar. Functions is a $4/month add-on on any plan; without it the page asks you to pay first, from your points or by bank transfer, and unlocks as soon as the payment is confirmed. Then choose New function.
  2. Give it a name. It answers at https://<name>.rimbra.live right away. Names are shared with apps, so a name belongs to one function or one app.
  3. Start from the template in JavaScript or TypeScript, or pick a file from one of your deployed applications, like functions/hello.js.
  4. Edit the code in the dashboard and choose Deploy (or press ⌘S). Each deploy is a new version and serves the next request.
js
export default {
  async fetch(request, env, ctx) {
    const url = new URL(request.url)
    if (url.pathname === "/hello") {
      return Response.json({ hello: "world" })
    }
    return new Response("Not found", { status: 404 })
  },
}

What the code gets

The module exports an object with a fetch method. It runs for every request and returns a Response. Request, Response, Headers, URL, fetch, crypto and the node: built-ins are available. Imports of npm packages are not bundled yet, so keep a function to one file.

ArgumentWhat it is
requestThe visitor's request: method, url, headers and body, with X-Real-IP set to their address.
envYour variables and secrets as env.NAME, bindings such as env.CACHE, and env.next() for middleware.
ctx.waitUntil(promise)Keeps work going after the response is ready, like logging. The request waits for it to finish.

Run before your app

Under Routes, add an application and a path such as /api/* or /login. Every request to that path on the application, at its rimbra.live address and its custom domains, reaches the function first. Return a Response to answer it, or env.next() to let it through to the app. Pass a changed request to env.next() to send different headers on to the app.

js
export default {
  async fetch(request, env) {
    if (request.headers.get("authorization") !== `Bearer ${env.ADMIN_TOKEN}`) {
      return new Response("Not allowed", { status: 401 })
    }
    const headers = new Headers(request.headers)
    headers.set("x-checked-by", "function")
    return env.next(new Request(request, { headers }))
  },
}

Variables, secrets and bindings

  • Add variables under Variables and secrets. Secrets are encrypted at rest and never shown again in the dashboard.
  • Changes apply to the next request; no redeploy is needed.
  • Bindings let the code use other Rimbra products, like await env.CACHE.get("key"). The Bindings card appears once those products are available to your workspace.

Logs, metrics and versions

  • console.log, warn and error appear under Logs, next to the last 100 requests with their status, time and CPU time.
  • Metrics show requests and errors for today and the last 14 days, and p50 and p95 response times.
  • The last 10 versions are kept. Roll back to any of them and the next request runs it, with no rebuild.
  • Send a test request from the Code card to try the live version without leaving the dashboard.

Price and limits

Functions is a $4/month add-on on any plan: 300,000 requests a month and up to 5 functions, then $1 per extra million requests, paid from your points. The $10/month Developer pack includes Functions, Queues, Tunnels and Buckets with double the allowances. No plan includes Functions on its own.

  • CPU time counts only the time your code is working, not time spent waiting on fetch or a database. Request and response bodies can be up to 10 MB, and code up to 1 MB.
  • Requests reset each billing cycle. Past the included requests they are paid from your points while pay as you go is on. With it off, or with no points left, requests stop at the allowance until the next cycle.
  • Without the add-on, functions answer 402 and can be opened, tested and deleted, but not changed or deployed. Nothing is deleted, and adding Functions turns them back on at once.
Functions add-onDeveloper pack
Functions510
Requests a month300,000600,000
Past that$1 per million$1 per million
CPU time per request50 ms on Free, 200 ms on paid plans50 ms on Free, 200 ms on paid plans
Memory per function128 MB128 MB
Time to answer30 s30 s

When a limit is reached

Visitors get a JSON body with an error code and a plain message. The function's logs show the detail.

StatuserrorMeaning
402plan_requiredThe workspace doesn't have the Functions add-on, so the function is paused. Adding Functions turns it back on at once.
429function_request_limitThe workspace used its included requests and pay as you go is off or out of points. Requests come back when the cycle resets or after adding points. Retry-After is set.
503cpu_limit_exceededThe request used more than its CPU time and was stopped.
503memory_limit_exceededThe function used more than 128 MB and was stopped.
504timeoutNo answer within 30 seconds.
500function_errorThe code threw an error or didn't return a Response.

From an AI agent

Through Rimbra MCP, agents can list functions, deploy a function (creating it if needed) and read its logs with list_functions, deploy_function and get_function_logs.