Run a function routine
Custom function routine ids use the formatfunction:t_.... To start a run, call POST /routines/{routine_id}/run.
Replace function:t_abc123 and the input names with your function’s routine id and inputs. Give each item an id you can use to match its result later.
Read the results
Use the returnedroutine_run_id to request the run’s results:
data array yet:
status: "complete". Use a delay between polls and a timeout appropriate for your application. For HTTP errors, follow the error handling and rate limit guidance rather than continuing to poll unchanged.
Read individual results from data. Each item’s id matches an id you supplied in the run request. Check each item’s status: a completed run can contain failed items. For example, a function with a company_name output could return:
result depend on your function’s outputs. Use item ids to associate results with inputs rather than relying on response order. finished counts finished items, including failures; it is not a count of successful results.
Retrieve every page
A completed run’s results can span multiple pages. If the response includescursor, pass that value to the same endpoint to retrieve the next page:
data from each page and continue with each returned cursor until cursor is omitted. Treat cursors as opaque values. total and finished describe the whole run, not the current page. See pagination for the general cursor pattern.
This polling flow applies to runs started with /routines/{routine_id}/run. Runs started through the batch API use the separate batch results endpoint.
Webhook notifications
Therun and run-batch/start requests accept an optional webhook_id. Clay notifies that webhook when the run finishes, so your system can react without polling.
Run clay webhooks --help for webhook creation, testing, delivery payloads, and signature verification.
Batch run a function routine
For large input sets, create an upload URL, upload JSONL input, then start a batch run.Batch runs
Learn how batch runs fit into Routines.
When to use Workflows
Workflows are also routines, but they are in Alpha and are built differently. Use Workflows when you want to build, edit, validate, run, inspect, or batch-run Clay logic from the plugin or CLI instead of building the logic in the Clay UI.Workflows (Alpha)
Compare Workflows with functions.

