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

# Calls and results

```bash
export RASEN_API_BASE="https://api.rasen.ai/v1"
export RASEN_API_KEY="<your key>"
AUTH="Authorization: Bearer $RASEN_API_KEY"
```

## Start a call

An outbound call needs a published agent and a number assigned to it for outbound calls
([Phone numbers](/guides/phone-numbers)).

```bash
KEY=$(uuidgen)
curl -sS -i -X POST "$RASEN_API_BASE/calls" \
  -H "$AUTH" -H "Idempotency-Key: $KEY" -H "Content-Type: application/json" \
  -d '{"agent_id": "agent_…", "to": "+12025550123",
       "expected_version_id": "pub_…",
       "dynamic_variables": {"customer_name": "Alex"},
       "metadata": {"crm_ticket": "T-4821"}}'
```

```http
HTTP/1.1 202 Accepted
Location: /v1/calls/call_…

{"call_id": "call_…", "published_version_id": "pub_…", "state": "admitted",
 "from_number_id": "num_…", "poll_after_seconds": 2}
```

* `202` means the call was admitted and the dial was requested once. It is not a connected call.
* The call runs the agent's live published version, and the answer names it. The request carries no
  agent configuration. A call keeps its version even if a later publish or rollback changes the live
  one.
* With `expected_version_id`, a different live version is refused with `409 conflict`,
  `reason: live_version_mismatch` and `details.current_live_version_id`. Nothing is dialled. It
  cannot select an older version.
* The call dials from the agent's only outbound number, or from `from_number_id`. With no number the
  answer is `409 number_not_outbound`; with several and no choice it is `409 conflict`,
  `reason: outbound_number_ambiguous`.
* `dynamic_variables` holds at most 64 keys, 4096 characters per value and 16 KiB in total.
* `metadata` is for your own correlation: at most 16 keys (`^[a-z][a-z0-9_]{0,63}$`), string values
  of at most 512 characters, at most 4 KiB. It is returned on call reads and can be filtered on. It
  never routes the call and must not hold credentials.
* A paused or archived agent is refused with `agent_not_live` (`details.state`).

### Retrying a call start

* After a lost answer, send the identical request with the same key. You get the same call with
  `Idempotent-Replayed: true`, and the number is never dialled twice. A different body under the
  same key is `409 idempotency_key_reused`. A duplicate sent while the first is still being admitted
  answers `409 idempotency_in_progress` with `Retry-After`.

* The stored answer is the accepted call (IDs, version, state, poll hint). It never holds the number
  you dialled, the variables or the metadata, so a replay returns exactly the original body.

* `503 at_capacity` and `429 quota_exceeded` carry `Retry-After`. After that delay, send the
  identical request with the same key: it is admitted afresh. Every other refusal replays as itself
  for the key's 24 hours.

* `503 unavailable` names what was unavailable in `details.dependency` (`call_serving` for call
  start). Wait `Retry-After` and send the identical request with the same key.

## Run an agent on a call leg you already own

Use `POST /agent-sessions` (`createAgentSession`) when your own switch, carrier, dialer or
application already holds the call. Rasen places, answers and routes no telephone call and needs no
phone number. You get a media WebSocket for the call, and the agent talks on it.

```bash
curl -sS -i -X POST "$RASEN_API_BASE/agent-sessions" \
  -H "$AUTH" -H "Idempotency-Key: $(uuidgen)" -H "Content-Type: application/json" \
  -d '{"agent_id": "agent_…", "direction": "inbound",
       "media": {"transport": "binary", "encoding": "pcm16", "sample_rate": 8000},
       "metadata": {"external_call_id": "pbx-4411"}}'
```

```http
HTTP/1.1 201 Created
Location: /v1/calls/call_…

{"call_id": "call_…", "agent_id": "agent_…", "published_version_id": "pub_…", "state": "admitted",
 "direction": "inbound", "media": {"transport": "binary", "encoding": "pcm16", "sample_rate": 8000},
 "websocket_url": "wss://…/calls/call_…/ws/…", "expires_at": "2026-10-14T10:02:00Z"}
```

* The smallest request is `{"agent_id": "agent_…"}`. `media` then is `binary`, `pcm16`, 8000 Hz.
* `media.transport`: `binary` sends raw audio in binary frames; `json` sends base64 media events in
  text frames. `media.encoding`: `pcm16` (signed 16-bit little-endian mono) or `mulaw` (G.711,
  8000 Hz only). `media.sample_rate` is 8000 or 16000 and is the same in both directions.
* Unknown fields are refused. A `to`, caller ID, number or provider field is `400 invalid_request`.
* Connect to `websocket_url` exactly as returned and send audio before `expires_at`, 120 seconds
  after admission. The agent's audio comes back on the same socket. The call becomes active when the
  first audio frame arrives. One socket per call.
* The URL is a credential: do not log it.
* A socket that does not connect in time frees the reserved capacity, and the call ends with
  `end_reason` `never_connected`.
* `direction` is a label for call reads and filters. Without it, the live version's
  `call_direction` setting is used, else `outbound`.
