Calling a workflow from your app

Call a workflow from your app's server like a function, POST /api/workflows/v1/<name>/run, and get back what its Output step returns.

An app's server can call one of the workspace's workflows like a function: "sort this support ticket", "pull the order out of this photo", "write the follow-up". It sends the input and gets back the output. The workflow's steps (AI, data, sends) are edited in Workflows, so the logic changes with no redeploy of the app, and every run is in the workflow's run history with its cost.

App events start workflows too, but don't answer: an event says "this happened" and any workflow listening reacts. A call names one workflow and waits for its answer. See App events.

Making a workflow callable

A workflow is callable once it has an app call trigger (in its editor, Starts when, + Add, Your app calls it). The trigger says what the workflow takes and returns, one field per line:

ticket: string
priority?: integer   1 is the most urgent
  • Types: string, number, integer, boolean, object, array, any.
  • A ? after the name makes it optional; text after the type describes it.
  • A workflow has at most one app call trigger. Adding it again replaces its input and output.

In a pulled workflow file it's {"type": "api", "description": "...", "input": {"ticket": "string"}, "output": {"queue": "string"}}, where a field is a type, or {"type", "required", "description"}.

Steps read the input as {{trigger.payload.<field>}}, as on an event run. The answer is whatever reaches the workflow's Output step.

Calling it

From the app's server, with the token Oalo gives a server app (OALO_SYNC_TOKEN, see The app's environment) or a Sync API token with Can call workflows (oalo tokens create --name <what it is> --scope workflows):

curl -X POST "$OALO_URL/api/workflows/v1/triage/run" \
  -H "Authorization: Bearer $OALO_SYNC_TOKEN" -H "Content-Type: application/json" \
  -d '{"input": {"ticket": "My order never came"}, "contact": {"external_ref": "user_42", "email": "ana@example.com"}}'
  • input: checked against the trigger's fields before anything runs. A missing required field, a wrong type or a field the workflow doesn't take answers 422 with a list of the problems.
  • contact (optional): the person it's about, matched or made as for app events (external_ref, email, phone, name), so the workflow's sends reach them.
  • wait (optional): seconds to wait for the answer, 0 to 55, default 30.

The answer:

{"run_id": 812, "workflow": "triage", "status": "success", "output": {"queue": "shipping"},
 "error": null, "cost_usd": 0.0031, "test": false, "poll": "/api/workflows/v1/runs/812"}
  • 200 when the run finished. Check status: success, or error, halted_iterations, halted_cost or cancelled with error saying why. waiting means the workflow parked on a Wait step; output is what it had then, and the rest runs later as its own run.
  • 202 with status: running when it didn't finish within wait. Read it again with GET /api/workflows/v1/runs/<run_id>.

GET /api/workflows/v1 lists the callable workflows with their input and output.

Typed calls

oalo typegen writes the callable workflows into oalo.generated.ts with the models: an input and output type per workflow and a runWorkflow function.

import { runWorkflow, getWorkflowRun } from "./oalo.generated";

const run = await runWorkflow("triage", { ticket: text }, { contact: { external_ref: user.id } });
if (run.status === "success") route(run.output?.queue);

It uses OALO_URL and OALO_SYNC_TOKEN from the environment, so it runs on the app's server only. oalo typegen --check fails when a workflow's input or output changes.

Preview calls are tests

A preview's token is locked to dev, so its calls are test runs, as Try it in the editor: they read dev data, steps that send a message or change a record are simulated and show what they would have done, and the run is marked as a test in Run history. AI steps run, and cost what they normally do. A preview's calls run even when the workflow is off; the live app's calls need it on (409 workflow_off otherwise). The answer's test says which it was. An unlocked token runs for real unless the body says "env": "dev".

Limits

  • Calls come from a server: a request with an Origin header (a browser) is refused, since the token must stay secret.
  • 120 calls a minute per token, and 20 calls running at once per workspace (429 busy past that; retry shortly).
  • Each run keeps the workflow's own caps on steps and cost, and its AI use is billed like any other workflow's.
  • An Idempotency-Key header makes a retry after a lost answer safe once the first call has answered. A retry sent while the first call is still waiting starts a second run.

Common mistakes

  • Calling from the browser. Call your own server, and have it call the workflow.
  • Reading output without checking status. A failed or still running run has no useful output.
  • A Wait step in a callable workflow. The call answers waiting with what it had before the wait. Keep callable workflows short; start long ones with an event.
Related
Try it on your own Base

Sign up, install the CLI, and deploy your repo in a few minutes.

bring your repo