> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.rasen.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.rasen.ai/_mcp/server.

# How Rasen works

> Follow the path from a workspace key to a published agent, a routed number, a call and its results, with the operations, objects and agent states of each step.

## Summary

This page shows each step from an API key to a finished call, with its operations and objects.
It also gives the states of an agent. It does not give the requests of each step; each step links
the guide that does.

## Facts

| Item                 | Value                                                                            |
| -------------------- | -------------------------------------------------------------------------------- |
| Authentication       | `Authorization: Bearer <key>`. The key selects its workspace                     |
| Mutations            | `Idempotency-Key` on each write; `If-Match` with the current `ETag` on each edit |
| What a call runs     | The agent's live version at admission. Draft edits never change a call           |
| Agent `state` values | `draft`, `live`, `paused`, `archived`. Open vocabulary                           |
| Archive window       | 14 days from `archived_at` to `archive_deadline`, then permanent deletion        |
| IDs                  | Opaque strings of at most 128 characters                                         |

## The flow

1. **Get a workspace and an API key.** A member of the workspace creates the key in the Rasen app,
   on the **Developers** page under **API keys**. The API has no operation that creates a
   workspace or a key. Check the key with `getContext`. See
   [Authentication](/get-started/authentication) and [Quickstart](/get-started/quickstart).
2. **Create an agent.** `createAgent` creates the agent in state `draft`, with its first draft.
   Edit the draft with `updateAgentDraft`, pick a voice with `listVoices` and set variables with
   `setAgentVariable`. See [Build and publish an agent](/guides/agents).
3. **Add knowledge, tools and credentials.** Add sources with `createKnowledgeSource`,
   `uploadKnowledgeSource` or `createAgentKnowledgeSource`, and link them with
   `addAgentKnowledgeSource`. Add webhook tools with `createAgentTool`, and MCP servers with
   `createMcpServer` and `discoverMcpTools`. Store tool credentials with `createSecret`. See
   [Add knowledge to an agent](/guides/knowledge), [Add tools and MCP servers](/guides/tools),
   [Store and rotate tool credentials](/guides/secrets) and
   [Add a before-call tool](/guides/before-call-tool).
4. **Validate and publish.** `validateAgentDraft` checks the draft, with an optional patch, and
   saves nothing.
   `publishAgent` freezes the complete draft into a version and makes it live in one step. The
   agent is then `live`. `rollbackAgent` makes an earlier version live again. See
   [Build and publish an agent](/guides/agents).
5. **Test in the browser.** `setAgentShareLink` issues a link that runs the live version in a
   browser, with no phone number and no carrier. `rotateAgentShareLink` replaces it. See
   [Share a test-call link](/guides/share-links).
6. **Connect a carrier account or a SIP trunk.** `createTelephonyConnection` stores the
   credentials of a carrier account. `connectSipTrunk`, `createSipInboundConnection` and
   `createSipOutboundTrunk` set up a SIP trunk. See [Connect a carrier account](/guides/telephony)
   and [Connect a SIP trunk](/guides/sip-trunk).
7. **Import a number.** `listAvailablePhoneNumbers` and `importPhoneNumbers` import numbers of a
   carrier account. `importSipNumber` imports a number of a SIP trunk. See
   [Connect a carrier account](/guides/telephony) and [Connect a SIP trunk](/guides/sip-trunk).
8. **Route the number to the agent.** `setPhoneNumberInboundAgent` makes the agent answer the
   number. `addPhoneNumberOutboundAgent` lets the agent call from it. `provisionPhoneNumber`
   retries the carrier setup of an inbound number. See
   [Route phone numbers to agents](/guides/phone-numbers) and
   [Configure call transfers](/guides/call-transfers).
9. **Calls happen.** An inbound call to a routed number needs no operation. `createCall` places
   an outbound call. `createAgentSession` runs the agent on a call leg that you own. Campaigns
   call a list: `createCampaign` or `uploadCampaign`, then `planCampaign`, `admitCampaign` and
   `startCampaign`. See [Place calls and read results](/guides/calls),
   [Run an outbound campaign](/guides/campaigns), [Call lifecycle](/concepts/call-lifecycle) and
   [Campaign lifecycle](/concepts/campaign-lifecycle).
