Groundfloor Docs

Functions

Write a handler, deploy it, and call it over HTTP.

A Function runs your code when a request arrives and returns a response. Use it for APIs, webhooks, data transformations and tools for AI agents. You write only the handler; Coderunner provides the HTTP endpoint, routing and scaling.

Before you start

  • A workspace where you're a Writer, Admin or Owner.
  • For the CLI: npm install -g @groundfloorcloud/cli, then gf login and gf workspaces use <workspace-id>.

Write the handler

Every handler receives two arguments:

  • payload — the JSON sent by the caller.
  • context — reserved for information from the runtime. Don't rely on its contents yet.

Whatever the handler returns becomes the response. You can return anything; this shape is the convention, and every example in these docs uses it:

handler.js
const handler = async (context, payload) => {
  if (!payload?.name) {
    return {
      statusCode: 400,
      body: { error: "name is required" },
      headers: { "content-type": "application/json" },
    };
  }
  return {
    statusCode: 200,
    body: { greeting: `Hello, ${payload.name}` },
    headers: { "content-type": "application/json" },
  };
};

module.exports = { handler };

You don't create a server, listen on a port, add a /health route or write a Dockerfile. The same handler in Python, .NET, Go and Rust is in each language reference.

Deploy it

Zip your project

Put your files at the root of the ZIP, not inside a folder. The ZIP can be up to 64 MiB; a larger one is refused.

Create the Coderunner

Go to Build → Coderunner and create one. Choose its language and the Function type.

Upload and deploy

Upload the ZIP. When the build finishes, deploy the new version. The Coderunner's page then shows its address under Invoke address.

From your project folder:

gf deploy --name greeter --workload-type function

The CLI detects Node.js (package.json) and Python (requirements.txt or pyproject.toml). For other languages add --runtime, for example --runtime dotnet or --runtime go. gf deploy creates the Coderunner if it doesn't exist, uploads your code, waits for the build, deploys it and prints the URL. It also prints an access: line saying who can call it, and the command to change that.

API=https://platform.groundfloor.cloud/v1/workspaces/$WORKSPACE_ID/coderunners

# 1. Create the Coderunner
curl -X POST "$API" -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{"title":"greeter","runtime":"node","workload_type":"function"}'

# 2. Upload your ZIP as a new version. The response includes the version's ID.
curl -X POST "$API/$CODERUNNER_ID/upload" -H "Authorization: Bearer $TOKEN" \
  -F "file=@greeter.zip"

# 3. When the version's build has finished (GET $API/$CODERUNNER_ID/versions), deploy it
curl -X POST "$API/$CODERUNNER_ID/deploy" -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" -d '{"version_id":"'"$VERSION_ID"'"}'

See the Coderunners API for every field.

Call it

Every Function has a Deployment URL of this form. The Client Portal shows it as the Invoke address on the Coderunner's page, and gf deploy prints it:

https://invoke.groundfloor.cloud/v1/coderunners/<coderunner-id>

Send a POST with a JSON object to it, with a bearer token:

curl -X POST "https://invoke.groundfloor.cloud/v1/coderunners/$CODERUNNER_ID" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name":"Ada"}'

The JSON object reaches your handler as payload, and the call returns your handler's response. The URL is the same for every version you deploy. Only the body is passed on: any path you add after the ID, query string or headers you send never reach your code.

Who can call it

Each Function and Job has an invoke access setting:

AccessWho can call the Deployment URL
tokenCallers with a token for this workspace (below). The default for every new Function and Job
publicAnyone, without a token. A token sent anyway is ignored and never passed to your code. Functions only
offNobody: the URL answers 404

In the Client Portal these are Login required (token), Public and Off. Whatever the setting, you can still start runs with Run on the Coderunner's page, gf coderunner run or the API.

Functions created before invoke access existed are public until you change them. Switch them to token unless they really must be open to anyone.

With token, use one of these:

CallerToken
You, trying it from a terminalgf token (you need the Writer, Admin or Owner role in the workspace)
A server, CI pipeline or another CoderunnerAn M2M token from a machine client in the same workspace

Tokens your app users get from signing in to a Shell app or a standalone app are refused, and so is a token for another workspace (403). To call code from a browser app with the user's token, use a Service backend instead.

Change who can call it

You need the Writer, Admin or Owner role. Every change is recorded in the activity log.

