Publish a version
This guide uses a small procedure that acknowledges a new claim. Save it asclaim-acknowledgement.procedure.md:
claim-acknowledgement.procedure.md
source. Every publish needs an Idempotency-Key; retrying with the
same key returns the first result instead of publishing twice.
id in the source’s front matter is the procedure’s id. access: "organization" lets every
member of your organization run a new procedure; without it, only you can until you share it.
expectedLatestVersion: null makes the publish fail with 409 version_conflict if the procedure
already exists, so you never overwrite one by accident. On later publishes, send the version you
expect to be the latest.
diagnostics lists compiler warnings. If the source doesn’t compile, nothing is
published and the response is 422 invalid_procedure, with a details entry for each error
giving its line, column and message.
Check its inputs
Read the version to see the inputs a run takes, each with its JSON Schema, the schema of the result it returns, and any connections it needs:Start a run
Name the procedure and pass the inputs. Withoutversion, the run starts the live version. Use a
key you can derive from your own event, such as the claim number, so a retried request never
starts a second run.
run.id. A retry with the same key and body returns outcome: "already_started" and the
same run. Inputs that don’t match the version’s schemas are refused with
422 invalid_run_inputs, whose details name the input that doesn’t match, such as
Procedure input claim_number does not satisfy its schema.
Add "visibility": "private" to keep the run visible only to the key’s user. Private runs are
left out of everyone else’s run lists.
Read the result
Read the run until itsstatus is final: completed, failed, cancelled, terminated or
timed_out.
output holds the value the procedure returned under its output’s name (acknowledgement
here), in the shape the version’s output schema declares. A failed
run has failure with a code and message instead. tasks lists what the run asked people to
do, such as approvals, each with its id, title and status; while one is open the run stays
running. A task you can’t read shows only its id. Open webUrl to see the run’s
steps in Effective.
To find runs later, list them with GET /procedures/runs, filtered by procedureId, status or
creation time. Lists are paginated.
Answer a task
A procedure can ask people to decide something, such as approving a payout. The run waits, and itstasks list each task with its status. Your system can answer for the person who was assigned the task,
using that person’s API key. To find what is waiting on them, list their open tasks:
canSubmit is true when the task is open and assigned to you. Send an answer that matches
answerSchema, with an optional comment kept beside it:
outcome: "submitted" with the task, now completed, and the run continues with
the answer. A retry with the same key returns outcome: "already_submitted" and the first answer.
An answer that doesn’t match the schema is refused with 422 invalid_answer, with a details
entry for each mismatch. A task that was already answered, or closed because its run was
cancelled, is refused with 409 task_not_open. Only the task’s assignees can answer it.
Try a draft
Before you publish a change, run the edited source as a draft. Effective compiles it and runs it with your inputs and connections, but stores no version: the live version doesn’t change, and runs that don’t send source keep starting it. Send the source fields you would publish (source,
sourceName, and any fragments or documents) in place of procedureId:
draft: true and no version. Only you can see it unless you send
"visibility": "collaborative". Read it with GET /procedures/runs/{runId} as in
Read the result, and list your drafts with draft=true.
- Source that doesn’t compile is refused with
422 invalid_procedureand the samedetailsa publish gives, and no run starts. - The
Idempotency-Keycovers the source, so use a new key for each edit. Reusing one with changed source is refused with409 idempotency_conflict. - A draft can’t declare secrets. Publish a procedure that reads secrets to run it.
Publish a new version
Publish the changed source with a newIdempotency-Key and expectedLatestVersion set to the
current latest version. The response’s live.outcome says what happened to the live version:
promoted: the new version is live, and new runs start it.held_interface_mismatch: the new version’s inputs or output differ from the live version’s, so it was not made live. Systems that start runs keep working against the old inputs until you switch.
generation, then set the live version:
409 live_version_changed; read the procedure again and decide. Runs that name a version are
not affected by the live version.
Cancel a run
outcome: "cancelling", and the run reaches cancelled. Cancelling a run that
already finished returns outcome: "already_finished" and changes nothing, so a retry is safe.
The body is required; send {} without a reason.
Who can do what
The API follows the procedure’s sharing in Effective. A procedure you can’t see answers404.
Reading a version’s inputs needs permission to read the procedure’s source, and publishing or
setting the live version needs permission to publish it; without them the answer is 403.
Starting a run needs permission to run the procedure. A draft runs unpublished code, so it needs
permission to publish the procedure its source’s id names, or to create procedures when that id
is new; resource-scoped and app API keys can’t start drafts. Someone else’s private run answers
404.
Tasks follow their own sharing: you can read a task assigned to you, or any task if you can view
your organization’s tasks, and only its assignees can answer it.
Procedures, runs and tasks have no API usage charge. A run uses credits for the agent and model work its
steps do; see Usage and billing.