Edge Compute and Runtime
Edge Compute and Runtime
Compute Functions let you run your own server-side code next to your WoWSQL project without deploying or scaling servers. You write a small Node.js or Python handler, deploy it from the dashboard, and call it over HTTPS at your project host. Typical uses are payment and third-party webhooks, calls to external APIs that need a secret key, image or document processing, AI calls and short background jobs.
In the dashboard this feature is called Compute (page title Compute Functions). The pricing page lists it as Edge Functions. They are the same product. Compute Functions are not the same as SQL functions and stored procedures, which run inside Postgres and are managed under Procedures and Triggers.
In short:
- Two runtimes: Node.js and Python. One source file per function.
- Each function is an HTTP endpoint at
https://{project-slug}.wowsqlconnect.com/functions/v1/{function-name}. - Calls are authenticated with your project API key or a signed-in user's access token. You can turn verification off per function for webhooks.
- Project secrets are injected as environment variables. Changing a secret does not require a redeploy. Secret values are write-only: they cannot be read back after you save them.
- Function code, invocation logs and Compute settings are stored in your project database, in the
functionsschema. - You can restrict which browser origins may call your functions with
CORS_ORIGINS, and choose how long invocation logs are kept. - Usage is measured in execution hours per month: Free 5 hours, Pro 100 hours, Scale 100 hours.
How It Works
A request to your function goes through the same project gateway that serves /rest/v1, /auth/v1, /storage/v1 and /realtime/v1. The gateway forwards /functions/v1/... to the compute runtime in your project's region, which runs your handler and returns its response.
| Step | What happens |
|---|---|
| 1 | The client sends a request to https://{project-slug}.wowsqlconnect.com/functions/v1/{name}. |
| 2 | If the request carries an apikey, Authorization or x-wowsql-api-key header, the gateway validates it. An invalid key is rejected here. |
| 3 | The runtime looks up the function, checks the project's remaining compute hours (returns 402 when they are used up) and, if Verify JWT / API key is on, requires a valid credential (returns 401 otherwise). |
| 4 | The runtime starts a fresh, short-lived Node.js or Python process for this request, passes it the request as an event object, and injects your environment variables and secrets. |
| 5 | The handler's return value becomes the HTTP response. Execution time is recorded against the project's monthly budget and shown under Recent invokes. |
Runtime model
- Fresh process per request. Every invocation runs in a new process in a new temporary working directory, which is deleted afterwards. Nothing in memory or on disk survives between requests. Keep state in your database or in Storage.
- One file, no package install. Your function is a single source file (up to 256 KB). There is no
package.jsonorrequirements.txtstep, so use the language's built-in modules: for examplecryptoandfetchin Node.js, andjson,hmacandurllibin Python. - Node.js uses CommonJS. Export the handler with
module.exports(orexports.handler). ES module syntax such asexport defaultat the top level is not supported. - Async is supported. Node.js handlers can return a Promise. Python handlers can be
async def.
Regions
Functions run on the data plane of the region your project lives in, so calls from a function to your database stay inside that region. WoWSQL projects can be created in:
| Region | Code |
|---|---|
| Mumbai, India | ap-south-1 |
| US East (N. Virginia) | us-east-1 |
| Europe (Frankfurt) | eu-central-1 |
A function is not replicated to other regions. Despite the "edge" name, it runs in your project's region only, not at a global edge location.
Creating and Deploying a Function
From the dashboard
- Open your project and select Compute in the sidebar.
- Click Node or Python to start from a template, or Webhook for a payment webhook receiver. The Webhook template pre-fills the name
payment-webhookand turns Verify JWT / API key off. - Enter a Name and choose the Runtime.
- Set Verify JWT / API key. Leave it on for calls from your own app. Turn it off only for callers that cannot send a WoWSQL credential, such as payment gateway webhooks.
- Write your handler in the editor and click Deploy. The function is live at the URL shown above the editor as soon as the deploy succeeds.
- Click Test invoke to call it. The dashboard sends the request with your project's anon key and shows the status code, headers and body.
Deploying again with the same name replaces the function's code and settings. Delete removes it immediately.
Function names
- 1 to 64 characters: lowercase letters, numbers and hyphens.
- Must start and end with a letter or number. Names are converted to lowercase.
- Up to 50 functions per project.
From the CLI
wowsql-cli 1.7.0 has no commands for creating, deploying or invoking functions. Use the dashboard to deploy. You can manage the secrets your functions read with wowsql secrets (see Environment Variables and Secrets).
From an AI assistant (MCP)
The WoWSQL MCP server provides two Compute tools in the database tool group. If your MCP client does not list them, reconnect it to refresh the tool list.
| Tool | What it does |
|---|---|
list_compute_functions | Lists the project's functions (name, runtime, Verify JWT setting), this month's usage, CORS_ORIGINS, the log retention setting and the invoke base URL. Read-only. |
invoke_compute_function | Invokes a function by name with an optional JSON body and HTTP method (default POST) and returns the status code and body. Counts against the project's compute hours. Not registered when the MCP URL has read_only=true. |
Deploying, editing and deleting functions is not available through MCP. See MCP Reference.
Handler contract
Your handler receives one argument, event, describing the HTTP request:
| Field | Type | Description |
|---|---|---|
method | string | HTTP method, for example POST. |
path | string | Full path, for example /functions/v1/hello/orders/42. |
rawPath | string | The part after the function name, for example /orders/42, or /. |
headers | object | Request headers with lowercase names. |
query | string | Raw query string without the leading ?, for example page=2&limit=10. Parse it yourself. |
body | object or string | Parsed JSON when the request Content-Type contains json and the body is valid JSON; otherwise the body as a string. |
rawBody | string | The unparsed request body. Use this for webhook signature checks. |
slug | string | Your project slug. |
functionName | string | The function's name. |
Return a response object. body may be a string or any JSON-serialisable value, which is sent as JSON:
{
"statusCode": 200,
"headers": { "content-type": "application/json" },
"body": { "ok": true }
}
Shortcuts: returning a plain string sends 200 with text/plain. Returning any other object or value without a statusCode sends 200 with that value as JSON. If the handler throws, the response is 500 with {"error": "..."}.
Node.js example
module.exports = async function (event) {
const input = typeof event.body === 'object' && event.body !== null ? event.body : {}
const name = input.name || 'world'
return {
statusCode: 200,
headers: { 'content-type': 'application/json' },
body: { message: `Hello ${name}!` }
}
}
Python example
def handler(event):
body = event.get("body")
name = body.get("name", "world") if isinstance(body, dict) else "world"
return {
"statusCode": 200,
"headers": {"content-type": "application/json"},
"body": {"message": f"Hello {name}!"},
}
In Python, name the entry point handler(event) or main(event).
Invoking a Function
URL format
https://{project-slug}.wowsqlconnect.com/functions/v1/{function-name}
https://{project-slug}.wowsqlconnect.com/functions/v1/{function-name}/{any/sub/path}
The alias /api/functions/{function-name} is rewritten to /functions/v1/{function-name}. Supported methods are GET, POST, PUT, PATCH, DELETE and HEAD. Browser preflight OPTIONS requests are answered by the Compute runtime (204 with CORS headers, or 403 CORS_ORIGIN_DENIED) and never reach your handler. Every response includes an x-wowsql-exec-ms header with the execution time in milliseconds.
Authentication
| Caller | Send | Notes |
|---|---|---|
| Your web or mobile app | apikey: wowsql_anon_... | The anon key is safe to ship in client code. Combine it with your own checks inside the function. |
| A signed-in end user | Authorization: Bearer USER_ACCESS_TOKEN | An access token issued by your project's Authentication. The token must be signed by your project and, if it carries a project reference, it must match this project. |
| Your backend or a cron job | apikey: wowsql_service_... | Server-side only. Never ship the service key to a browser or app. |
| Payment gateways and other webhooks | Nothing | Only when Verify JWT / API key is off. Verify the sender's signature inside the function. |
When Verify JWT / API key is on and no valid credential is sent, the call fails with 401 JWT or apikey required. Any credential you do send is validated by the gateway even when verification is off, so a wrong key always fails.
Examples
curl -X POST "https://your-project-slug.wowsqlconnect.com/functions/v1/hello" \
-H "apikey: wowsql_anon_your_key_here" \
-H "Content-Type: application/json" \
-d '{"name": "Saravana"}'
const res = await fetch('https://your-project-slug.wowsqlconnect.com/functions/v1/hello', {
method: 'POST',
headers: {
apikey: 'wowsql_anon_your_key_here',
'Content-Type': 'application/json'
},
body: JSON.stringify({ name: 'Saravana' })
})
const data = await res.json()
Restricting browser origins (CORS_ORIGINS)
By default any website can call your functions from a browser. To allow only your own front ends, enter their origins in the CORS_ORIGINS box at the top of the Compute page and click Save CORS.
- One origin per line (commas and spaces also separate entries), in the form
https://hostorhttp://localhost:3000: scheme, host and optional port, no path. A trailing slash is removed and duplicates are dropped. - An empty list (the default) or the single entry
*allows any origin. Saving an empty box clears the list. - When the list is set, a request that carries an
Originheader not on the list is rejected with403and{"code": "CORS_ORIGIN_DENIED"}before your handler runs. Matching is case-insensitive. - Requests without an
Originheader (server-to-server calls, payment webhooks,curl, and the dashboard's Test invoke) are not affected. - The list applies to every function in the project and syncs to the runtime without a redeploy.
https://app.example.com
https://admin.example.com
http://localhost:3000
CORS_ORIGINS is an origin allowlist, not authentication. Keep Verify JWT / API key on, or check a signature or token inside the function, for anything that must not be public.
Management API
The dashboard manages functions through these endpoints on https://api.wowsql.com. They require a WoWSQL account session, not a project API key. Changing functions, CORS, log retention or secrets needs write access to the project.
| Method and path | Purpose |
|---|---|
GET /api/v1/projects/{slug}/compute-functions | List functions, this month's usage, plan limits, the 40 most recent invocations and the invoke base URL. The response also includes cors_origins, log_retention (mode, count, days) and secret_keys (names only, never values). |
PUT /api/v1/projects/{slug}/compute-functions/{name} | Create or replace a function. Body: name, runtime (node or python), source, verify_jwt (default true), optional timeout_ms (1000 to 60000). |
DELETE /api/v1/projects/{slug}/compute-functions/{name} | Delete a function. |
POST /api/v1/projects/{slug}/compute-functions/{name}/invoke | Test invoke. Body: method, path, headers, body. Calls the public URL with the project's anon key. |
PUT /api/v1/projects/{slug}/compute-cors | Set CORS_ORIGINS. Body: {"cors_origins": [...]} (a list, or one string separated by newlines, commas or spaces; empty clears). Returns the saved list. |
PUT /api/v1/projects/{slug}/compute-log-retention | Set log retention. Body: log_retention_mode (count or time), log_retention_count (10 to 10000), log_retention_days (1 to 90). |
POST /api/v1/projects/{slug}/compute-secrets | Create or replace a function secret. Body: key, value. Returns the key only. |
DELETE /api/v1/projects/{slug}/compute-secrets/{key} | Delete a function secret. |
Environment Variables and Secrets
Every function receives these environment variables:
| Variable | Value |
|---|---|
WOWSQL_URL | Your project URL, https://{project-slug}.wowsqlconnect.com. |
DATABASE_URL | A Postgres connection string for the project database, when available. See Accessing the Database. |
WOWSQL_JWT_SECRET | The project's JWT signing secret, for verifying user access tokens yourself. |
NODE_ENV | production (Node.js). |
Every project secret is also injected as an environment variable with the same name. Add secrets in either place:
- Dashboard: on the Compute page, enter the name in KEY and the value in value below the editor, then click Save. Saved secrets are listed by name only; click × next to a name to delete it.
- CLI:
wowsql secrets set KEY "value"(see CLI Secrets).
Secret names set from the Compute page must start with a letter or underscore and contain only letters, numbers and underscores (up to 255 characters). If the same name is set in both places, the value saved on the Compute page is the one your function sees.
Secret values are write-only. After you save a secret, its value cannot be read back from the dashboard, the API (GET /api/v1/projects/{slug}/secrets/{key} returns 403 "Secret values cannot be read after save."), the CLI or the Table Editor. To change a value, save it again. Keep your own copy of anything you may need later.
wowsql secrets set RAZORPAY_KEY_SECRET "your-razorpay-secret"
wowsql secrets set WOWSQL_SERVICE_KEY "wowsql_service_your_key_here"
Read them in code with process.env.KEY (Node.js) or os.environ["KEY"] (Python). Changes sync to the runtime automatically; you do not need to redeploy. All functions in a project see all of the project's secrets. You cannot override PATH, LD_PRELOAD or LD_LIBRARY_PATH.
Your project's service key is not injected automatically. If a function needs elevated database access, store the service key as a secret yourself and keep that function behind Verify JWT / API key or your own authorisation check.
Accessing the Database from a Function
Because packages cannot be installed, there is no Postgres driver available inside the runtime. The recommended way to read and write data is the project REST API at WOWSQL_URL, called with the built-in HTTP client and a key stored as a secret.
module.exports = async function (event) {
const res = await fetch(`${process.env.WOWSQL_URL}/rest/v1/orders?status=eq.paid&limit=10`, {
headers: { apikey: process.env.WOWSQL_SERVICE_KEY }
})
if (!res.ok) {
return { statusCode: res.status, body: { error: await res.text() } }
}
return { statusCode: 200, body: await res.json() }
}
import json
import os
import urllib.request
def handler(event):
req = urllib.request.Request(
os.environ["WOWSQL_URL"] + "/rest/v1/orders?status=eq.paid&limit=10",
headers={"apikey": os.environ["WOWSQL_SERVICE_KEY"]},
)
with urllib.request.urlopen(req, timeout=5) as resp:
rows = json.loads(resp.read())
return {"statusCode": 200, "body": rows}
The Data API is off by default for new projects. If REST calls from your function return 403 DATA_API_DISABLED, enable the Data API for the project and expose the tables you need. Row Level Security still applies to the key you use: the anon key and user tokens only see what your policies allow; the service key bypasses them.
Logs and Monitoring
The Compute page shows a usage bar (compute hours used this month against your plan) with your plan name, default timeout and memory, and a Recent invokes table. Each row records the time of the call, the function name, HTTP status code, execution time in milliseconds and any error message. The dashboard lists the latest 40 invocations.
Log retention
Invocation logs are stored in your project database (functions.logs). Choose how many to keep with the retention control at the top of the Compute page, then click Save logs:
| Mode | Range | Default |
|---|---|---|
| Keep last (count) | 10 to 10,000 most recent invocations | 200 |
| Keep days (time) | 1 to 90 days | 7 days (used only when this mode is selected) |
New projects keep the last 200 invocations. Older entries are deleted automatically.
Error messages come from the runtime: uncaught exceptions, timeouts, and the first part of the process's standard error output when the function produced no valid response.
The runtime reads your function's response from standard output. Do not write to standard output with console.log (Node.js) or print() (Python): it corrupts the response and the call fails with 500 Function did not return JSON. Write diagnostics to standard error instead, with console.error or print(..., file=sys.stderr).
Where Function Data Is Stored
Function code, invocation logs, Compute settings and function secrets live in your project's own database, in the functions schema:
| Table | Contents |
|---|---|
functions.handlers | One row per function: name, runtime, source, Verify JWT setting and timeout. |
functions.logs | Invocation log: function name, status code, execution time, error and time. |
functions.settings | One row: CORS_ORIGINS and the log retention setting. |
functions.secrets | Function secrets, encrypted. Hidden from the Table Editor. |
The functions schema appears in the Table Editor's schema picker. Manage functions from the Compute page or the Management API rather than by editing these tables. Functions, logs, settings and secrets created before this storage change were moved into the schema automatically. Compute usage (execution hours) is still metered by the platform.
Limits
| Limit | Free | Pro | Scale |
|---|---|---|---|
| Execution hours per month | 5 | 100 | 100 |
| Default timeout per invocation | 10 seconds | 60 seconds | 60 seconds |
| Memory (Node.js heap) | 128 MB | 512 MB | 512 MB |
| Concurrent invocations per project | 2 | 20 | 20 |
| Limit | Value (all plans) |
|---|---|
| Functions per project | 50 |
| Source size per function | 256 KB |
| Per-function timeout setting | 1 to 60 seconds |
| Response size | About 1 MB. Larger responses are cut off and fail. |
| Runtimes | Node.js, Python |
Requests above the concurrency limit wait for a free slot rather than failing. A call that runs past its timeout is stopped and returns 504.
Pricing and Plan Availability
Compute Functions are available on every plan. Usage is measured in execution hours: the wall-clock time your functions are running, summed across all invocations in the project. Idle time costs nothing. A function that runs for 200 ms uses 200 ms of the budget.
| Plan | Price | Included execution hours |
|---|---|---|
| Free | $0 per month | 5 hours per month |
| Pro | $25 per month | 100 hours per month |
| Scale | $99 per month | 100 hours per month |
The budget resets at the start of each calendar month (UTC). There is no overage charge for compute: when a project has used its hours, further calls return 402 until the next month or until you upgrade.
{
"code": "COMPUTE_HOURS_EXCEEDED",
"message": "This project used its compute hours for the month.",
"hours_monthly": 5,
"hint": "Upgrade your plan or wait until next month."
}
Functions keep working when a Free project is in the read-only lock, so webhooks are not dropped.
Best Practices
- Keep Verify JWT / API key on unless the caller genuinely cannot send a credential. For public endpoints, add your own checks (signature, token or rate limiting) inside the function.
- Always verify webhook signatures against
event.rawBody, reject requests with a missing signature, and use a constant-time comparison. - Keep secrets in project secrets, never in source code. Rotate them with
wowsql secrets set; no redeploy is needed. - Never return secrets or the service key in a response, and never send the service key to client code.
- Set timeouts on outbound calls shorter than your function timeout, and return a clear error when a dependency is slow.
- Make handlers idempotent. Webhook providers retry; use the event ID to ignore duplicates.
- Return quickly. You pay for wall-clock time, including time spent waiting on other services.
- Log to standard error only (
console.error,print(..., file=sys.stderr)). - Do not rely on local state. Each request runs in a new process and a new temporary directory.
Webhook receiver example (Node.js)
Turn Verify JWT / API key off for this function and store the gateway's webhook secret as RAZORPAY_WEBHOOK_SECRET.
const crypto = require('crypto')
module.exports = async function (event) {
const secret = process.env.RAZORPAY_WEBHOOK_SECRET
const signature = event.headers['x-razorpay-signature'] || ''
if (!secret || !signature) {
return { statusCode: 400, body: { error: 'missing signature' } }
}
const expected = crypto.createHmac('sha256', secret).update(event.rawBody || '').digest('hex')
const a = Buffer.from(expected)
const b = Buffer.from(signature)
if (a.length !== b.length || !crypto.timingSafeEqual(a, b)) {
return { statusCode: 400, body: { error: 'invalid signature' } }
}
const payload = JSON.parse(event.rawBody)
// Record payload.event and payload.payload in your database here.
return { statusCode: 200, body: { received: true } }
}
Troubleshooting
| Status | Message | Cause and fix |
|---|---|---|
400 | Function name must be lowercase letters, numbers and hyphens (1–64 chars). | Rename the function. See Function names. |
400 | At most 50 functions per project. | Delete unused functions or combine routes in one function using rawPath. |
400 | Function source is over 256 KB. | Reduce the source size. Move large data to Storage or the database. |
401 | JWT or apikey required | Send apikey or Authorization: Bearer ..., or turn off Verify JWT / API key for webhooks. |
401 | Invalid API key | The key is wrong, revoked or belongs to another project. Copy it again from API Keys. |
402 | COMPUTE_HOURS_EXCEEDED | The project used its monthly execution hours. Upgrade, or wait for the monthly reset. |
404 | Function 'name' not found | Check the name in the URL. It is case-insensitive and must match a deployed function. |
500 | Function did not return JSON | Something wrote to standard output. Replace console.log or print() with standard error logging. |
500 | Export default, handler, or module.exports as a function | Node.js: export the handler with module.exports = async function (event) { ... }. Top-level export default is not supported. |
500 | Define handler(event) or main(event) | Python: define a top-level handler or main function. |
500 | Cannot find module '...' or ModuleNotFoundError | Third-party packages are not available. Use built-in modules and the REST API. |
500 | Function produced no output | The process crashed before returning, for example out of memory. Check the error in Recent invokes. |
503 | Control plane unavailable or Could not reach the function runtime | Temporary platform issue. Retry with backoff and check the status page. |
504 | Function timed out | The handler ran past its timeout. Speed it up, add timeouts to outbound calls, or move long work elsewhere. |
403 | DATA_API_DISABLED (from a REST call inside your function) | Enable the Data API for the project. See Accessing the Database. |
403 | CORS_ORIGIN_DENIED | The browser origin is not in CORS_ORIGINS. Add it on the Compute page, or clear the list. See Restricting browser origins. |
400 | Invalid CORS origin: ... Use https://host or http://localhost:3000. | Enter origins without a path, for example https://app.example.com. |
400 | Keep between 10 and 10000 logs. or Keep logs between 1 and 90 days. | Choose a log retention value inside the allowed range. |
400 | Secret key must be letters, numbers, and underscores. | Rename the secret, for example RAZORPAY_WEBHOOK_SECRET. |
403 | Secret values cannot be read after save. | Expected: secret values are write-only. Save the secret again to change it. |
A secret change not showing up usually means the function was invoked within a few seconds of saving. Invoke again. If a function works from Test invoke but not from your app, compare the headers: Test invoke adds the anon key automatically.