Open the Coderunner from Build → Coderunner and find Invoke address:

  • Who can call it: choose Off, Login required or Public. Choosing Public asks you to confirm with Make public, since anyone who knows the address can then call it and every call counts towards your usage. Choosing Off asks you to confirm with Turn off: every caller of the address gets "not found" until you turn it back on, while Run on this page still works. A Job has no Public option.
  • Address: the address as POST <address>, with a copy button. It only accepts POST, so opening it in a browser doesn't work.
  • Example: a curl command you can copy. With Login required, replace <YOUR_TOKEN> with a token from gf token, or an M2M token from gf m2m token for servers and CI.

A public Function shows a warning, Anyone with the address can call this function. Click Switch to Login required to require a token, or Keep public if it has to stay open, for example as a public webhook.

With gf 0.2.9 or later:

gf coderunner invoke-access -c greeter          # show the current setting and address
gf coderunner invoke-access -c greeter token    # or off, or public

public and off show the workspace, the Coderunner and the address, and ask you to confirm; token applies without asking. In a script, add --yes, and name the workspace with -w <workspace-id> or GROUNDFLOOR_WORKSPACE_ID: without a terminal, the CLI won't make a Function public or turn its address off in your saved default workspace. --json prints the result as JSON. A machine client needs Can deploy services.

curl -X PUT "https://platform.groundfloor.cloud/v1/workspaces/$WORKSPACE_ID/coderunners/$CODERUNNER_ID/invoke" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{"access":"token"}'

A machine client needs Can deploy services. See Invoke access.

AI agents using the Groundfloor MCP can switch a Function to Login required, or to Off after confirming with you, but never to Public: that's a step you take yourself, in the Client Portal or the CLI.

Errors

Errors are short fixed sentences. They never include your function's own error output; read that in the Process Log.

StatusMeaning
400The body isn't a JSON object
401Access is token and no valid token was sent
402Your Free organization is paused because it used up its free usage
403The token can't write to this workspace, belongs to another workspace, or is an app user's token
404No such Function or Job, its access is off, or it's a Service (call its own URL)
409Nothing is deployed, or it's a Schedule (Schedules have no Deployment URL)
413The body is larger than the limit
415The body isn't sent as Content-Type: application/json
423The workspace is suspended
429Too many calls, or too many running at once. Wait for the Retry-After seconds
502The function failed, didn't answer within the time limit, or its response was too large
503The platform is busy. Wait for the Retry-After seconds

Limits

LimitDefault
Request body1 MiB, one JSON object
Response1.5 MiB. A larger response is 502, or, if part of it was already sent, the connection is closed before the end
Time100 seconds for the whole call, including the response
Calls per minute, per Function60 per caller (per token, or per IP address when public) and 600 in total. A Job can be started 10 times a minute
Calls per minute, per IP address300 to one Function or Job, and 600 across all of them, whatever the token
Calls running at onceAbout 20 per workspace and per organization, of which at most 10 without a token

Limits can differ by region. Over a rate or running-at-once limit you get 429 with Retry-After.

  • No streaming. The caller gets the response when your handler returns; a Function can't stream partial results or hold a connection open.
  • Response headers. Only Content-Type, Cache-Control, ETag, Last-Modified and Content-Language from your response are kept; cookies and CORS headers your code sets are dropped. Browsers on any site can call the URL, but without cookies or other credentials.
  • Signed webhooks. Providers such as Stripe and GitHub sign the exact bytes of the request body. A Function receives the parsed JSON, not those bytes or the signature headers, so it can't check the signature. Receive those webhooks in a Service.
  • Large responses or long work. Use a Service, or start a Job and store the result.

Other ways to run it

You can also run it without the URL:

  • Client Portal: open the Coderunner and use Run with a JSON payload.
  • CLI: gf coderunner run -c greeter --payload '{"name":"Ada"}'
  • API: POST https://platform.groundfloor.cloud/v1/workspaces/{workspace_id}/coderunners/{coderunner_id}/run with the payload itself as the JSON body.

Scaling

A Function scales with its traffic, between a minimum and a maximum number of instances that you set on the deployment.

  • Minimum 0 — no instances run while it's idle, and one starts when a request arrives.
  • Minimum 1 or more — instances stay warm, so the first request doesn't wait for one to start.

A Function is billed for the time its instances are up, not per request. After the last request it stays up for a minute or two before scaling to zero, and that time counts. See How compute is billed.

Set the range in the Client Portal's deploy dialog or with the API. See Configuration and secrets.

Keeping files

Anything a Function writes to local disk is lost when it restarts, redeploys or scales to zero. To keep files, add a persistent disk, mounted at /data, and write them there. A Function with a disk runs at most one instance.

Check that it worked

The call returns your handler's response. If it fails, open Observe → Process Log to see your function's output and errors; see Logs and troubleshooting.

Next steps

On this page