> ## 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/from-template

> Add a scenario from a template, with all its routes.

Creates a scenario from a [template](https://docs.keebai.com/dev/endpoints/scenario-templates-list.md) with all its routes — or nothing, if one route fails.

## Endpoint

```
POST https://api.keebai.com/v1/agents/{id}/scenarios/from-template
```

## Required scope

`agents:write`

## Path parameters

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

## Body

| Field | Type | Required | Description |
| - | - | - | - |
| `template_key` | `string` | Yes | The `key` from [`GET /v1/scenario-templates`](https://docs.keebai.com/dev/endpoints/scenario-templates-list). |
| `name` | `string` | No | Another name, if the business calls it differently. |
| `language` | `string` | No | Language of the template. Defaults to the agent's language. |
| `knowledge_node_id` | `string` | Only for `information` templates | `ObjectId` of the knowledge base folder the scenario answers from. Required when the template's `kind` is `information`. |

## Example request

```bash curl theme={"system"}
curl -X POST https://api.keebai.com/v1/agents/6650a1b2c3d4e5f6a7b8c9d0/scenarios/from-template \
  -H "Authorization: Bearer kbai_pk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "template_key": "agenda"
  }'
```

## Response

### 201 Created

```json theme={"system"}
{
  "scenario": {
    "id": "6652c0ffee11223344556677",
    "agent": "6650a1b2c3d4e5f6a7b8c9d0",
    "name": "Bookings",
    "icon": "calendar",
    "kind": "instructions",
    "when_to_open": "The customer wants to book, change or cancel an appointment.",
    "description": "",
    "description_locked": false,
    "channel_ids": [],
    "knowledge_node_id": null,
    "knowledge_missing": false,
    "order": 0,
    "status": "approved",
    "source": "template",
    "created_by": "ana@example.com",
    "created_at": "2026-11-11T14:01:55.103000",
    "updated_at": "2026-11-11T14:01:55.103000",
    "routes": [
      {
        "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": "template",
        "created_by": "ana@example.com",
        "created_at": "2026-11-11T14:02:10.512000",
        "updated_at": "2026-11-11T14:02:10.512000"
      }
    ]
  },
  "missing_functions": [
    "join_waitlist"
  ]
}
```

### 400 Bad Request

Missing `template_key` or an unknown property.

### 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; `template_not_found` when no template has that key.

### 422 Unprocessable Entity

`knowledge_folder_required` when the template is of kind `information` and no `knowledge_node_id` was sent; `knowledge_folder_not_found` when that folder does not exist or is not active; `too_many_scenarios` (50 per agent).

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

* **`missing_functions` are functions its routes use that your company does not have yet.** The routes keep them and the agent gets them as soon as they exist — so this is a to-do list, not an error.
* **An `information` template needs its folder.** Send `knowledge_node_id` with the knowledge base folder it answers from; the `kind` of each template comes in [`GET /v1/scenario-templates`](https://docs.keebai.com/dev/endpoints/scenario-templates-list).
* **A template is a starting point.** Adjust its routes to the business with [`PATCH .../routes/{routeId}`](https://docs.keebai.com/dev/endpoints/agents-route-update).


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