Skip to content

POST /v1/runs

Summary

This endpoint queues and executes a run of a published prompt version. It accepts the identifier of the prompt version, the inputs required by that prompt (text and/or images), and optional runner options. The server attempts to process the run synchronously: if the run finishes within roughly two minutes, it returns the run's outputs and status immediately; otherwise it returns a timeout response with the run ID so you can poll the run using GET /v1/runs/:runId.

HTTP Request

http
POST /v1/runs

Request Body

The body must be JSON. All fields not listed below are ignored.

FieldTypeRequiredDescription
promptVersionIdstringYesIdentifier of the published prompt version to run.
inputsobjectYesContainer for the inputs expected by the prompt. See the prompt's inputsJTD to learn the required keys and types.
inputs.textInputsobjectDepends on inputsJTDRecord mapping input keys to string values. Only include the keys required by the prompt.
inputs.imageInputsarray of objectsDepends on inputsJTDArray of image objects. The number of images must exactly match the imageCount specified in the prompt's inputsJTD metadata. Each entry specifies an image using one of two forms: a url object with an image url or a base64 object with a Base64‑encoded image. The discriminator field type determines which form is used.
runOptionsobjectNoPartial record whose keys must be one of the supported run options (see Reference: Run options) and whose values are strings. Use this to override default runner settings. Omit to accept all defaults.

Image input objects

Each image entry is a discriminated union on its type:

typeRequired fieldsDescription
"url"url (string)A publicly accessible HTTPS URL pointing to the image.
"base64"base64 (string)A Base64‑encoded image without any data URL prefix.

Response

Success (200 OK)

When the run finishes within the waiting window, the server returns a JSON object whose status is "SUCCESS" and a data object containing:

FieldTypeDescription
runIdstringIdentifier of the run.
outputsarray of objectsList of output items. Each item has a type field ("text", "image", or "error") and a data field containing the corresponding content. See Output item types.
runStatusstringStatus of the run. Possible values include "queued", "running", "succeeded", and "failed". See Run status.
tokensintegerBetterPrompt tokens consumed. See account page for token details..

An example success response:

json
{
  "status": "SUCCESS",
  "data": {
    "runId": "01234567-89ab-cdef-0123-456789abcdef",
    "outputs": [{ "type": "text", "data": "A witty caption for your image…" }],
    "runStatus": "succeeded",
    "tokens": 132
  }
}

Output item types

typeShapeDescription
text{ "type": "text", "data": string }Generated text content.
image{ "type": "image", "data": string }The URL to a generated image resource. The URL is publicly accessible and expires after 24 hours.
error{ "type": "error", "data": string }Error message when a step fails during generation.

Timeout (504 Gateway Timeout)

If the run has not finished within the server's two‑minute polling window, the request returns a timeout response:

json
{
  "status": "GATEWAY_TIMEOUT_ERROR",
  "message": "The request timed out while waiting for the run to finish.",
  "data": {
    "runId": "01234567-89ab-cdef-0123-456789abcdef"
  }
}

You can continue to monitor the run by calling GET /v1/runs/:runId until it completes.

Error responses

See Error codes.

HTTP statusstatus codeDescription
422VALIDATION_ERRORThe request body failed validation; for example, the promptVersionId is not a valid UUID, required fields are missing, an image input has an unsupported type, or runOptions contains invalid keys.
404NOT_FOUND_ERRORThe specified promptVersionId does not correspond to any published prompt version, or the prompt has been unpublished.
504GATEWAY_TIMEOUT_ERRORThe run did not finish within the allotted time. The data field contains the runId, which can be polled later.

See also