Galon Cloud
Galon Cloud

Galon Functions

Run JavaScript at a public HTTPS address: upload an ES module, deploy it, call it.

Markdown · API reference · OpenAPI

Before you start

  • A Galon account, a project and a prepaid balance. From the console, no key: open Functions, pick a template, select Deploy function — the function is live at its address. From the API below: a key with functions:deploy and job:read; the environment of a deploy must be the key's (test with a test key).

Quickstart

Every example reads GALON_API_BASE (https://api.galon.ai/v1) and GALON_API_KEY from the environment and prints the HTTP status and the JSON body.

1. Set your key. Export the base URL and your key.

curl

export GALON_API_BASE="https://api.galon.ai/v1"
export GALON_API_KEY="gln_test_..."

2. Upload the code. An ES module with export default { fetch }, sent as application/javascript. The answer gives source.source_ref and source.source_sha256.

curl

cat > worker.js <<'JS'
export default {
  async fetch(request) {
    return new Response("Hello from Galon Functions");
  },
};
JS
curl -sS -X POST "$GALON_API_BASE/functions/sources" \
  -H "Authorization: Bearer $GALON_API_KEY" \
  -H "Content-Type: application/javascript" \
  --data-binary @worker.js \
  -w '\n%{http_code}\n'

Python 3 (standard library)

import json, os, urllib.error, urllib.request

source = b"""export default {
  async fetch(request) {
    return new Response("Hello from Galon Functions");
  },
};
"""
req = urllib.request.Request(os.environ["GALON_API_BASE"] + "/functions/sources", data=source, method="POST",
                             headers={"Authorization": "Bearer " + os.environ["GALON_API_KEY"],
                                      "Content-Type": "application/javascript"})
try:
    with urllib.request.urlopen(req) as res:
        print(res.status, json.load(res))
except urllib.error.HTTPError as err:
    print(err.code, json.load(err))

Node.js 18+ (fetch)

const source = "export default {\n  async fetch(request) {\n    return new Response(\"Hello from Galon Functions\");\n  },\n};\n";
const res = await fetch(`${process.env.GALON_API_BASE}/functions/sources`, {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.GALON_API_KEY}`, "Content-Type": "application/javascript" },
  body: source,
});
console.log(res.status, JSON.stringify(await res.json()));

3. Deploy it. name: lowercase, up to 40 characters. The answer is 202 with the deploy job and the function's public url.

curl

curl -sS -X POST "$GALON_API_BASE/functions/deployments" \
  -H "Authorization: Bearer $GALON_API_KEY" \
  -H "Idempotency-Key: quickstart-function-0001" \
  -H "Content-Type: application/json" \
  -d '{"name": "hello", "source_ref": "'"$GALON_SOURCE_REF"'", "source_sha256": "'"$GALON_SOURCE_SHA256"'", "environment": "test", "compatibility_date": "2026-11-01"}' \
  -w '\n%{http_code}\n'

Python 3 (standard library)

import json, os, urllib.error, urllib.request

req = urllib.request.Request(
    os.environ["GALON_API_BASE"] + "/functions/deployments",
    data=json.dumps({"name": "hello", "source_ref": os.environ["GALON_SOURCE_REF"], "source_sha256": os.environ["GALON_SOURCE_SHA256"], "environment": "test", "compatibility_date": "2026-11-01"}).encode(),
    headers={"Authorization": "Bearer " + os.environ["GALON_API_KEY"],
             "Idempotency-Key": "quickstart-function-0001",
             "Content-Type": "application/json"},
    method="POST",
)
try:
    with urllib.request.urlopen(req) as res:
        print(res.status, json.load(res))
except urllib.error.HTTPError as err:  # the error body carries detail.code and detail.next_action
    print(err.code, json.load(err))

Node.js 18+ (fetch)

const res = await fetch(`${process.env.GALON_API_BASE}/functions/deployments`, {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.GALON_API_KEY}`, "Idempotency-Key": "quickstart-function-0001", "Content-Type": "application/json" },
  body: JSON.stringify({name: "hello", source_ref: process.env.GALON_SOURCE_REF, source_sha256: process.env.GALON_SOURCE_SHA256, environment: "test", compatibility_date: "2026-11-01"}),
});
console.log(res.status, JSON.stringify(await res.json()));

4. Wait for the deploy. Read the job until status is final.

curl

curl -sS -X GET "$GALON_API_BASE/functions/jobs/${GALON_FUNCTION_JOB_ID}" \
  -H "Authorization: Bearer $GALON_API_KEY" \
  -w '\n%{http_code}\n'

Python 3 (standard library)

import json, os, urllib.error, urllib.request

req = urllib.request.Request(
    os.environ["GALON_API_BASE"] + "/functions/jobs/" + os.environ["GALON_FUNCTION_JOB_ID"],
    headers={"Authorization": "Bearer " + os.environ["GALON_API_KEY"]},
    method="GET",
)
try:
    with urllib.request.urlopen(req) as res:
        print(res.status, json.load(res))
except urllib.error.HTTPError as err:  # the error body carries detail.code and detail.next_action
    print(err.code, json.load(err))

Node.js 18+ (fetch)

const res = await fetch(`${process.env.GALON_API_BASE}/functions/jobs/${process.env.GALON_FUNCTION_JOB_ID}`, {
  method: "GET",
  headers: { Authorization: `Bearer ${process.env.GALON_API_KEY}` },
});
console.log(res.status, JSON.stringify(await res.json()));

