Skip to content

Declare endpoints, auth, subscriptions and schedules

Everything a function needs is declared in its code. The platform reads the declarations from the built artifact when you publish; there is no separate manifest to keep in step. The result is the function’s describe document (field-by-field in Function describe document and ABI). If the code does not declare it, the runner will not let the function do it.

var greeting = fn.Config("GREETING")
var orders = fn.DB("main")
func init() {
fn.Webhook("POST /events/order-created", onOrderCreated, fn.Timeout(10*time.Second), fn.MaxBody(256<<10))
fn.Platform("GET /orders/{id}", getOrder)
fn.Open("GET /healthz", health)
fn.Subscribe("shop:orders:order:created", "/events/order-created", fn.Mode("IMMEDIATE"))
fn.Schedule("0 */15 * * * *", "/events/order-created", fn.Timezone("Africa/Johannesburg"))
fn.HTTPAllow("api.stripe.com")
fn.Emits("shop:orders:order:invoiced")
}
func main() {}

Handlers are plain net/http handlers. Endpoint options: fn.Timeout, fn.MaxBody, fn.CORS. Subscription options: fn.Mode, fn.MaxRetries, fn.DataOnly, fn.SubTimeout. Schedule options: fn.Timezone, fn.Payload.

Every endpoint names exactly one auth mode. There is no default.

Declared with Describe auth Who calls it What the runner checks first
Webhook webhook subscriptions, schedules, dispatch jobs the platform’s delivery signature
Platform platform people and services holding platform tokens a valid platform access token; your code then checks the caller’s permissions and client access
Open none anyone nothing: for health checks and third-party webhooks you verify yourself

A webhook endpoint accepts POST only (the SDKs refuse anything else at registration). Paths use Go’s routing patterns: literal segments, {name}, and a trailing {rest...}. The most specific pattern wins; a path that matches under another method answers 405 with Allow.

A Platform endpoint authenticates the token and nothing more. Your handler decides whether the principal may do this: HasPermission (with * segment wildcards), CanAccessClient(id), CanAccessClientCode("acme"). Skipping that check is the common mistake: a valid token for any principal gets through the runner.

Each endpoint can override the function’s timeout (default 30 s) and maximum request body (default 1 MiB), and declare a CORS policy (origins, methods, headers, credentials). Without a CORS declaration the runner does nothing CORS-related for the endpoint.

Which service account signs a webhook delivery

Section titled “Which service account signs a webhook delivery”

A Webhook endpoint verifies the delivery signature with the signing secret of a service account. By default that is the application’s service account (the oldest active account linked to the application). If deliveries to your function are signed by another account, for example the one on a connection, give the function that account:

Terminal window
fcdev fn deploy shop.orders . --create --service-account shop-integration # at creation
fcdev fn set shop.orders --service-account shop-integration # change it
fcdev fn set shop.orders --clear-service-account # back to the application's

The value is the account’s code or id; the platform checks that it exists, is active and that you may use it. A function that names an account uses only that account’s secret: if the account is deactivated or deleted, every webhook delivery is refused 401 INVALID_SIGNATURE rather than quietly falling back to the application’s account, and the platform logs function webhook secret is empty. Credentials are cached for one minute, so a change or a rotated secret reaches runners in about that time.

A delivery that arrives before the runner has the signing secret at all (the account was only just attached) is answered 503 WEBHOOK_SECRET_PENDING with Retry-After: 5, not 401: the platform retries a 503 and would not retry a 401, which would lose the delivery.

Subscribe(eventType, path) asks for an event type to be delivered to one of your webhook endpoints. Schedule(cron, path) asks for a cron firing to be. In both, the path must be a literal path that lands on a webhook endpoint.

  • Cron is 6-field, seconds first: sec min hour day-of-month month day-of-week, so 0 */15 * * * * is every 15 minutes. A 5-field expression is rejected at publish. The timezone defaults to UTC. See Cron.
  • A subscription without a mode keeps each message group in order and moves on past a failure (NEXT_ON_ERROR), like every other subscription. Ask for IMMEDIATE if you do not need ordering. Because dispatch groups are per subscriber, a function’s BLOCK_ON_ERROR subscription blocks only its own deliveries; see Ordering.
  • A schedule fires exactly once per tick. Concurrency is the receiver’s job: a slow function can still be running when the next tick arrives.

Subscriptions and schedules are not created when you publish. They are created, updated or removed when you promote a version to live, to match what that version declares. Promoting an older version back restores its wiring. See Publish, promote and use aliases.

Declaration Grants
Config("KEY") / Secret("KEY") reading that key. Values are set on the platform per function (secrets and config)
DB("name") a database handle. The connection string is a platform setting; the pool belongs to the runner
HTTPAllow("api.example.com") or *.example.com outbound HTTP to that host, checked on redirects too
Emits("app:subdomain:aggregate:event") emitting that event type, for your own application only
Dispatches(target, path) creating dispatch jobs (guide)
UsesPlatformToken() a platform access token (guide)
TraceContexts(...) named trace contexts (guide)

Promotion is refused while a config key, secret or database the version declares has no value.

Limit Default Set per function
Memory per instance 64 MB yes
Concurrent calls 16 yes
Timeout 30 s yes, and per endpoint
Request body 1 MiB yes, and per endpoint

A function past its concurrency limit answers 429; deliveries wait and try again without spending an attempt. A function that needs more memory than it may have fails only its own call. For the database limits (10,000 rows or 8 MiB per result, open transactions rolled back at the end of the call) and the outbound limits (responses over 16 MiB refused), see Functions.