---
title: "Create or update a chain definition"
method: POST
path: "/agent/v1/chains"
tags: ["Agent Sandbox"]
---

# Create or update a chain definition

`POST /agent/v1/chains`

Steps reference scenario names (see /agent/v1/scenarios) plus 'ok' for a normal response. loop=true wraps past the end; loop=false holds the final step forever. scope 'per-run' keys position by X-Agent-Run-Id (falls back to per-key without one); 'per-key' shares position across all calls on the key.

## Request body

- object
  - `name` string, required
  - `steps` string[], required
  - `loop` boolean
  - `scope` 'per-run' | 'per-key'

## Response `201`

Definition stored

## Other responses

- `401` — No agent key
- `422` — Validation failure with field_errors + valid_steps

---

[API](https://skmtc.net/reqres/apis/reqres-api.md) · [All operations](https://skmtc.net/reqres/apis/reqres-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/reqres/reqres-api/revisions/e5ced6578853/schema)
