> ## Documentation Index
> Fetch the complete documentation index at: https://docs.keebai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# PATCH /v1/agents/{id}/scenarios/{scenarioId}/routes/{routeId}

> Partial update of a route.

Changes only the fields you send; `steps` or `cases` sent are replaced whole. A change of content writes a new version, so it can be [restored](https://docs.keebai.com/dev/endpoints/agents-route-version-restore.md).

## Endpoint

```
PATCH https://api.keebai.com/v1/agents/{id}/scenarios/{scenarioId}/routes/{routeId}
```

## Required scope

`agents:write`

## Path parameters

| Parameter | Type | Description |
| - | - | - |
| `id` | `string` | `ObjectId` of the agent. |
| `scenarioId` | `string` | `ObjectId` of the scenario. |
| `routeId` | `string` | `ObjectId` of the route. |

## Body

| Field | Type | Required | Description |
| - | - | - | - |
| `title` | `string` | No | 1 to 120 characters. |
| `applies_when` | `string` | No | Up to 1000. When this route applies. |
| `not_applies_when` | `string` | No | Up to 1000. When it looks like it applies but does not. |
| `steps` | `array` | No | Up to 50. Each step is `{ instruction?, actions?, steps? }`, nested up to **6 levels**; a seventh returns 400. |
| `cases` | `array` | No | Up to 50. Each case is `{ condition?, action?, actions? }`. |
| `order` | `number` | No | Position inside the scenario. |
| `status` | `string` | No | `proposed`, `approved` or `archived`. |
| `move_to_scenario_id` | `string` | No | Another scenario of the same agent to move the route to. |
| `expected_updated_at` | `string` | No | The `updated_at` you read, sent back as is. |

An action is `{ kind, target }`. `kind` is `native` (a platform function by name), `tool` (a [webhook tool](https://docs.keebai.com/dev/endpoints/tools-list.md) id), `catalog`, `move_stage` (a pipeline stage id), `tag` (a tag id) or `send_file`. Up to 60 per step or case.

## Example request

```bash curl theme={"system"}
curl -X PATCH https://api.keebai.com/v1/agents/6650a1b2c3d4e5f6a7b8c9d0/scenarios/6652c0ffee11223344556677/routes/6652c0ffee11223344556688 \
  -H "Authorization: Bearer kbai_pk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "status": "archived",
    "expected_updated_at": "2026-11-11T14:02:10.512000"
  }'
```

## Response

### 200 OK

```json theme={"system"}
{
  "route": {
    "id": "6652c0ffee11223344556688",
    "scenario": "6652c0ffee11223344556677",
    "title": "Book an appointment",
    "applies_when": "The customer asks for an appointment for a service.",
    "not_applies_when": "They only ask for the price, without wanting to book.",
    "steps": [
      {
        "instruction": "Ask which service and which day.",
        "actions": [],
        "steps": []
      },
      {
        "instruction": "Offer the available times.",
        "actions": [
          {
            "kind": "native",
            "target": "search_availability"
          }
        ],
        "steps": [
          {
            "instruction": "If none fits, offer the next day with availability.",
            "actions": [],
            "steps": []
          }
        ]
      }
    ],
    "cases": [
      {
        "condition": "There is no availability this week",
        "action": "Offer the waiting list.",
        "actions": [
          {
            "kind": "native",
            "target": "join_waitlist"
          }
        ]
      }
    ],
    "order": 0,
    "status": "archived",
    "version": 2,
    "source": "manual",
    "created_by": "ana@example.com",
    "created_at": "2026-11-11T14:02:10.512000",
    "updated_at": "2026-11-11T14:02:10.512000"
  }
}
```

### 400 Bad Request

An unknown value, steps nested more than 6 levels, an unknown property, or a `scenarioId`/`routeId` that is not an `ObjectId`.

### 404 Not Found

`AGENT_NOT_FOUND` when the agent belongs to another project of the company, `UPSTREAM_ERROR` (message `AGENT_NOT_FOUND`) when no agent has that id in the company; `scenario_not_found` or `route_not_found` when the scenario or the route is not the agent's.

### 409 Conflict

`stale_revision`: `expected_updated_at` no longer matches — someone saved in between. Read it again and re-apply your change.

### 401 Unauthorized

Missing, invalid, revoked, or expired token.

### 403 Forbidden

The token does not have the `agents:write` scope.

### 502 Bad Gateway

The agent service is unreachable.

## Operational notes

* **Archiving is the safe way to stop using a route.** It stays, with its history.
* **Moving keeps the history.** The route changes scenario; its versions come with it.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.