Deploying and running functions
Deploy from the console, the CLI or GitHub; dependencies; versions and rollback; environments; calling by name or id, synchronously, asynchronously or streaming; headers, errors and retries; and reading your data safely.
#Ways to deploy
| From | How | Good for |
|---|---|---|
| Console | Functions › your function › edit › Save & deploy | Small functions, quick fixes |
| CLI | sov fn deploy ./folder --name hello --note "…" | Code in your repository, CI |
| GitHub | Import a function from a connected repository; commit console edits back | Teams that review code in GitHub |
A function name is lowercase letters, digits, - and _ (at most 128), and it is the name you call. Any other name is refused with 422 INVALID_FUNCTION_NAME, and the error gives the name to use. Nothing is renamed for you. The console turns what you type into a valid name as you type, and sov fn deploy without --name makes one from the folder name and prints it.
The entry file is main.py (Python), index.mjs / index.js (Node.js), index.ts (TypeScript on Bun) or main.go (Go, compiled at deploy); --entrypoint and --handler change it. Every deploy is a new version; a deploy that fails never replaces the version serving traffic.
sov fn deploy ./functions/send-receipt --name send-receipt --note "retry on 5xx"
sov fn versions send-receipt
sov fn rollback send-receipt # back to the previous version#Dependencies
The standard library (Python) and built-ins such as fetch (Node.js) are always there. To ship packages, vendor them with your code and deploy with --include-deps (bundles node_modules or vendored Python packages) — available on paid plans.
| Free | Pro | Ultra | Team | Enterprise | |
|---|---|---|---|---|---|
| Bundling your own function dependencies | — | ✓ | ✓ | ✓ | ✓ |
#Environments
Deploying through an environment's URL (staging, a version) creates that environment's own copy; production keeps serving its version. When the change is ready, promote it to production — Environments, staging and deploying to production. Secrets and environment variables stay per environment, so staging never uses production keys.
#Call it
| Way | Use for |
|---|---|
POST /functions/v1/<name> (sovaria.functions.call) | Answers within a request: the response is what the function returns. |
Any method on /functions/v1/<name>/<path> (sovaria.functions.fetch) | HTTP functions: webhooks with signatures, OAuth callbacks, GET APIs, files — HTTP functions. |
Asynchronously (sovaria.functions.invokeAsync, sov fn invoke --async) | Long work. You get an invocation id at once; read its status and result later (sovaria.functions.invocationStatus(id), GET /api/v1/fn/invocations/<id>). |
| Streaming | Send output as it is produced (AI responses) — Local development, logs and streaming. |
| Triggers and schedules | Run on database, auth, storage or realtime events, or on a cron schedule — Event triggers. |
Successful responses carry X-Sovaria-Invocation-Id (find the run in the logs), X-Sovaria-Duration-Ms and X-Sovaria-Compute-GB-Seconds.
By name or by id
Every function also has a stable id (a UUID), shown as function_id in the functions list and in GET /api/v1/fn/functions/<name>. Functions created from source get it when they are created; functions deployed as a bundle (sov fn deploy, a zip) get one made from the project and the name, so it never changes between deploys. Wherever a route takes the name, the id works too: /functions/v1/<id>, the management routes under /api/v1/fn/functions/<id>/… and the invoke routes. Use the id when the name might change, or when you store a reference to the function in your own data.
await sovaria.functions.call('send-receipt', { orderId }) // by name
await sovaria.functions.call('3f6c1d2e-8a4b-4c7d-9e21-5b0a7c9d4e10', { orderId }) // the same function, by idA name always wins: if a function is really named like a UUID, that name is called. Another project's function id never resolves in yours.
supabase-js's invoke
With createClient(url, key, { results: 'supabase' }), functions.invoke(name, { body, headers, method }) is supabase-js's call: it goes to /functions/v1/{name} like call() (the user's token, the function's access policy, your plan's body size and invocation limits) and resolves to { data, error }. data is parsed JSON, text, or a Blob for binary answers. The other SDKs already take the same options. Without that option, functions.invoke(name, payload) returns the result and throws on errors; the supabase form invoke(name, { body }) works there too (JS SDK 0.10.6+): an object made only of body, headers and method sends body as the request body.
const { data, error } = await sovaria.functions.invoke('resize', { body: { id }, headers: { 'x-trace': traceId }, method: 'POST' })
if (error) {
if (error.name === 'FunctionsHttpError') console.log('function said', error.context.status, await error.context.json())
else if (error.name === 'FunctionsRelayError') console.log('Sovaria refused the call', error.statusCode) // policy, plan limit, quota
else console.log('no answer', error.message) // FunctionsFetchError
}
sovaria.functions.setAuth(serviceToken) // send another token on invoke() (null goes back to the session)A call ends when your handler returns. Each call runs in its own short-lived sandbox: once the answer is sent, the sandbox stops at once, threads and timers included (like a Lambda freeze). Finish any work — sending an email, writing a row — before you return, or hand it to a queue (Queues).
#Errors
| You get | Because |
|---|---|
401 | The function requires sign-in and the caller isn't signed in. |
403 | Only the service key may call it, or the browser origin isn't allowed. |
404 | No function with that name in this environment. |
409 | It was saved but never deployed. |
413 | The request body is over the function's limit. |
429 | The function's rate limit, or the organization's concurrent-run limit, was reached — retry after Retry-After. |
422 FUNCTION_TIMEOUT | Your code ran past its time limit and was stopped (raise timeout_sec in the function's limits, or make it faster). The run is logged as TIMEOUT. |
| Your own status (403, 404, 409…) | A default (JSON) function always answers 200 with what it returns, so a returned { statusCode: 409 } is just data. To answer with a status, make it an HTTP function (sov fn deploy --http) and return Response.json(body, status=409) (Python: from sovaria_functions import Response) or a Response in JavaScript. |
422 FUNCTION_FAILED | Your code raised an error, ran out of memory or disk, or returned a result over the size limit. The answer names the error (The function failed: ValueError: …); the run is logged as FAILED with the full traceback. In the JS SDK (0.10.6+) the error is code: 'SERVER_ERROR' with a message safe to show users; serverCode is FUNCTION_FAILED and technicalMessage has your error line. |
503 RUNNER_BUSY | Every sandbox was busy for a moment, or the runner had no room left for the call's memory limit (calls wait up to 1.5 s for room first; one project can use at most half of a runner's sandboxes at once). Retry after Retry-After — the SDKs do. |
HTTP calls are not retried for you. Event triggers retry failed runs and keep the ones that keep failing in a dead-letter queue, so write handlers that can safely run twice (check whether the work was already done before doing it).
#Start-up and concurrency
- Functions run in isolated sandboxes that are reused between calls when possible; the first call after a deploy or a quiet period can take longer.
- Create clients and read configuration at module level, not inside the handler, so warm calls skip it.
- How many runs may execute at once is set by your plan; beyond it a call waits briefly, then gets
429 PLAN_LIMIT_REACHED(fn.concurrency) withRetry-After: 2.
| Free | Pro | Ultra | Team | Enterprise | |
|---|---|---|---|---|---|
| Concurrent function invocations | 5 | 50 | 200 | 500 | 2,000 |
| Monthly function invocations | 100,000 | 1,000,000 | 3,000,000 | 20,000,000 | 100,000,000 |
| Monthly function compute (GB-seconds) | 5,000 | 50,000 | 200,000 | 1,000,000 | 5,000,000 |
#Read and write your data from a function
Nothing to set up: every call of a function gets its project's API address and a key of its own, and can always reach its project's API host. createClient() (JavaScript) or create_client() / create_sync_client() (Python) with no arguments read them. The key acts like the service role, so it skips row-level security and the default rules: decide in your code what the caller may do — use context.caller — before acting for them.
import { createClient } from 'npm:@sovaria/sdk'
const sovaria = createClient() // no secrets: SOVARIA_URL and SOVARIA_FUNCTION_KEY are set for each call
export async function handler(event, context) {
const userId = context.caller.user_id
if (!userId) return { error: 'sign in first' }
// Queries resolve to the rows and throw a SovariaError on failure (createClient's default 'rows' mode).
const orders = await sovaria.from('orders').select('id, total').eq('customer_id', userId)
const reply = await sovaria.agents.run('support-bot', { input: 'Summarise these orders: ' + JSON.stringify(orders) })
return { orders, summary: reply.text }
}| Set for every call | What it is |
|---|---|
SOVARIA_URL | The project's API address (https://<ref>.sovarias.in, or the environment's own address in a staging or preview environment). A secret of the same name that you set wins. |
SOVARIA_PROJECT_ID, SOVARIA_ORG_ID, SOVARIA_ENV_ID | The project, its organization and the environment the call runs in (no SOVARIA_ENV_ID in production). |
SOVARIA_FUNCTION_KEY | A key for this call only. It expires a few minutes after the call ends (the call's time limit plus 5 minutes, at most an hour), never reaches your logs, and can't be set as a secret. |
What the function's key can do: the same as the service-role key on your data, storage, users (the admin API), messaging and push, queues, other functions, and your project's agents (those set to *Your server code only* or *Your app's users*; an agent for *Project members* refuses it). It works only in its own project and environment: a request naming another environment is refused (403 FUNCTION_KEY_OTHER_ENVIRONMENT). It never manages the project: only the routes above are open to it, so API keys, project secrets, billing, organization and project settings, domains, auth settings (providers, hooks, signing keys, SSO), connections, deploys, function settings and secrets, flows changes and Sovariq's own chats answer 403 FUNCTION_KEY_NOT_ALLOWED — use a team member's session or the service-role key for those. In a simulated (dry) run the key reads but never writes. An expired key answers 401 FUNCTION_KEY_EXPIRED; create the client inside the handler (in Python a client made at module level also picks up each call's new key by itself).
- Your project's own API host is always reachable; other hosts still need the function's allowed hosts (Function › Network).
- A
SOVARIA_SERVICE_ROLE_KEYsecret, when you set one, is used instead of the function's key (the service role has no environment pin and reaches management APIs). - To act as the signed-in user instead (their row rules apply, and agents for project members work for team members), pass their session:
createClient({ url: process.env.SOVARIA_URL, accessToken: userToken }). - Pass values as
params, never inside the SQL string. - Staff can turn the automatic key off for the whole platform (Control Center › Platform › Limits ›
fn.project_credential); functions then need theSOVARIA_URLandSOVARIA_SERVICE_ROLE_KEYsecrets and the project's host in their allowed hosts again.
#Coming from Firebase or Supabase?
| Platform | What this is called there |
|---|---|
| Firebase | firebase deploy --only functions |
| Supabase | supabase functions deploy |
| Sovaria | Deploying and running functions |
Moving an existing app? Migrate from Supabase or Firebase imports users (with their passwords), data, files and rules.