10. **Read the results.** `getCall` gives the call's state and the readiness of each result. Read
    the results with `getCallTranscript`, `getCallSummary`, `getCallExtraction`,
    `downloadCallRecording` and `listCallToolOutcomes`. Follow a live call with
    `streamLiveCallTranscript`. See [Place calls and read results](/guides/calls),
    [Follow a call's transcript live](/guides/live-transcript) and
    [Read tool call logs](/guides/tool-call-logs).
11. **Receive webhooks.** `createWebhookEndpoint` subscribes an HTTPS endpoint to `call.completed`,
    `call.failed`, `call.analyzed` and `tool.failed`. See [Receive call events with webhooks](/guides/webhooks)
    and [Webhook events](/reference/webhook-events).
12. **Measure usage.** `listUsage` and `queryUsage` give the quantities of each component, for
    each agent or call. See [Measure usage](/guides/usage).

## Objects

Each ID is opaque: never parse it or build one. The prefix of the contract examples helps you
read logs.

| Object               | What it is                                                                                                | ID prefix                                                                 |
| -------------------- | --------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- |
| Workspace            | The container of agents, numbers, calls and keys. A key belongs to one workspace.                         | `ws_`                                                                     |
| API key              | The bearer credential of one workspace. You manage keys in the Rasen app.                                 | `key_`                                                                    |
| Agent                | A voice agent: its identity, its draft, its versions and its state.                                       | `agent_`                                                                  |
| Draft                | The editable configuration of an agent: prompt, voice, settings, variables and tools. One for each agent. | None. Read it at `/agents/{agent_id}/draft`; its `revision` is its `ETag` |
| Version              | An immutable published configuration. Calls run the live version.                                         | `pub_`                                                                    |
| Tool                 | A webhook tool of an agent, or a tool from an MCP server.                                                 | `tool_`                                                                   |
| MCP server           | A registered MCP server whose tools agents can use.                                                       | `mcp_`                                                                    |
| Secret               | A write-only credential for tools and MCP servers, with immutable versions.                               | `sec_`                                                                    |
| Knowledge source     | A web page, text or document that an agent answers from.                                                  | `kb_`                                                                     |
| Telephony connection | The stored credentials of a carrier account.                                                              | None in the contract examples                                             |
| Phone number         | A number imported from a carrier account or a SIP trunk.                                                  | `number_`                                                                 |
| Call                 | One call: inbound, outbound, an agent session or a browser test.                                          | `call_`                                                                   |
| Campaign             | A list of recipients that one agent calls. The same ID is the `batch_id` of the exports.                  | None in the contract examples                                             |
| Webhook endpoint     | An HTTPS URL that receives call and tool events.                                                          | `wep_`                                                                    |
| Share link           | A bearer link to test the live version in a browser. One for each agent.                                  | None. Read it at `/agents/{agent_id}/share-link`                          |

## Agent lifecycle

| `state`    | Meaning                                                                                                           | Calls                                      |
| ---------- | ----------------------------------------------------------------------------------------------------------------- | ------------------------------------------ |
| `draft`    | The agent was never published.                                                                                    | Refused. Publish the agent first.          |
| `live`     | The agent has a live version.                                                                                     | Admitted. Each call runs the live version. |
| `paused`   | The agent keeps its configuration and history.                                                                    | Refused with `agent_not_live`.             |
| `archived` | The agent is in its 14-day archive window. Rasen refuses draft edits, publish and rollback with `agent_archived`. | Refused with `agent_not_live`.             |

| From                        | To                                    | Cause                                                                                                                         |
| --------------------------- | ------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| None                        | `draft`                               | `createAgent`                                                                                                                 |
| `draft`                     | `live`                                | `publishAgent`                                                                                                                |
| `live`                      | `live`                                | `publishAgent` with a new version, or `rollbackAgent` to an earlier version                                                   |
| Any state                   | `paused`                              | No API operation sets `paused`.                                                                                               |
| `draft`, `live` or `paused` | `archived`                            | `archiveAgent`. It refuses with `archive_blocked` while a call, a campaign or other work of the agent runs.                   |
| `archived`                  | The state before the archive          | `unarchiveAgent`, before `archive_deadline`                                                                                   |
| `archived`                  | Deleted: reads answer `404 not_found` | `archive_deadline`, 14 days after `archived_at`. Running work or a legal hold can delay the deletion, never bring it forward. |

```mermaid
stateDiagram-v2
    [*] --> draft: createAgent
    draft --> live: publishAgent
    live --> live: publishAgent or rollbackAgent
    draft --> archived: archiveAgent
    live --> archived: archiveAgent
    paused --> archived: archiveAgent
    archived --> draft: unarchiveAgent
    archived --> live: unarchiveAgent
    archived --> paused: unarchiveAgent
    archived --> [*]: archive_deadline passes
```

## Rules

* MUST publish an agent before it takes calls. A draft edit never changes a call.
* MUST NOT parse an ID or build one from a prefix.
* MUST send a new `Idempotency-Key` with each write, and the current `ETag` in `If-Match` with
  each edit.
* MUST keep an unknown `state` value of any object, and never read it as success.
* MUST unarchive an agent before its `archive_deadline` to keep it.

## Related

* [Quickstart](/get-started/quickstart)
* [Build and publish an agent](/guides/agents)
* [Archive and restore an agent](/guides/archive-agent)
* [Call lifecycle](/concepts/call-lifecycle)
* [Campaign lifecycle](/concepts/campaign-lifecycle)
* [Glossary](/reference/glossary)