5. Call your function. The function answers on its own public HTTPS address; no key is needed.

curl

curl -sS "$GALON_FUNCTION_URL" -w '\n%{http_code}\n'

Concepts

Module format. An ES module whose default export has fetch(request, env, ctx). Service-worker scripts and WebAssembly are refused.

Sources, then deploys. POST /v1/functions/sources stores the code and returns its reference; POST /v1/functions/deployments deploys a reference under a name; POST /v1/functions/deletions removes a revision.

Pricing on the API. GET /v1/functions/pricing returns the current price per million requests and per million CPU milliseconds, in USD.

Outbound requests. A function calls public websites over HTTPS on port 443, by host name. IP addresses, private networks, credentials in the URL and other ports (25 included) are refused.

Variables and secrets. The variables and secrets of your project's environment (Project → Variables) reach your functions as env.NAME — fetch(request, env, ctx). A secret never appears in a revision or a log; deploy again after a change so the new values are taken.

Revisions and rollback. Each deployment is a revision. In the console, roll back to any earlier one in one click: a new deployment of that code, same address.

API reference

These routes are served by the code but are not in the OpenAPI contract yet:

MethodPathAuthWhat it does
GET/v1/functions/pricingkey job:readCurrent prices in USD
POST/v1/functions/sourceskey functions:deployUpload an ES module
POST/v1/functions/deploymentskey functions:deployDeploy a source under a name
POST/v1/functions/deletionskey functions:deployDelete a revision
GET/v1/functions/jobs/{job_id}key job:readRead a deploy or delete job

Errors

Every error is JSON: {"detail": {"code", "message", "next_action"}}. next_action.code is stable, next_action.hint says what to do next, and console_url is added when a person must act. The codes below are those this service returns.

StatusCodeWhennext_action
413functions_request_too_largeThe request body is over the limit (10 MiB).fix_request
504functions_timeoutThe function ran past its time limit (30 s); the container was restarted.retry_later
402functions_account_blockedThe project's balance is used up: invocations are refused until a top-up.top_up_balance
401api_key_invalidNo key, or an unknown, revoked or expired key.use_valid_api_key
403scope_missingThe key lacks functions:deploy or job:read.add_missing_scope
403functions_tenant_not_allowedFunctions is not open to this account.check_project_access
400idempotency_key_requiredNo Idempotency-Key on a deploy.fix_request
415functions_module_not_jsThe source is not sent as JavaScript.fix_request
422functions_module_not_jsThe content is not an ES module with a default export.fix_request
413functions_module_too_largeThe script is over the size limit.fix_request
422functions_name_invalidThe name does not match [a-z][a-z0-9-]{0,39}.fix_request
403functions_environment_mismatchenvironment differs from the key's.use_key_of_right_environment
402functions_balance_exhaustedThe prepaid balance is used up.top_up_balance
409functions_operation_in_progressAnother deploy of this function is running.resolve_conflict
503functions_temporarily_unavailableTemporary: retry with the same Idempotency-Key.retry_later
next_actionWhat to do
fix_requestThe request is invalid. Fix it as 'message' and 'field' say, using the OpenAPI contract, then send it again. Do not retry it unchanged.
retry_laterTemporary error on Galon's side. Retry with exponential backoff and the same Idempotency-Key; if it lasts, contact support with the X-Request-Id header.
top_up_balanceThe project balance does not cover this call. Top up the balance in USD in the console, then retry with the same Idempotency-Key.
use_valid_api_keySend a valid Galon API key as 'Authorization: Bearer <key>'. If the key was revoked or has expired, create a new one in the console and retry with it.
add_missing_scopeThis key does not have the scope this call needs. Create a key with that scope in the console, then retry the same call with the new key.
check_project_accessThis project or key is not allowed to do this. Its owner must review the project, its key and its account in the console.
use_key_of_right_environmentThis call is not allowed for this key's environment (test or live). Use a key of the other environment, created in the console.
resolve_conflictThe request conflicts with the resource state or with an earlier request under the same Idempotency-Key. Read the resource first; for a new intent, use a new Idempotency-Key.

Limits, free tier and pricing

Read from the platform code each time this page is served.

LimitValue
Script size (default)1 MiB
Request body (max)10 MiB
Variables and secrets per environment100
Variable value (max)4 KiB
Secret value (max)8 KiB

Usage prices, in US dollars, read from the price grid served by the platform each time this page is served. Paid from the prepaid balance.

ItemPriceUnit
requests0.0253 USDper million requests
cpu_ms0.011528 USDper million CPU-ms

Functions are paid per request and per CPU millisecond from the prepaid balance; GET /v1/functions/pricing returns the prices in force.

FAQ

How am I billed?

Per request and per CPU millisecond, at the public prices, from the project's prepaid balance, settled every hour; nothing is billed when nothing runs.

**Can I bring existing fetch handler code?**

Modules with export default { fetch } run as they are.

Do I need a key to call my function?

No: the function's address is public. Protect it in your code if needed.

Do I need a key to deploy from the console?

No: the console deploys under your session (an administrator of the project). Keys are for your code and your AI agents.

How do I give a secret to a function?

Add it to your project's variables as a secret, then deploy the function again: it reads env.NAME. Keep secrets out of the code.

More