Start a routine
POST /api/routines/{id}/run starts an ML AI Code routine with an API trigger. Request body, Idempotency-Key header, example and status codes.
POST https://code.ml.ai/api/routines/{id}/runStarts a routine whose trigger is API. Make a routine with the API trigger on the Automations page, open it and copy its API URL.
Request
| Part | Value |
|---|---|
Authorization header | Bearer mlai_sk_..., an API key of the routine's owner. Required. |
Idempotency-Key header | Optional. Letters, numbers, . : _ -, up to 100 characters. A retried call with the same key returns the first run instead of starting another. |
| Body | Optional JSON {"input":"..."}, passed to the run as event data (up to 256 KB). |
Example
curl -X POST https://code.ml.ai/api/routines/ROUTINE_ID/run \
-H "Authorization: Bearer mlai_sk_..." \
-H "Idempotency-Key: deploy-2026-11-19" \
-H "Content-Type: application/json" \
-d '{"input":"Release 4.2 is tagged. Update the changelog."}'Responses
| HTTP status | status field | Meaning |
|---|---|---|
| 202 | started | The run started. The body has run and job ids. |
| 200 | duplicate | Same Idempotency-Key (or, without one, the same body) as an earlier call: you get the earlier run, nothing new starts. |
| 401 | - | No API key, or the key is wrong or revoked. |
| 402 | blocked | The run could not start. The reason field says why. |
| 404 | - | No API routine with this id on the key owner's account. |
| 409 | disabled | The routine is switched off. |
| 429 | limited | The routine already reached its hourly or daily run limit. |