API sequence reference
Build, run, inspect, and repair API sequences generated from prompts or workflow runs. Learn how run history, detailed request/response inspection, and AI Doctor help you debug and improve sequences.
The fields of an API sequence, the checks you can make on a response, and how a step reads values from earlier steps. For the steps that write, save and run one, see API tests.
Sequence
| Field | Meaning |
|---|---|
steps | The requests, in the order they run. Required, at least one. |
description | A short summary of what the sequence covers. |
stopOnFailure | When true (the default), the first failed step skips the steps after it. When false, every step runs. |
exports | Values to keep for later nodes in the same test. See Exports. |
Step
| Field | Meaning |
|---|---|
stepId | The name other steps use to read this step's response. Letters, digits and underscores, starting with a letter or underscore. Unique in the sequence. Defaults to step1, step2 and so on. |
apiRequestId | The id of a catalog request, from cofactor api-catalog endpoints list. Use "" for a step that does not use the catalog. It then needs method and urlTemplate. |
credentialId | The credential that signs the call, or null for none. |
credentialTemplateName | A persona name. The call is signed with that persona's credential on the environment the test runs on. Wins over credentialId. |
method | GET, POST, PUT, PATCH, DELETE, HEAD or OPTIONS. Defaults to the catalog request's method. |
urlTemplate | The address to call. Defaults to the catalog request's address. Start it with $var.ENV.api_url to call the environment the test runs on. |
queryParams | A list of { "key": "...", "value": "..." } pairs added to the address. |
bodyTemplate | The request body as a JSON string, so inner quotes are escaped. |
formParts | A multipart form body instead of bodyTemplate. Each part is { "kind": "text", "name": "...", "value": "..." } or { "kind": "file", "name": "...", "attachmentId": "<id>" }. A file part can add filename. Do not set a Content-Type header on the step. |
headersTemplate | Extra request headers, as { "Header-Name": "value" }. |
expectedStatusCodes | The status codes that pass, from 100 to 599. Without it, any 2xx passes. |
validations | Checks on the response. See Assertions. |
validationMode | all (the default) requires every validation to pass. any requires at least one. The status code must pass either way. |
description | A label for the step. |
urlTemplate, queryParams values, bodyTemplate, headersTemplate values and text formParts values can use values from earlier steps, $var variables and macros.
Assertions
Each validation has a left value, an operator and, for most operators, a right value.
{ "left": "read.response.status", "operator": "equals", "right": "active" }
left is <stepId>.response.<path>, a path into that step's JSON response. right is compared as written. It is not expanded, so {{...}} and $var in right stay literal text.
| Operator | Passes when |
|---|---|
equals | The value equals right. |
not_equals | The value differs from right. |
gt, gte, lt, lte | The value is greater than, at least, less than or at most right. Both are read as numbers. |
contains | The value includes right as text. |
not_contains | The value does not include right. |
is_set | The value exists. Needs no right. |
is_not_set | The value does not exist. Needs no right. |
Validations run only when the status code passes, and only on JSON responses. A validation on a missing value fails, except is_not_set, not_equals and not_contains, which pass.
Read values from earlier steps
Write {{<stepId>.response.<path>}} where a later step needs a value.
| Part | Rule |
|---|---|
| Path | Dots for keys and [0] for list items, as in {{list.response.data.pages[0].slug}}. |
.response. | Required. {{create.id}} is rejected when you save. |
| Order | A step reads only steps before it. A step cannot read itself. |
| Format | The earlier response must be JSON. |
Other values:
| Value | Meaning |
|---|---|
$var.ENV.api_url | The API address of the environment the test runs on. On a sandbox it is the address of the sandbox's api port, when the application declares one. |
$var.ENV.app_url | The web address of the environment. |
$var.ENV.<port>_url | The address of any other port a sandbox declares. |
$var.<name> | A value from the test's own variables, such as an export from a seed test. |
$RANDOM_STRING(6), $EMAIL() and others | A fresh value on every run. See Macros and variables. |
Exports
An export keeps a value from one step so later nodes in the same test can read it as $var.<variableName>.
{ "variableName": "project_id", "stepId": "create", "responsePath": "id" }
| Field | Meaning |
|---|---|
variableName | The variable's name, such as project_id. Unique in the sequence. |
stepId | The step to read from. |
responsePath | The path into the JSON body, such as data.id. |
source | response (the default) or request. |
Keep tokens out of exports. Use a credential for them.
Limits
- A call that gets no answer within 120 seconds fails.
- Saving checks the sequence's shape and references. It does not call your API. Run the test once before you rely on it.
- A run stores each request and response body up to a size cap.
cofactor workflow runs get ... --api-callprints the stored copy. $var.ENV.*needs an environment.cofactor workflow api-sequence executefails before it sends a request when the test has no default environment.