Skip to main content

Workflow Automations

User-authored multi-step generation graphs - a workflow chains several generation nodes together (a text prompt feeding an image generator, an image feeding a video generator, etc.), executed step by step with each node's output available to the nodes downstream of it.

Create a workflow​

Endpoint: POST /generation/workflows/

import httpx

API_KEY = "YOUR_FUNAI_API_KEY"
URL = "https://api.funai.art/generation/workflows/"

payload = {
"name": "Portrait to short clip",
"description": "Turns a text prompt into a portrait, then animates it",
"steps": {
"nodes": [
{"id": "n1", "type": "input_variable", "data": {"variableName": "topic", "varType": "string", "required": True}},
{"id": "n2", "type": "generation", "data": {"capabilityType": "text_to_image", "modelId": "...", "fieldValues": {"prompt": "{{input.topic}}"}}},
{"id": "n3", "type": "generation", "data": {"capabilityType": "image_to_video", "modelId": "...", "fieldValues": {"input_image": "{{prev.output_url}}"}}},
],
"edges": [
{"source": "n1", "target": "n2"},
{"source": "n2", "target": "n3"},
],
},
"is_public": False,
}

headers = {"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"}
response = httpx.post(URL, json=payload, headers=headers)
print(response.json())

The workflow is always owned by the authenticated caller - there is no way to create a workflow on behalf of another user.

Any input_variable node in the graph is automatically rolled up into the workflow's input_schema, returned on GET /generation/workflows/{id} - this is the contract an external caller uses to know what to pass to execute.

Run a workflow​

Endpoint: POST /generation/workflows/{workflow_id}/execute

response = httpx.post(
f"https://api.funai.art/generation/workflows/{workflow_id}/execute",
json={"input_data": {"topic": "a neon-lit alley at night"}},
headers=headers,
)
run = response.json()
print(run["run_id"])

You can run any workflow you own, or any workflow with is_public: true. input_data is validated against the workflow's input_schema before the run is dispatched - a missing required variable or a wrong type returns 422 with a message listing the problems.

Referencing a variable inside a node's fields uses {{input.<variable_name>}}. A node can also reference its parent's output with {{prev.<key>}}, or a specific upstream node's output with {{steps.<node_id>.<key>}} (needed for join nodes with more than one parent). All three resolve output_url or any key under a node's recorded output_metadata.

Poll a run​

Endpoint: GET /generation/workflows/runs/{run_id}

run = httpx.get(f"https://api.funai.art/generation/workflows/runs/{run_id}", headers=headers).json()
print(run["status"]) # PENDING | RUNNING | COMPLETED | FAILED
print(run["step_results"]) # keyed by node id

A run is only ever visible to the user it was run as, even if the workflow itself is public.

Edges must match media kinds: a text/string output can only feed a text/string input (prompt, etc.). An image output cannot land on a prompt field, and vice versa. Mismatched graphs return 400 on estimate and execute.

Every workflow gets a short share_slug. Open GET /generation/workflows/share/{slug} (or the app route /w/{slug}) to resolve it. Visibility is unchanged: the caller must own the workflow, or it must be public (is_public: true).

Other endpoints​

MethodPathDescription
GET/generation/workflows/mineList your own workflows
GET/generation/workflows/publicBrowse public workflows
GET/generation/workflows/share/{slug}Resolve a short share link
GET/generation/workflows/{id}Fetch a single workflow
PUT/generation/workflows/{id}Update a workflow you own
DELETE/generation/workflows/{id}Delete a workflow you own