* `expected_version_id`, `dynamic_variables` and `metadata` follow the same rules as
  [Start a call](#start-a-call). `metadata` is returned on call reads.
* The answer's `call_id` works with every call operation below: read, end, transcript stream,
  recording and results.
* The same key and body answer the same call, `websocket_url` and `expires_at`. A replay never
  extends the deadline. `503 at_capacity` and `429 quota_exceeded` carry `Retry-After`: send the
  identical request with the same key after it, and it is admitted afresh. Every other refusal
  replays as itself for the key's 24 hours.
* Call starts and agent sessions share the call-start rate limit
  ([Rate limits](/concepts/rate-limits)) and the workspace's concurrent-call quota. Capacity is
  reserved at admission, so a session counts until it ends or its connect window passes.

## End a call

```bash
curl -sS -X POST "$RASEN_API_BASE/calls/call_…/end" -H "$AUTH" -H "Idempotency-Key: $(uuidgen)"
```

A live call answers `{"terminal": false, "end_requested": true}`: the stop is requested and the call
ends shortly. A call that already ended answers its final state with `end_requested: false`; so does a
call in `evidence_pending`, whose conversation is over while its record is being finished. Ending
twice is safe. `503 call_orchestrator_unavailable` means no worker holds the call yet: retry with the
same key.

## Read a call

```bash
curl -sS "$RASEN_API_BASE/calls/call_…" -H "$AUTH"
```

The call carries its `state`, `terminal`, the readiness of each result (`transcript_state`,
`extraction_state`, `summary_state`), your `metadata`, and `effective_variables`:
the variable values the call ran with, classified. A `public` or `internal` variable shows its value;
a `pii` or `confidential` one is `redacted`; an undeclared one is `withheld_unclassified`; a secret
never appears. Follow `poll_after_seconds`; when it is null, nothing will change.

A call placed by a carrier dial also says what the carrier reported. `dial_outcome` is `dialing`
until the carrier reports, then its latest report, for example `answered`, `no_answer`, `busy`,
`voicemail`, `rejected`, `invalid_number` or `failed`. `dial_sip_code` is the SIP response code
when the carrier gave one (for example `480` or `486`). A call that never connected
(`end_reason: never_connected`) says why here. Both are null for calls no carrier dialled: inbound,
browser and test calls. Both fields also appear on call list items.

> **Note**
>
> `dial_outcome` is an open vocabulary. Preserve a value you do not recognise, and never treat it as
> success.

## List and search calls

Lists carry no variables, transcripts or result bodies.

> **Every call list and search reads only the last 30 days by default**
>
> Unless you send `start` and `end`, `GET /calls`, `POST /calls/search` and a metadata lookup read only
> the last 30 days. An older call is simply not in the answer: nothing says it was left out. One request
> spans at most 93 days, so to look further back, repeat the request over consecutive windows (`start`
> and `end` inside `filter` in the POST form).

```bash
# Newest first; the default range is the last 30 days (at most 93).
curl -sS "$RASEN_API_BASE/calls?agent_id=agent_a&agent_id=agent_b&terminal=true&limit=100" -H "$AUTH"
# Your own correlation value, exact match.
curl -sS "$RASEN_API_BASE/calls?metadata_key=crm_ticket&metadata_value=T-4821" -H "$AUTH"
```

For large ID sets, use the POST form (up to 1000 ID and metadata values, 128 KiB). It answers the
same page as the GET form ([Filters and limits](/concepts/filters)):

```bash
curl -sS -X POST "$RASEN_API_BASE/calls/search" -H "$AUTH" -H "Content-Type: application/json" \
  -d '{"filter": {"call_id": ["call_…", "call_…"], "extraction_state": ["ready"]}, "limit": 200}'
# Many correlation values at once, over an explicit window (the default is the last 30 days):
curl -sS -X POST "$RASEN_API_BASE/calls/search" -H "$AUTH" -H "Content-Type: application/json" \
  -d '{"filter": {"metadata_key": "crm_ticket", "metadata_value": ["T-4821", "T-4822"],
                  "start": "2026-07-01T00:00:00Z", "end": "2026-10-01T00:00:00Z"}, "limit": 200}'
```

Each item's `id` is the call ID. `metadata_key` and `metadata_value` go together; a key alone is
`invalid_request`. A metadata value may be empty (`"tag": ""`), so `metadata_value=` (GET) or
`"metadata_value": [""]` (POST) finds the calls that stored an empty value. Every other empty filter
value is refused.

## Keep a copy in sync

Scan for changes with `updated_since`. Items come oldest change first. A call's `updated_at` moves
when the call, its transcript, one of its results or one of its tool outcomes changes. The last page
carries `scanned_through`: start the next scan there.

```bash
SINCE="2026-09-29T00:00:00Z"
curl -sS "$RASEN_API_BASE/calls?updated_since=$SINCE&limit=200" -H "$AUTH"
# … follow next_cursor; on the last page, set SINCE to scanned_through
```

A scan never ends past a change that was still being written when it ran, so a change committed
while you read is picked up by the next scan rather than skipped. A long-running write can hold
`scanned_through` back for a while; it never makes a scan skip anything. A tracked call that shows
no change for five minutes should still be read directly once (`GET /calls/{call_id}`): do not infer
completion from silence.

### Changes scan availability

A changes scan (`updated_since`, on `GET /calls` or `POST /calls/search`) can answer
`503 unavailable` with `details.dependency = "call_changes"`. Keep your saved checkpoint unchanged,
wait `Retry-After`, and retry the scan. A creation-order list does not use the changes checkpoint;
it is not a substitute for a complete changes scan. Continue reading known calls directly when
needed, and do not infer completion from an unavailable scan.

* In changes mode, `start` and `end` bound `updated_at`, not `created_at`. If you send `start` too,
  it must equal `updated_since`. `end` is optional and capped at the visibility watermark.
* Timestamps without a time zone are refused, and so is an empty range.

## Results

Every result read returns what is stored and never starts work. A result that is not stored yet is
`pending` (follow `poll_after_seconds`); one that will not be produced is `unavailable`,
`not_requested` or `failed`, with no invented empty value.

```bash
curl -sS "$RASEN_API_BASE/calls/call_…/transcript?limit=200" -H "$AUTH"
curl -sS "$RASEN_API_BASE/calls/call_…/extraction" -H "$AUTH"
curl -sS "$RASEN_API_BASE/calls/call_…/summary" -H "$AUTH"
curl -sS "$RASEN_API_BASE/calls/call_…/tool-outcomes" -H "$AUTH"
```

* A transcript page is bound to the transcript it came from. If a newer transcript replaces it, the
  old cursor answers `invalid_request` with `field: cursor`: start again without it.
* Extraction fields are typed by the definitions the call ran with; a field the call did not yield
  is `not_found`.
* Tool outcomes show the tool, its kind, a state (`pending`, `succeeded`, `failed` or
  `indeterminate`) and a registered `reason`, never arguments, results or credentials. Built-in
  tools (`end_call`, `transfer`) have no `tool_id`.
* `indeterminate` means the effect is unknown: it may or may not have happened. Any outcome the
  platform cannot confirm reads this way. Check the system the tool acts on before doing anything
  again; never rerun it automatically.
* A tool call refused because its credential version was revoked shows `credential_unavailable` as
  its reason ([Secrets and rotation](/guides/secrets#4-emergency-revocation)).

## Download a recording

```bash
# Whole verified object. -J uses the server's sanitised attachment filename.
curl -sS -OJ "$RASEN_API_BASE/calls/call_…/recording" -H "$AUTH"

# Resume or fetch one byte range.
curl -sS -OJ "$RASEN_API_BASE/calls/call_…/recording" -H "$AUTH" \
  -H "Range: bytes=0-1048575"
```

The authenticated endpoint streams the selected immutable recording without exposing a storage URI
or signed URL and without converting the audio. A whole object answers `200`; one satisfiable range
answers `206`. An out-of-bounds range answers `416` with the size in `Content-Range`, while malformed
or multiple ranges are `400 invalid_request`. Unknown or foreign calls, calls without servable
recording evidence, and contradictory stored metadata all answer the same `404 not_found`.

## Export campaign evidence

Use the campaign ID returned by creation or listing with these read-only exports. See
[Campaigns](/guides/campaigns) to create, start and manage campaigns.

```bash
# One result row per recipient.
curl -sS -OJ "$RASEN_API_BASE/batch-calls/batch_…/export" -H "$AUTH"

# One transcript-state row per attempt; save response headers to find the next cursor.
curl -sS -D transcript-headers.txt -o transcripts.csv \
  "$RASEN_API_BASE/batch-calls/batch_…/transcripts/export?limit=500" -H "$AUTH"
```

The result CSV contains recipient and attempt identities, safe outcome fields, only the last four
destination digits and a SHA-256 value. It never contains a full destination, recording URL,
transcript, secret or diagnostic payload.

Transcript export is paged in CSV responses rather than JSON. Each page holds at most 500 attempts.
Follow `X-Next-Cursor` with the same `limit` until the header is absent. The first request fixes an
upper watermark, so attempts added later do not enter the download. Every row states whether the
transcript is `ready`, `pending`, `absent` or `unavailable`; inaccessible calls reveal neither a
call ID nor content. If an HTTP transfer breaks, discard that page and request it again with the same
cursor (or without a cursor for the first page).

## Stream transcript events

`GET /calls/{call_id}/transcript/stream` returns read-only Server-Sent Events for the selected
verified transcript layer. It requires `calls.read`. The stream reports readiness and public
transcript segments; reading it does not start transcription work.

```bash
curl -N -sS "$RASEN_API_BASE/calls/$CALL_ID/transcript/stream" \
  -H "Authorization: Bearer $RASEN_API_KEY" -H "Accept: text/event-stream"
```

Save the opaque event ID and send it in `Last-Event-ID` when reconnecting to this call. IDs bind
the workspace, call and selected generation. A replacement emits `transcript.restart` and closes;
discard the previous resume position and reconnect for the new generation.