spicyapiDocs
Main content

Managed preset workflows

Run multi-step media pipelines with a single API call, inspect step-by-step costs, and rely on automatic refunds for failed or unexecuted steps.

Managed preset workflows package common multi-step generation chains — such as editing an image and animating it to HD video, refining and upscaling to 4K, or extending and upscaling a video — behind three endpoints:

  • GET /api/v1/workflows — discover available presets, their input JSON Schemas, public step models, and billing summaries.
  • POST /api/v1/workflows/run — validate your input and queue step 0 as a standard generation task.
  • GET /api/v1/workflows/{workflowId} — poll progress, idempotently advance to the next step when the active step's outputs are ready, and collect the final assets.

Every workflow step executes as an ordinary SpicyAPI task. There is no hidden bundle pricing and no bypass of your account balance, spend caps, or API-key model permissions.

Available presets

The initial release includes three managed presets. Call GET /api/v1/workflows at runtime to read the current inputSchema and each step's public model identifier from the authenticated live catalog (GET /api/v1/models returns the per-model pricing for each step).

Preset IDPipelineRequired inputsOptional inputs (defaults)
image-to-video-hdEdit source image → animate into HD videoimage_url, promptedit_prompt, video_prompt, aspect_ratio, duration_seconds (3–15, default 5), resolution (720p | 1080p, default 1080p), generate_audio (boolean)
image-to-4k-upscaleRefine source image → upscale to 4Kimage_url, promptaspect_ratio, resolution (2k | 4k | 8k, default 4k), output_format (jpeg | png | webp, default jpeg)
video-extend-hdExtend source video → upscale to HD / 4Kvideo_url, promptduration_seconds (4–30, default 5), extend_resolution (480p | 720p, default 720p), target_resolution (720p | 1080p | 2k | 4k, default 1080p), generate_audio (boolean, default true)
  • image_url and video_url accept either a publicly accessible HTTPS media URL or a committed spicy://f/<id> upload URI (or spicy://a/<id> asset library reference). See Media.
  • Unknown input fields are rejected with 400 Bad Request (additionalProperties: false).
  • For image-to-video-hd, prompt applies to both steps unless you override either step with edit_prompt or video_prompt.

1. Discover presets

GET /api/v1/workflows

Requires an API key with the run_models capability. The response includes Cache-Control: private, max-age=60.

curl
curl -s https://api.spicyapi.ai/api/v1/workflows \
  -H "Authorization: Bearer $SPICY_API_KEY" | jq .

The example below uses MODEL_ID_FROM_CATALOG as a placeholder for each step's exact public model identifier returned at runtime by GET /api/v1/workflows and the live model catalog (GET /api/v1/models).

Response
{
  "code": 200,
  "msg": "success",
  "data": {
    "items": [
      {
        "id": "image-to-video-hd",
        "name": "Image Edit to HD Video",
        "description": "Refine or restyle a source image with a prompt, then animate the resulting frame into an HD video clip.",
        "category": "image-to-video",
        "billingSummary": "Billed step by step at each model's published rate (image edit + per-second video generation). Unexecuted steps are never charged, and any failed step is automatically refunded.",
        "inputSchema": {
          "type": "object",
          "required": ["image_url", "prompt"],
          "additionalProperties": false,
          "properties": {
            "image_url": { "type": "string", "minLength": 1 },
            "prompt": { "type": "string", "minLength": 1, "maxLength": 2000 },
            "duration_seconds": { "type": "integer", "minimum": 3, "maximum": 15, "default": 5 },
            "resolution": { "type": "string", "enum": ["720p", "1080p"], "default": "1080p" }
          }
        },
        "steps": [
          {
            "index": 0,
            "key": "edit_image",
            "title": "Edit Source Image",
            "description": "Apply prompt-guided image editing to produce the keyframe.",
            "model": "MODEL_ID_FROM_CATALOG"
          },
          {
            "index": 1,
            "key": "generate_video",
            "title": "Generate HD Video",
            "description": "Animate the edited keyframe into an HD video clip.",
            "model": "MODEL_ID_FROM_CATALOG"
          }
        ]
      }
    ]
  },
  "request_id": "req_01k3m8x9q2z4v7n5p6r8s0t1w2"
}

2. Start and poll a workflow run

Starting a run sends POST /api/v1/workflows/run (capability run_models) and returns HTTP 202 Accepted with Location: /api/v1/workflows/{workflowId}, Retry-After: 2, and Cache-Control: no-store.

  • Send an Idempotency-Key header (up to 128 characters) so network retries safely return the existing workflow run instead of starting a second one. Reusing the same key with different preset or input parameters returns 409 Conflict.
  • Optional X-Spicy-Retention shortens how long step outputs and prompts are kept (in seconds), propagated to every step task. See Retention and destruction.
  • Poll GET /api/v1/workflows/{workflowId} (capability read_tasks) with the same API key that started the workflow.

Polling advances the workflow

When the active step reaches succeeded and its platform-stored output is ready, GET /api/v1/workflows/{workflowId} idempotently creates the next step using a deterministic step key (<workflowId>:step:<index>). Concurrent polls never create duplicate step tasks or charge twice. Keep polling until top-level data.state is succeeded or failed.

Start and poll image-to-video-hd
IDEM_KEY="wf-$(uuidgen)"

START=$(curl -s -X POST https://api.spicyapi.ai/api/v1/workflows/run \
  -H "Authorization: Bearer $SPICY_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $IDEM_KEY" \
  -d '{
    "preset": "image-to-video-hd",
    "input": {
      "image_url": "spicy://f/fil_01k3m8x9q2z4v7n5p6r8s0t1w3",
      "prompt": "cinematic neon rain reflection, slow dolly push in",
      "duration_seconds": 5,
      "resolution": "1080p"
    }
  }')
