> ## 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.

# POST /v1/agents/{id}/scenarios/{scenarioId}/routes

> Add a route to a scenario.

Adds a route: when it applies, what the agent does step by step and its cases. The functions its actions name are mounted on the agent.

## Endpoint

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

## Required scope

`agents:write`

## Path parameters

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

## Body

| Field | Type | Required | Description |
| - | - | - | - |
| `title` | `string` | Yes | 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`. |

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 POST https://api.keebai.com/v1/agents/6650a1b2c3d4e5f6a7b8c9d0/scenarios/6652c0ffee11223344556677/routes \
  -H "Authorization: Bearer kbai_pk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Book an appointment",
    "applies_when": "The customer asks for an appointment for a service.",
    "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"
          }
        ]
      }
    ],
    "status": "approved"
  }'
```

## Response

### 201 Created

```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": "approved",
    "version": 1,
    "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

Missing `title`, an unknown action `kind`, steps nested more than 6 levels, or an unknown property at any level; or a `scenarioId` 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` when the agent has no scenario with that id.

### 422 Unprocessable Entity

`too_many_routes` (50 per scenario).

### 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

* **Version 1 is written on create.** Every later change of content adds one.
* **One route, one situation.** Use `not_applies_when` to keep it from catching the case next door.


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