JavaScript: Functions
Call edge functions from your app, deploy and version them, run them asynchronously, read logs, and manage their access, settings and bindings with @sovaria/sdk.
Functions run your server code next to your data. Apps call them with functions.call; the management methods (deploy, versions, logs, settings) are for your team and CI.
import { createClient } from '@sovaria/sdk'
const sovaria = createClient('https://<project-ref>.sovarias.in', '<anon-key>')
const total = await sovaria.functions.call<{ total: number }>('order-total', { cartId })
console.log(total.total)#Calling
sovaria.functions.call
Call a function the way an app does: POST {projectUrl}/functions/v1/{name} with the signed-in user's token (or no token for functions marked public).
sovaria.functions.call(
functionName: string,
payload?: JsonValue = {},
options?: { apiVersion?: string },
): Promise<T>Returns the function's result.
Parameters
functionNamestringrequired- The function's name.
payloadJsonValueoptionaldefault{}- JSON body your function receives.
options{ apiVersion?: string }optional
Returns
Promise<T> — Whatever the function returns (typed with the generic).
- Runs as the signed-in user (or anonymously) — the function's access setting decides who may call it.
{
"sent": true,
"to": "ada@example.com"
}sovaria.functions.invoke
In results: 'supabase' mode, supabase-js's invoke(name, { body, headers, method }) → { data, error }: the app route /functions/v1/{name} with the signed-in user's token (or the anon key), the function's own policy and the plan's limits; error is a FunctionsHttpError (the function answered 4xx/5xx; error.context is the Response), FunctionsRelayError (the platform refused) or FunctionsFetchError (no answer).
sovaria.functions.invoke(
functionName: string,
payload?: unknown,
options?: { projectId?: string; deployId?: string; executionProfile?: 'standard' | 'heavy' },
): Promise<JsonObject> | Promise<ParityResult<unknown>>Otherwise, for a project team member, the operator call (POST /api/v1/fn/{name}/invoke) for tests and tools; for an app user or a visitor, the app route like call() (the operator route refuses them).
Parameters
functionNamestringrequiredpayloadunknownoptionaloptions{ projectId?: string; deployId?: string; executionProfile?: 'standard' | 'heavy' }optional
Returns
Promise<JsonObject> | Promise<ParityResult<unknown>>
- In
results: 'supabase'mode this is supabase-js's call:invoke(name, { body, headers, method })→{ data, error }over the app route (/functions/v1/{name}, the user's token, the function's policy and plan limits).error.nameisFunctionsHttpError(the function answered 4xx/5xx;error.contextis the Response),FunctionsRelayError(the platform refused) orFunctionsFetchError(no answer). - Otherwise it runs a function as a team member (
POST /api/v1/fn/{name}/invoke) for tests and tools; apps usecall().
sovaria.functions.invokeAsync
Invoke async.
sovaria.functions.invokeAsync(
functionName: string,
payload: JsonValue,
options?: { projectId?: string deployId?: string executionProfile?: 'standard' | 'heavy' simulation?: boolean },
): Promise<JsonObject>Parameters
functionNamestringrequiredpayloadJsonValuerequiredoptions{ projectId?: string deployId?: string executionProfile?: 'standard' | 'heavy' simulation?: boolean }optional
Returns
Promise<JsonObject> — { invocation_id } — poll invocationStatus for the result.
{
"accepted": true,
"invocation_id": "0b7c2e91d4a64f0f9a3e5c1d2b8f7a60",
"status": "QUEUED",
"project_id": "f0c3e9a2-1b4d-4e7f-8a6c-2d9b5e3f1a07",
"function_name": "nightly-report",
"deploy_id": "dep_3a…",
"version": 4,
"mode": "invoke",
"profile": "standard",
"created_at": 1792263000.512
}sovaria.functions.invocationStatus
Invocation status.
sovaria.functions.invocationStatus(
invocationId: string,
projectId?: string,
): Promise<JsonObject>Parameters
invocationIdstringrequiredprojectIdstringoptional
Returns
Promise<JsonObject>
{
"invocation_id": "0b7c2e91d4a64f0f9a3e5c1d2b8f7a60",
"status": "SUCCEEDED",
"project_id": "f0c3e9a2-1b4d-4e7f-8a6c-2d9b5e3f1a07",
"function_name": "nightly-report",
"deploy_id": "dep_3a…",
"version": 4,
"mode": "invoke",
"profile": "standard",
"created_at": 1792263000.512,
"updated_at": 1792263009.612,
"started_at": 1792263000.9120002,
"completed_at": 1792263009.612,
"result": {
"rows": 1043
},
"error": "",
"attempts": 1,
"max_attempts": 3,
"available_at": null,
"lease_until": null,
"queue_status": "done"
}sovaria.functions.simulate
Simulate.
sovaria.functions.simulate(
functionName: string,
payload: JsonValue,
options?: { projectId?: string; deployId?: string; executionProfile?: 'standard' | 'heavy' },
): Promise<JsonObject>Parameters
functionNamestringrequiredpayloadJsonValuerequiredoptions{ projectId?: string; deployId?: string; executionProfile?: 'standard' | 'heavy' }optional
Returns
Promise<JsonObject>
{
"ok": true,
"invocation_id": "0b7c2e91d4a64f0f9a3e5c1d2b8f7a60",
"deploy_id": "dep_7a…",
"function_name": "send-receipt",
"project_id": "f0c3e9a2-1b4d-4e7f-8a6c-2d9b5e3f1a07",
"version": 7,
"mode": "simulate",
"profile": "standard",
"simulation": true,
"duration_ms": 201,
"result": {
"sent": true,
"to": "ada@example.com"
},
"stdout": "",
"stderr": "",
"memory_mb": 256,
"gb_seconds": 0.0503,
"estimated_cost_usd": 8.4e-7
}#Deploying and versions
sovaria.functions.plan
Validate a bundle and get a signed plan bound to its exact bytes.
sovaria.functions.plan(
bundle: Blob,
name: string,
projectId?: string,
): Promise<JsonObject>Parameters
bundleBlobrequirednamestringrequiredprojectIdstringoptional
Returns
Promise<JsonObject>
sovaria.functions.deploy
Plans, then applies exactly the planned bundle (Sovaria refuses anything else).
sovaria.functions.deploy(
bundle: Blob,
name: string,
projectId?: string,
): Promise<JsonObject>Parameters
bundleBlobrequired- A zip
Blobwith your code (the CLI builds it for you:sov fn deploy). namestringrequired- Function name.
projectIdstringoptional- Defaults to the client's project.
Returns
Promise<JsonObject>
- Plans first and applies exactly the planned bundle, so what you reviewed is what runs.
sovaria.functions.status
Status.
sovaria.functions.status(
deployId: string,
projectId?: string,
): Promise<JsonObject>Parameters
deployIdstringrequiredprojectIdstringoptional
Returns
Promise<JsonObject>
{
"deploy_id": "dep_7a…",
"project_id": "f0c3e9a2-1b4d-4e7f-8a6c-2d9b5e3f1a07",
"function_name": "send-receipt",
"version": 7,
"status": "READY",
"invoke_url": "https://<project-ref>.sovarias.in/functions/v1/send-receipt",
"change_note": "retry on 5xx",
"created_by": "6e19c0a2-…",
"error": null,
"created_at": 1792263000.512,
"updated_at": 1792263000.512,
"is_active": true,
"promoted_at": 1792263000.512,
"promoted_by": "6e19c0a2-…"
}sovaria.functions.versions
Versions.
sovaria.functions.versions(
functionName: string,
options: { projectId?: string; limit?: number; offset?: number },
): Promise<JsonObject>Parameters
functionNamestringrequiredoptions{ projectId?: string; limit?: number; offset?: number }required
Returns
Promise<JsonObject>
{
"project_id": "f0c3e9a2-1b4d-4e7f-8a6c-2d9b5e3f1a07",
"function_name": "send-receipt",
"versions": [
{
"version": 7,
"deploy_id": "dep_7a…",
"status": "READY",
"change_note": "retry on 5xx",
"created_by": "6e19c0a2-…",
"created_at": 1792263000.512,
"updated_at": 1792263000.512,
"bundle_sha256": "e3b0c442…",
"is_active": true,
"promoted_at": 1792263000.512,
"promoted_by": "6e19c0a2-…"
}
]
}sovaria.functions.promote
Promote.
sovaria.functions.promote(
functionName: string,
options: { projectId?: string version?: number deployId?: string reason?: string },
): Promise<JsonObject>Parameters
functionNamestringrequiredoptions{ projectId?: string version?: number deployId?: string reason?: string }requiredprojectId, theversion(ordeployId) to make live, optionalreason.
Returns
Promise<JsonObject>
sovaria.functions.rollback
Rollback.
sovaria.functions.rollback(
functionName: string,
options: { projectId?: string version?: number reason?: string },
): Promise<JsonObject>Parameters
functionNamestringrequiredoptions{ projectId?: string version?: number reason?: string }requiredprojectId, optionalversionto go back to,reason.
Returns
Promise<JsonObject>
{
"project_id": "f0c3e9a2-1b4d-4e7f-8a6c-2d9b5e3f1a07",
"function_name": "send-receipt",
"from_version": 7,
"from_deploy_id": "dep_7a…",
"to_version": 6,
"to_deploy_id": "dep_6c…",
"updated_at": 1792263000.512,
"reason": "receipt template broke",
"rollback": true
}sovaria.functions.history
History.
sovaria.functions.history(
functionName: string,
options: { projectId?: string mode?: 'invoke' | 'simulate' limit?: number offset?: number },
): Promise<JsonObject>Parameters
functionNamestringrequiredoptions{ projectId?: string mode?: 'invoke' | 'simulate' limit?: number offset?: number }required
Returns
Promise<JsonObject>
{
"project_id": "f0c3e9a2-1b4d-4e7f-8a6c-2d9b5e3f1a07",
"function_name": "send-receipt",
"entries": [
{
"invocation_id": "0b7c2e91d4a64f0f9a3e5c1d2b8f7a60",
"deploy_id": "dep_7a…",
"version": 7,
"mode": "invoke",
"profile": "standard",
"status": "SUCCESS",
"started_at": 1792263000.512,
"completed_at": 1792263000.6920002,
"duration_ms": 182.4,
"event_preview": "{\"orderId\":1042}",
"result_preview": "{\"sent\":true}",
"error": "",
"memory_mb": 256,
"gb_seconds": 0.0456,
"estimated_cost_usd": 7.6e-7
}
]
}sovaria.functions.simulationDiff
Simulation diff.
sovaria.functions.simulationDiff(
functionName: string,
options: { projectId?: string leftInvocationId: string rightInvocationId: string },
): Promise<JsonObject>Parameters
functionNamestringrequiredoptions{ projectId?: string leftInvocationId: string rightInvocationId: string }required
Returns
Promise<JsonObject>
{
"project_id": "f0c3e9a2-1b4d-4e7f-8a6c-2d9b5e3f1a07",
"function_name": "send-receipt",
"left_invocation_id": "0b7c…",
"right_invocation_id": "9d1e…",
"left_version": 6,
"right_version": 7,
"diff": "--- v6\n+++ v7\n- \"sent\": false\n+ \"sent\": true",
"changed": true
}#Settings and logs
sovaria.functions.list
List.
sovaria.functions.list(
options?: { projectId?: string; limit?: number; offset?: number } = {},
): Promise<JsonObject>Parameters
options{ projectId?: string; limit?: number; offset?: number }optionaldefault{}
Returns
Promise<JsonObject>
{
"project_id": "f0c3e9a2-1b4d-4e7f-8a6c-2d9b5e3f1a07",
"functions": [
{
"project_id": "f0c3e9a2-1b4d-4e7f-8a6c-2d9b5e3f1a07",
"function_name": "send-receipt",
"function_key": "send-receipt",
"active_version": 7,
"active_deploy_id": "dep_7a…",
"latest_version": 7,
"latest_status": "READY",
"last_deployed_at": 1792263000.512,
"last_invoked_at": 1792266600.512,
"deploy_count": 7,
"queued_jobs": 0,
"origin": "cli",
"runtime": "node18",
"description": "Email a receipt after payment",
"env_id": "",
"inherited": false
}
]
}sovaria.functions.get
Get.
sovaria.functions.get(name: string): Promise<JsonObject>Parameters
namestringrequired
Returns
Promise<JsonObject>
{
"id": "fn_5d1a0c3e",
"name": "send-receipt",
"runtime": "node18",
"entrypoint": "handler",
"region": "us-east-1",
"description": "Email a receipt after payment",
"verify_jwt": true,
"public": false,
"version": 7,
"source_hash": "3f9c1e…",
"status": "active",
"created_at": "2026-10-02T09:14:07Z",
"updated_at": "2026-10-17T11:20:45Z"
}sovaria.functions.getSource
Get source.
sovaria.functions.getSource(name: string): Promise<JsonObject>Parameters
namestringrequired
Returns
Promise<JsonObject>
{
"name": "send-receipt",
"source": "export async function handler(event, context) {\n …\n}",
"runtime": "node18"
}sovaria.functions.update
Update.
sovaria.functions.update(
name: string,
body: JsonObject,
): Promise<JsonObject>Parameters
namestringrequiredbodyJsonObjectrequired- Settings to change — public access, allowed outbound hosts, limits.
Returns
Promise<JsonObject>
{
"id": "fn_5d1a0c3e",
"name": "send-receipt",
"runtime": "node18",
"entrypoint": "handler",
"region": "us-east-1",
"description": "Email a receipt (with PDF)",
"verify_jwt": true,
"public": false,
"version": 7,
"source_hash": "3f9c1e…",
"status": "active",
"created_at": "2026-10-02T09:14:07Z",
"updated_at": "2026-10-17T11:20:45Z"
}sovaria.functions.delete
Delete.
sovaria.functions.delete(name: string): Promise<JsonObject>Parameters
namestringrequired
Returns
Promise<JsonObject>
{
"status": "deleted",
"name": "send-receipt"
}sovaria.functions.logs
Logs.
sovaria.functions.logs(
name: string,
query?: { limit?: number; offset?: number; status?: string },
): Promise<JsonValue>Parameters
namestringrequiredquery{ limit?: number; offset?: number; status?: string }optionallimit,offset,status(e.g.error).
Returns
Promise<JsonValue>
[
{
"invocation_id": "inv_8c1e…",
"timestamp": "2026-10-18T09:12:04.120Z",
"project_id": "f0c3e9a2-1b4d-4e7f-8a6c-2d9b5e3f1a07",
"function": "send-receipt",
"status": "succeeded",
"duration_ms": 182,
"error": null,
"stderr_preview": "",
"stdout_preview": "receipt sent to ana@example.com"
}
]sovaria.functions.jobs
Jobs.
sovaria.functions.jobs(
functionName: string,
options: { projectId?: string; status?: string; limit?: number; offset?: number },
): Promise<JsonObject>Parameters
functionNamestringrequiredoptions{ projectId?: string; status?: string; limit?: number; offset?: number }required
Returns
Promise<JsonObject>
{
"project_id": "f0c3e9a2-1b4d-4e7f-8a6c-2d9b5e3f1a07",
"function_name": "nightly-report",
"jobs": [
{
"invocation_id": "0b7c2e91d4a64f0f9a3e5c1d2b8f7a60",
"project_id": "f0c3e9a2-1b4d-4e7f-8a6c-2d9b5e3f1a07",
"function_name": "nightly-report",
"deploy_id": "dep_3a…",
"version": 4,
"mode": "invoke",
"profile": "standard",
"status": "SUCCEEDED",
"created_at": 1792263000.512,
"updated_at": 1792263009.612,
"attempts": 1,
"max_attempts": 3,
"available_at": null,
"lease_until": null,
"started_at": 1792263000.9120002,
"completed_at": 1792263009.612,
"result": {
"rows": 1043
},
"error": ""
}
]
}sovaria.functions.getPolicy
Get policy.
sovaria.functions.getPolicy(name: string): Promise<JsonObject>Parameters
namestringrequired
Returns
Promise<JsonObject>
{
"invoke_permission": "authenticated",
"rate_limit_per_minute": 60,
"max_payload_bytes": 1048576,
"allowed_origins": "*",
"timeout": 30,
"saved": true
}sovaria.functions.setPolicy
Set policy.
sovaria.functions.setPolicy(
name: string,
body: JsonObject,
): Promise<JsonObject>Parameters
namestringrequiredbodyJsonObjectrequired
Returns
Promise<JsonObject>
{
"invoke_permission": "authenticated",
"rate_limit_per_minute": 120,
"max_payload_bytes": 65536,
"allowed_origins": "https://app.example.com",
"timeout": 20
}sovaria.functions.getBindings
Get bindings.
sovaria.functions.getBindings(name: string): Promise<JsonObject>Parameters
namestringrequired
Returns
Promise<JsonObject>
[
{
"name": "STRIPE_KEY",
"type": "secret",
"value": "••••••••"
},
{
"name": "ORDERS_DB",
"type": "database",
"value": "postgresql://…"
},
{
"name": "WEBHOOK_URL",
"type": "url",
"value": "https://hooks.example.com/orders"
}
]sovaria.functions.setBindings
Set bindings.
sovaria.functions.setBindings(
name: string,
body: JsonObject,
): Promise<JsonObject>Parameters
namestringrequiredbodyJsonObjectrequired
Returns
Promise<JsonObject>
[
{
"name": "STRIPE_KEY",
"type": "secret",
"value": "••••••••"
}
]#GitHub
sovaria.functions.githubRepositories
Github repositories.
sovaria.functions.githubRepositories(
body: JsonObject,
): Promise<JsonObject>Parameters
bodyJsonObjectrequired
Returns
Promise<JsonObject>
{
"repositories": [
{
"full_name": "skolist/shop",
"default_branch": "main",
"private": true
}
],
"count": 1,
"auth_source": "connected"
}sovaria.functions.githubImport
Github import.
sovaria.functions.githubImport(body: JsonObject): Promise<JsonObject>Parameters
bodyJsonObjectrequired
Returns
Promise<JsonObject>
{
"status": "imported",
"function": {
"name": "send-receipt",
"version": 8,
"deploy_id": "dep_8b…",
"files": [
"index.mjs",
"lib/email.mjs"
]
},
"github": {
"repository": "skolist/shop",
"path": "functions/send-receipt",
"ref": "main",
"auth_source": "connected"
}
}sovaria.functions.githubCommit
Github commit.
sovaria.functions.githubCommit(body: JsonObject): Promise<JsonObject>Parameters
bodyJsonObjectrequired
Returns
Promise<JsonObject>
{
"status": "committed",
"function": "send-receipt",
"repository": "skolist/shop",
"path": "functions/send-receipt/index.mjs",
"ref": "main",
"sha": "9f2c…",
"commit_sha": "a1b2c3d…",
"commit_url": "https://github.com/skolist/shop/commit/a1b2c3d",
"auth_source": "connected"
}#Live streams
sovaria.streams.functionLogs
Function logs.
sovaria.streams.functionLogs(
options?: { function?: string; backfill?: number; maxSeconds?: number; signal?: AbortSignal } = {},
): AsyncGenerator<AgentEvent, any, any>Parameters
options{ function?: string; backfill?: number; maxSeconds?: number; signal?: AbortSignal }optionaldefault{}function(one function's lines; all when left out),backfill(recent lines to send first),maxSeconds(close after this long),signalto stop.
Returns
AsyncGenerator<AgentEvent, any, any> — An async iterator of log lines as JSON objects, as they are written.
for await (const line of sovaria.streams.functionLogs({ function: 'send-invoice' })) console.log(line). Stop iterating or abort the signal to close the stream.
sovaria.streams.flowExecution
Flow execution.
sovaria.streams.flowExecution(
executionId: string,
options?: { signal?: AbortSignal } = {},
): AsyncGenerator<AgentEvent, any, any>Parameters
executionIdstringrequired- The run's id (from
flows.runor the run list). options{ signal?: AbortSignal }optionaldefault{}signalto stop.
Returns
AsyncGenerator<AgentEvent, any, any> — An async iterator of the run's step events until it finishes.
sovaria.streams.conversation
Conversation.
sovaria.streams.conversation(
conversationId: string,
options?: { after?: number; signal?: AbortSignal } = {},
): AsyncGenerator<AgentEvent, any, any>Parameters
conversationIdstringrequired- The Sovariq conversation.
options{ after?: number; signal?: AbortSignal }optionaldefault{}after(the last event number you have, to resume),signalto stop.
Returns
AsyncGenerator<AgentEvent, any, any> — An async iterator of the conversation's events (text, tool steps, approvals) while it runs.
#More
sovaria.functions.setAuth
supabase-js: use this token (instead of the session's) for invoke() calls.
sovaria.functions.setAuth(token: string | null): voidnull goes back to the session.
Parameters
tokenstring | nullrequired- A token to send instead of the session's on
invoke()(supabase mode);nullgoes back to the session.
Returns
void
sovaria.functions.fetch
Call an HTTP function like fetch: any method, a sub-path, headers, a raw body (string, bytes, FormData…), and the function's own Response back (status, headers, binary body).
sovaria.functions.fetch(
functionName: string,
path?: string = '',
init?: { method?: string; headers?: Record<string, string>; body?: BodyInit | null; query?: Record<string, string> } = {},
): Promise<Response>Sends the signed-in user's token when there is one (none for public functions). const res = await sovaria.functions.fetch('api', 'users/42', { method: 'PUT', body: JSON.stringify(user) }) if (res.status === 201) console.log(await res.json())
Parameters
functionNamestringrequiredpathstringoptionaldefault''init{ method?: string; headers?: Record<string, string>; body?: BodyInit | null; query?: Record<string, string> }optionaldefault{}
Returns
Promise<Response>
sovaria.functions.setHttp
Make a function an HTTP function (Request in, Response out) or a JSON one again.
sovaria.functions.setHttp(
functionName: string,
http: boolean,
): Promise<JsonObject>Parameters
functionNamestringrequiredhttpbooleanrequired
Returns
Promise<JsonObject>
sovaria.functions.request
Request.
sovaria.functions.request(
method: string,
path: string,
options?: RequestOptions = {},
): Promise<JsonValue>Parameters
methodstringrequiredpathstringrequiredoptionsRequestOptionsoptionaldefault{}
Returns
Promise<JsonValue>
sovaria.functions.apiVersions.list
List.
sovaria.functions.apiVersions.list(): Promise<JsonObject>Returns
Promise<JsonObject>
sovaria.functions.apiVersions.get
Get.
sovaria.functions.apiVersions.get(name: string): Promise<JsonObject>Parameters
namestringrequired
Returns
Promise<JsonObject>
sovaria.functions.apiVersions.create
Pin every function's current code (or only functions; pins picks a version number per function).
sovaria.functions.apiVersions.create(
body: { name: string; note?: string; functions?: string[]; pins?: Record<string, number> },
): Promise<JsonObject>Parameters
body{ name: string; note?: string; functions?: string[]; pins?: Record<string, number> }required
Returns
Promise<JsonObject>
sovaria.functions.apiVersions.update
Update.
sovaria.functions.apiVersions.update(
name: string,
body: { note?: string status?: 'active' | 'deprecated' | 'retired' sunset_at?: number | string clear_sunset?: boolean pins?: Record<string, number> remove?: string[] },
): Promise<JsonObject>Parameters
namestringrequiredbody{ note?: string status?: 'active' | 'deprecated' | 'retired' sunset_at?: number | string clear_sunset?: boolean pins?: Record<string, number> remove?: string[] }required
Returns
Promise<JsonObject>
sovaria.functions.apiVersions.deprecate
Deprecate: calls still work and answers carry Deprecation / Sunset headers until sunsetAt.
sovaria.functions.apiVersions.deprecate(
name: string,
sunsetAt?: Date | string | number,
): Promise<JsonObject>Parameters
namestringrequiredsunsetAtDate | string | numberoptional
Returns
Promise<JsonObject>
sovaria.functions.apiVersions.retire
Retire: calls that ask for it get 410 API_VERSION_RETIRED.
sovaria.functions.apiVersions.retire(name: string): Promise<JsonObject>Parameters
namestringrequired
Returns
Promise<JsonObject>
sovaria.functions.apiVersions.delete
Only a retired version can be deleted.
sovaria.functions.apiVersions.delete(name: string): Promise<JsonObject>Parameters
namestringrequired
Returns
Promise<JsonObject>