Workflows
The Workflows API allows you to run workflows (multi-step AI pipelines) built in the Hatz platform. Workflows execute asynchronously -- you submit a run request and then poll for the job status to get results.
Run a Workflow
Submit a workflow for execution. The workflow runs asynchronously in the background. Use the returned job_id to poll for status and results.
Endpoint
POST /v1/workflows/run
Request Body
app_id(required): The UUID of the workflow to runinputs(required): Key-value object of user inputs, where keys are thevariable_namedefined on the workflow's input fields (same format as the App Builder query endpoint)is_draft_app(optional): Whether to run the draft version of the workflow (default:false)
File Inputs
If a workflow has an input of type file_upload, you can pass a file UUID (obtained from the File Upload endpoint) as the value for that input. The workflow step will then have access to the file contents.
When uploading a file for use in a workflow, we recommend including scope_type and scope_id in the upload request so the file is properly registered:
curl 'https://ai.hatz.ai/v1/files/upload' \
-H 'X-API-Key: $HATZ_API_KEY' \
--form 'file=@"report.csv"' \
--form 'scope_type="workflow"' \
--form 'scope_id="5ae6e9dd-0296-4409-8fe4-1fc646bb22f7"'
Then pass the returned file_uuid in the workflow's inputs.
Example Request
curl -X POST 'https://ai.hatz.ai/v1/workflows/run' \
-H 'X-API-Key: $HATZ_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"app_id": "5ae6e9dd-0296-4409-8fe4-1fc646bb22f7",
"inputs": {
"topic": "machine learning",
"audience": "beginners"
}
}'
Example with a file input:
curl -X POST 'https://ai.hatz.ai/v1/workflows/run' \
-H 'X-API-Key: $HATZ_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"app_id": "5ae6e9dd-0296-4409-8fe4-1fc646bb22f7",
"inputs": {
"report_file": "8fb5bc1d-5a8d-4015-86a6-b0ca394e7793",
"summary_style": "executive"
}
}'
Response
{
"status": "Workflow Job Invoked",
"job_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
}
The workflow is now running in the background. Use the job_id to check its progress.
Get Workflow Job Status
Poll this endpoint to check the status of a running workflow and retrieve its step outputs once complete.
Endpoint
GET /v1/workflows/{job_id}
Path Parameters
job_id(required): The job ID returned from the run endpoint
Example Request
curl 'https://ai.hatz.ai/v1/workflows/a1b2c3d4-e5f6-7890-abcd-ef1234567890' \
-H 'X-API-Key: $HATZ_API_KEY'
Response
{
"job_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"app_id": "5ae6e9dd-0296-4409-8fe4-1fc646bb22f7",
"tenant_id": "tenant_9x2AbC123",
"user_id": "user-uuid",
"created_at": "2025-01-15T10:00:00Z",
"updated_at": "2025-01-15T10:00:30Z",
"start_time": 1736935200000,
"end_time": 1736935230000,
"number_of_steps": 3,
"status": "complete",
"user_inputs": {
"topic": "machine learning",
"audience": "beginners"
},
"app_data": { },
"step_outputs": [
{
"step_id": "step-1-uuid",
"job_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"step_type": "prompt",
"status": "complete",
"output_type": "dump",
"created_at": "2025-01-15T10:00:05Z",
"updated_at": "2025-01-15T10:00:15Z",
"start_time": 1736935205000,
"end_time": 1736935215000,
"duration": 10000,
"output_data": "Step 1 output text...",
"payload": {}
},
{
"step_id": "step-2-uuid",
"job_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"step_type": "prompt",
"status": "complete",
"output_type": "dump",
"created_at": "2025-01-15T10:00:15Z",
"updated_at": "2025-01-15T10:00:30Z",
"start_time": 1736935215000,
"end_time": 1736935230000,
"duration": 15000,
"output_data": "Step 2 output text...",
"payload": {}
}
]
}
Job Status Values
| Status | Description |
|---|---|
pending |
Job has been created but hasn't started processing |
running |
Job is currently being processed |
complete |
All steps finished successfully |
failed |
One or more steps encountered an error |
Polling Recommendation
Since workflows run asynchronously, poll the status endpoint to check for completion. A reasonable approach is to start polling after a short delay (e.g., 2 seconds) and then check every few seconds until the status is complete or failed.
Get Presigned URL for Workflow Output
If a workflow step produces a document (e.g., a generated file), you can get a temporary download URL for it.
Endpoint
POST /v1/workflows/presigned-url
Request Body
job_id(required): The workflow job run IDstep_id(required): The step ID whose output contains the fileexpires_in(optional): URL expiration in seconds (default:3600)
Example Request
curl -X POST 'https://ai.hatz.ai/v1/workflows/presigned-url' \
-H 'X-API-Key: $HATZ_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"job_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"step_id": "step-2-uuid",
"expires_in": 3600
}'
Response
{
"url": "https://s3.amazonaws.com/...",
"expires_in": 3600
}
Schedules
A schedule runs a workflow automatically at set times, with fixed inputs. Schedules belong to a workflow, so every schedule endpoint is under /v1/workflows/{app_id}/triggers.
Rules
- A workflow can have one schedule. A second create returns
400with"Maximum 1 triggers per workflow". - An organization can have up to 100 schedules (
400with"Maximum 100 triggers per organization"). - Schedules run at most once an hour. Use a single number in the cron minute field: more frequent schedules such as
*/15 * * * *or0,30 * * * *are rejected with400and"Minimum schedule interval is 1 hour. Please use a less frequent schedule." cron_expressionis a 5-field Unix cron expression (minute, hour, day of month, month, day of week), evaluated intimezone.- Restrict either the day of month or the day of week, not both. If both are set, the day of week is ignored:
0 9 1 * 1runs only on the 1st of each month, not also every Monday. Leave one of the two fields as*. timezoneis an IANA name such asAmerica/New_York. It defaults toUTC.frequency(hourly,daily,weekly,monthlyorcustom) is a label for display. The schedule followscron_expression.next_run_atis the next run time in UTC. It isnullwhile a schedule is paused.
Check the timezone and cron expression before you send them. These endpoints don't validate an unknown timezone (for example Mars/Olympus) or an impossible time (for example hour 25) up front. Such a request can fail with a 5xx error, or be saved with next_run_at: null as a schedule that never runs. After a create or update, check that next_run_at is set for an active schedule.
Who Can Manage Schedules
The API key's user needs permission to share the workflow. The workflow's owner always has it. Some users the owner lets edit the workflow (with Allow internal organization to edit) can have it too, including tenant admins and MSP users. Users who can only view the workflow never have it. Without it, every schedule endpoint returns 403 with "SHARE permission required". That includes:
- users who can only view the workflow, or can't see it, including tenant admins and MSP users;
- users in another organization;
- an unknown
app_id.
Schedules run as the user who created them.
The Schedule Object
| Field | Description |
|---|---|
id |
Schedule ID (UUID) |
app_id |
The workflow's UUID |
entity_id |
The organization's UUID |
user_id |
UUID of the user who created the schedule |
name |
Display name, 1–100 characters |
trigger_type |
Always schedule |
status |
active or paused |
schedule_config |
frequency, cron_expression and timezone |
default_inputs |
The inputs sent to the workflow on each run, in the same format as Run a Workflow |
next_run_at, last_run_at |
Next and most recent run times (UTC), or null |
run_count |
Number of runs started by this schedule |
consecutive_failures, last_failure_cause, last_failure_outcome |
Recent failures, if any |
execution_state |
eligible, or reauth_required when the schedule can't run until its authorization is restored |
execution_state_reason |
With reauth_required: authorization_failed, authorization_revoked or authorization_missing |
execution_state_changed_at, paused_reason, remediation_owner, remediation_path, recovery_action, circuit_opened_at, last_recovered_at |
Why the schedule stopped and how to recover. Hatz may pause a schedule that keeps failing. |
created_at, updated_at |
Timestamps |
List Schedules
GET /v1/workflows/{app_id}/triggers
Returns {"triggers": [...]} with the workflow's schedule, or an empty array.
curl 'https://ai.hatz.ai/v1/workflows/e4212000-0000-4000-8000-000000000001/triggers' \
-H "X-API-Key: $HATZ_API_KEY"
Create a Schedule
POST /v1/workflows/{app_id}/triggers
New schedules start active.
Request Body
name(required): 1–100 charactersschedule_config(required):cron_expression(required): 5-field cron expressionfrequency(required):hourly,daily,weekly,monthlyorcustomtimezone(optional): IANA timezone (default:UTC)
default_inputs(optional): workflow inputs for each run (default:{})
Example Request
curl -X POST 'https://ai.hatz.ai/v1/workflows/e4212000-0000-4000-8000-000000000001/triggers' \
-H "X-API-Key: $HATZ_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"name": "Morning sales report",
"schedule_config": {
"frequency": "daily",
"cron_expression": "0 9 * * *",
"timezone": "America/New_York"
},
"default_inputs": {"topic": "weekly sales"}
}'
Response
{
"id": "29acb56a-1d92-4ae3-843b-5e9f5c8d3ff9",
"app_id": "e4212000-0000-4000-8000-000000000001",
"entity_id": "dd000001-0001-4001-a001-000000000001",
"user_id": "dd200100-0000-4000-a000-000000000002",
"name": "Morning sales report",
"trigger_type": "schedule",
"status": "active",
"schedule_config": {
"timezone": "America/New_York",
"frequency": "daily",
"cron_expression": "0 9 * * *"
},
"default_inputs": {
"topic": "weekly sales"
},
"next_run_at": "2026-11-06T14:00:00+00:00",
"last_run_at": null,
"execution_state": "eligible",
"execution_state_reason": null,
"execution_state_changed_at": "2026-11-06T01:13:11.742185+00:00",
"run_count": 0,
"consecutive_failures": 0,
"last_failure_cause": null,
"last_failure_outcome": null,
"paused_reason": null,
"remediation_owner": null,
"remediation_path": null,
"recovery_action": null,
"circuit_opened_at": null,
"last_recovered_at": null,
"created_at": "2026-11-06T01:13:11.742185+00:00",
"updated_at": "2026-11-06T01:13:11.766875+00:00"
}
Get a Schedule
GET /v1/workflows/{app_id}/triggers/{trigger_id}
Returns the schedule object. An unknown trigger_id, or one that belongs to a different workflow, returns 404 with "Trigger not found".
Update a Schedule
PUT /v1/workflows/{app_id}/triggers/{trigger_id}
Send only the fields to change: name, schedule_config (the whole object), status (active or paused) or default_inputs. An empty body leaves the schedule unchanged. Returns the updated schedule object.
curl -X PUT 'https://ai.hatz.ai/v1/workflows/e4212000-0000-4000-8000-000000000001/triggers/29acb56a-1d92-4ae3-843b-5e9f5c8d3ff9' \
-H "X-API-Key: $HATZ_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"schedule_config": {
"frequency": "weekly",
"cron_expression": "30 14 * * 1",
"timezone": "UTC"
}
}'
Pause or Resume a Schedule
POST /v1/workflows/{app_id}/triggers/{trigger_id}/toggle
Switches an active schedule to paused, or a paused one to active. No request body. Returns the updated schedule object.
Delete a Schedule
DELETE /v1/workflows/{app_id}/triggers/{trigger_id}
{
"success": true,
"schedule_cleanup_deferred": false
}
schedule_cleanup_deferred: true means the schedule is deleted and will not run, but removing it from the scheduler is being retried in the background. Deleting the same schedule again returns 404.
Delete All Schedules for a Workflow
DELETE /v1/workflows/{app_id}/triggers
{
"deleted_count": 1,
"schedule_cleanup_failures": 0
}
Returns deleted_count: 0 when the workflow has no schedules.
Error Responses
Errors use the standard envelope. message explains the error.
404 Not Found
{
"error": {
"type": "HTTPException",
"message": "Job not found: Requested resource not found",
"details": {},
"path": "/v1/workflows/00000000-0000-4000-8000-000000000000"
}
}
429 Too Many Requests
Returned when your organization has exceeded its credit limit:
{
"error": {
"type": "HTTPException",
"message": "Workflows have been rate limited for your organization due to a credit overage.",
"details": {},
"path": "/v1/workflows/run"
}
}
Schedule Errors
| Status | When |
|---|---|
400 |
Second schedule on a workflow, organization limit reached, or a schedule more frequent than hourly |
401 |
Missing or invalid API key |
403 |
"SHARE permission required" (see Who Can Manage Schedules) |
404 |
"Trigger not found" |
409 |
error.details.code is schedule_moved: the schedule was moved to an automation, so it can't be created or turned back on here |
422 |
Invalid body or IDs: empty or too-long name, a cron expression without 5 fields, an unknown frequency or status, missing schedule_config, or a non-UUID app_id or trigger_id (type is RequestValidationError) |
A 5xx response means the schedule could not be saved with the scheduler. A failed create may not return a trigger_id, so call List Schedules to see whether the schedule exists before you retry. Retrying won't help when the timezone or cron is invalid (see Rules); fix the value first.