---
question: Which HTTP routes reach a module's workflow?
kind: task
via_web: na
via_cli: na
via_python: available
via_api: available
via_config: na
ref_python: expose_app
ref_api: POST /api/workflows/{module_id}/{name}/runs
prereq: You need a workflow in a module that runs, and the project's API running (`abi dev up`).
next:
  - /capabilities/build/workflows/run-a-workflow
  - /capabilities/build/workflows/monitor-and-cancel-a-run
  - /capabilities/build/apps/create-an-app
---

# Expose as an API

Two HTTP surfaces reach a module's workflow:

| Route | Reaches | Auth | Runs |
|---|---|---|---|
| `/api/workflows` on Nexus | Every durable workflow of every module: `@workflow` methods and published classes (`workflow.<slug>`, `pipeline.<slug>`) | The instance's `ABI_API_KEY`, or a platform super admin's session | A durable run, recorded and audited |
| The backend of one of the module's apps | The routes you write, which call the workflow | The Nexus user who opened the app | What your route does: `run` in process, or a durable start |

You do not register a workflow on `/api/workflows`: Nexus lists what the modules declare, as soon as they run. The kernel API does not mount a module's workflow classes.

## Web UI

Not applicable. Nexus has no screen that publishes a workflow: the routes come from the code. Nexus starts durable workflows from System › Jobs: see [Run a workflow](/capabilities/build/workflows/run-a-workflow?via=web).

## CLI

Not applicable. No command publishes a route. `abi new app` scaffolds an app folder: see [Create an app](/capabilities/build/apps/create-an-app?via=cli).

## Python

### Put the workflow behind an app's backend

A module serves its apps through Nexus, without a port of its own. Each `apps/<name>/manifest.json` next to the module's package is an app, and the ASGI application bound to it answers the requests its files do not. A route of that backend can call a workflow of the module:

```python title="src/reports/__init__.py"
from fastapi import FastAPI

from reports.workflows.CustomersWorkflow import CustomersWorkflowParameters

api = FastAPI()


class ABIModule(BaseModule):
    module_id = "acme.reports"
    dependencies = ModuleDependencies(services=("document", "triple_store"))

    async def on_initialized(self) -> None:
        module = self

        @api.get("/api/customers/{entity_id}")
        async def summarize(entity_id: str) -> dict:
            workflow = module.get_workflow_instance("customers_workflow")
            return await workflow.run(CustomersWorkflowParameters(entity_id=entity_id))

        self.expose_app("console", api)  # apps/console/manifest.json
```

The route looks the instance up when a request comes in: the module builds its classes after `on_initialized`. To record each call as a run instead, start the durable workflow there: `await module.get_workflow("workflow.customers_workflow").run({...})`.

### Know who calls

Nexus checks the user's access to the app, then forwards the request over NATS. The app's page calls `fetch("api/customers/42")`, relative to its folder. `request.scope["abi"]` holds the signed-in `user_id`, the `workspace_id` the app was opened from, and the `caller`. Only Nexus (caller `api`) may send a `user_id` or a `workspace_id`. Any other caller, another module or a script with its own service token, reaches the app too, but never on behalf of a user: a request from one that names a user or a workspace is refused (`PERMISSION_DENIED`) before the app sees it. Tell the callers apart by `request.scope["abi"]["caller"]`. A script that only needs to start the workflow uses `/api/workflows`, in the REST API steps.

## REST API

### Start it through Nexus

Any durable workflow starts with `POST /api/workflows/{module_id}/{name}/runs`, where `name` is the `@workflow` name or `workflow.<slug>`:

```bash
curl -s -X POST "http://localhost:9879/api/workflows/acme.reports/workflow.customers_workflow/runs?wait=30" \
  -H "Authorization: Bearer $ABI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"entity_id": "42"}'
```

The body is the class's parameters model, or the `@workflow`'s input. With `abi dev up`, use the `api` port that `abi dev ports` prints.

### Know the routes

| Route | Does |
|---|---|
| `GET /api/workflows` | Lists the workflows, with their input and output schemas, limits and triggers. |
| `POST /api/workflows/{module_id}/{name}/runs` | Starts a run: `?wait=0..120`, `Idempotency-Key`, 422 with the schema faults. |
| `GET /api/workflows/{module_id}/runs/{run_id}` | Reads a run, with its steps and result. |
| `POST /api/workflows/{module_id}/runs/{run_id}/cancel` | Cancels a running run. |

The key stands for the operator: starts and cancels are written to the audit log with `via: api_key`. A user who is not a platform super admin gets 403. These routes are not in the generated API reference. The steps are on [Run a workflow](/capabilities/build/workflows/run-a-workflow?via=api) and [Monitor and cancel a run](/capabilities/build/workflows/monitor-and-cancel-a-run?via=api).

## Config

Not applicable. `config.yaml` has no per-workflow route setting: Nexus lists every workflow the modules declare.
