Skip to Content
ML.aiDocs

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}/run

Starts 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

PartValue
Authorization headerBearer mlai_sk_..., an API key of the routine's owner. Required.
Idempotency-Key headerOptional. Letters, numbers, . : _ -, up to 100 characters. A retried call with the same key returns the first run instead of starting another.
BodyOptional 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 statusstatus fieldMeaning
202startedThe run started. The body has run and job ids.
200duplicateSame 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.
402blockedThe run could not start. The reason field says why.
404-No API routine with this id on the key owner's account.
409disabledThe routine is switched off.
429limitedThe routine already reached its hourly or daily run limit.

On this page