Invoke a function
How to call a deployed function with the JavaScript SDK or over HTTP, and how your function knows who is calling.
1. Call from the SDK
invoke is the only call a public key can make. It works the same in a browser and on a server.
The generic invoke<T> only types the response. The name and the body are not checked at compile time.
list, get, listJobs, enqueueJob and the other management methods need a service_role key and belong on your server. A public key receives 403. See who can call what.
2. Describe the request
Your function receives exactly the request you describe, not a wrapper around it.
| Option | Default | What the function sees |
|---|---|---|
method | POST | req.method |
path | / | new URL(req.url).pathname |
headers | none | req.headers, except the platform headers listed below |
body | none | await req.json() (or req.text() for a string) |
timeout | client default (30 s) | not visible: cancels your call |
signal | none | not visible: cancels your call |
responseType | 'json' | not visible: how the SDK decodes the response, see non-JSON responses |
Rules worth knowing:
GETandHEADare sent without a body.- A body that is not a string is sent as JSON, with
content-type: application/jsonunless you set one. A string body is sent as-is and also getscontent-type: application/json, so read it withreq.text(). - With no
body, the function receives a request with no body. A bareawait req.json()throws, so writeawait req.json().catch(() => ({}))when the call can be made without a payload. - The body must be JSON: an object, array, string, number or boolean. A
Blob,ArrayBuffer, typed array,FormData,URLSearchParamsorReadableStreamis refused with the error codeinvalid_bodybefore any request is sent. - Framing headers (
content-length,transfer-encoding,connection,host, …) are ignored.
3. Read the caller's identity
The platform validates the key and the user's token before your function runs, then adds these headers:
| Header | Value |
|---|---|
x-aura-role | anon, authenticated or service_role |
x-aura-user-id | The user's id when x-aura-role is authenticated, otherwise absent |
x-aura-project-id | The project id |
authorization | The user's JWT, only for a signed-in user |
apikey | The key used for the call |
Real results of this call with three different keys:
The platform discards authorization, apikey, x-request-id and every x-aura-* header that a caller puts in headers, whatever their case. Only the values it verified itself reach your function. Other custom headers pass through unchanged.
The x-request-id of the call is not forwarded to your function. To correlate a call with a log line, generate your own id, send it in headers and log it in the function.
4. Call over HTTP
Without the SDK, send a JSON object that describes the request. The body field is what your function receives.
Both apikey and Content-Type: application/json are required. Add Authorization: Bearer <user JWT> to call as a signed-in user. The default response is an envelope; the X-Aurabase-Invoke-Mode: raw header returns your function's own response instead, see non-JSON responses.
5. Read the result
invoke never throws. It returns { data, error }:
Test data rather than error when you need the value: TypeScript then knows it is not null. To handle failures precisely, read errors, timeouts and retries.