echo "$START" | jq .

WORKFLOW_ID=$(echo "$START" | jq -r '.data.workflowId')

while true; do
  RUN=$(curl -s "https://api.spicyapi.ai/api/v1/workflows/$WORKFLOW_ID" \
    -H "Authorization: Bearer $SPICY_API_KEY")
  STATE=$(echo "$RUN" | jq -r '.data.state')
  echo "state=$STATE currentStep=$(echo "$RUN" | jq -r '.data.currentStep') totalCost=$(echo "$RUN" | jq -r '.data.totalCost')"
  if [ "$STATE" = "succeeded" ] || [ "$STATE" = "failed" ]; then
    echo "$RUN" | jq .
    break
  fi
  sleep 3
done

Response shape and states

Both POST /api/v1/workflows/run and GET /api/v1/workflows/{workflowId} return the same data object inside the standard {code, msg, data, request_id} envelope. Polling a succeeded workflow automatically refreshes short-lived signed URLs on the final step's output.assets.

Completed workflow response
{
  "code": 200,
  "msg": "success",
  "data": {
    "workflowId": "wfr_01k3m8x9q2z4v7n5p6r8s0t1w9",
    "preset": "image-to-video-hd",
    "state": "succeeded",
    "currentStep": 1,
    "totalSteps": 2,
    "totalCost": "0.34",
    "steps": [
      {
        "index": 0,
        "key": "edit_image",
        "title": "Edit Source Image",
        "model": "MODEL_ID_FROM_CATALOG",
        "state": "succeeded",
        "taskId": "job_01k3m8x9q2z4v7n5p6r8s0t1wa",
        "estimatedCost": "0.04",
        "actualCost": "0.04",
        "settled": true,
        "output": {
          "assets": [
            {
              "key": "tasks/2026/11/27/job_01k3m8x9q2z4v7n5p6r8s0t1wa/frame.png",
              "url": "https://example.r2.cloudflarestorage.com/results/frame.png?X-Amz-Signature=SIGNATURE_FROM_RESPONSE",
              "expiresAt": "2026-11-27T09:32:11Z",
              "mime": "image/png"
            }
          ]
        },
        "startedAt": "2026-11-27T09:10:00Z",
        "completedAt": "2026-11-27T09:10:12Z"
      },
      {
        "index": 1,
        "key": "generate_video",
        "title": "Generate HD Video",
        "model": "MODEL_ID_FROM_CATALOG",
        "state": "succeeded",
        "taskId": "job_01k3m8x9q2z4v7n5p6r8s0t1wb",
        "estimatedCost": "0.30",
        "actualCost": "0.30",
        "settled": true,
        "output": {
          "assets": [
            {
              "key": "tasks/2026/11/27/job_01k3m8x9q2z4v7n5p6r8s0t1wb/clip.mp4",
              "url": "https://example.r2.cloudflarestorage.com/results/clip.mp4?X-Amz-Signature=SIGNATURE_FROM_RESPONSE",
              "expiresAt": "2026-11-27T09:35:00Z",
              "mime": "video/mp4"
            }
          ]
        },
        "startedAt": "2026-11-27T09:10:15Z",
        "completedAt": "2026-11-27T09:12:40Z"
      }
    ],
    "output": {
      "assets": [
        {
          "key": "tasks/2026/11/27/job_01k3m8x9q2z4v7n5p6r8s0t1wb/clip.mp4",
          "url": "https://example.r2.cloudflarestorage.com/results/clip.mp4?X-Amz-Signature=SIGNATURE_FROM_RESPONSE",
          "expiresAt": "2026-11-27T09:35:00Z",
          "mime": "video/mp4"
        }
      ]
    },
    "createdAt": "2026-11-27T09:10:00Z",
    "updatedAt": "2026-11-27T09:12:40Z",
    "completedAt": "2026-11-27T09:12:40Z"
  },
  "request_id": "req_01k3m8x9q2z4v7n5p6r8s0t1wc"
}

Workflow and step states

  • Workflow state: queued, running, succeeded, or failed.
  • Step state: pending (not yet started), queued, running, succeeded, failed, expired, canceled, or skipped (downstream step bypassed after an earlier step failed).
  • Each started step carries its own taskId, which you can inspect individually with GET /api/v1/jobs/recordInfo or download as a model-named attachment with POST /api/v1/common/download-url.

Transparent step-by-step billing and refunds

Workflow billing follows the exact same hold-and-settle contract as standalone tasks (see Billing):

  • Per-step pricing at published rates: Each step is billed at its model's published account rate (including any group discount on your account). steps[].estimatedCost shows the held estimate while a step is in progress; once steps[].settled is true, steps[].actualCost holds the final settled charge. totalCost sums each step's final actualCost (when settled) or estimatedCost (while still open).
  • No upfront charge for unexecuted steps: Step 1 is never created and holds no funds until step 0 succeeds with a ready output.
  • Automatic refund on step failure: If a step fails or expires, its hold is automatically released/refunded under standard task settlement rules, and all subsequent steps transition from pending to skipped with zero charge.
  • Partial completion stays auditable: If step 0 succeeds and step 1 fails (for example due to insufficient balance for step 1, an API-key model restriction, or an upstream generation failure), step 1 is refunded (or never created) and step 0's completed output remains accessible in steps[0].output and via steps[0].taskId.
  • API-key model permissions apply to every step: If your API key uses an Allowed models list, allow every step model returned by GET /api/v1/workflows for the preset you intend to run.

Next steps

On this page