Skip to main content
Pre-call initialization lets you dynamically select and configure the agent before a call starts. Works on all transports.

Supported Transports

Setup

Phone numbers (Twilio / WhatsApp)

Bind with routing_target_type: "webhook":

WebRTC

Pass server_url in requestData:
variables beside server_url reach your server as call.variables, and win a clash with the ones you answer — see WebRTC. Outside development server_url must be https:// (a number’s is a 422, a WebRTC one a 400), except a Kubernetes Service in the same cluster, whose host ends in .svc or .svc.cluster.local. Loopback and private addresses are not exempt. An inline agent you answer with is not refused for a plain-http tool or MCP URL, but deliveries to one are logged as plain_http_delivery, at most once a minute per kind and naming only the host. See Compliance.

Your Server Receives

call.id is the id the call is created with — the call_id of its events, its webhooks and GET /v1/calls/{id} — so you can match the call-init you answered to everything the call does after it. (A text conversation’s is the session’s id; see below.)

Outbound calls

An outbound call placed from a webhook-routed number (POST /v1/calls/outbound or a campaign) runs call-init too, at the dial, before the phone rings. The roles are the same as inbound: phoneNumber is your number, customer the person called. call also carries agent_id, the agent the dial named, and variables, the dial’s (a campaign target’s) template variables, when it has any. provider_call_id is empty: nothing has been dialled yet.
  • Your answer’s agent_id (an agent in the same project) or inline agent runs the call; with neither, the dial’s agent does.
  • Your variables are merged under the dial’s: on a clash the dial’s value wins. Your metadata is stored as on an inbound call (the call’s metadata.metadata), and knowledge_context likewise.
  • A call-init that fails, times out, or names an agent that cannot run (an invalid inline config, an agent_id that is not one of the project’s) does not stop the dial: the dial’s agent runs with the dial’s own variables and metadata, none of your answer, and a warning is logged.
  • Call-init runs after the project’s limits admit the dial, so a refused dial never reaches your server.
A number with any other routing never runs call-init.

Text conversations (SMS, WhatsApp text)

A text to a webhook-routed number runs call-init once per conversation: on the message that opens a session, never on the ones after it. call.id is the id the session is created with (the session_id of its events), call.type is inboundSms or inboundWhatsAppMessage, and provider_call_id is empty.
  • Your answer’s agent_id (an agent in the number’s project) or inline agent answers the conversation. An inline agent has no agent row: the session’s agent_id is null, and its config is never shown by the API.
  • variables, metadata and knowledge_context are kept on the session and apply to every reply in it, as they do for a whole call.
  • A call-init that fails, times out, or names no agent that can run leaves the message unanswered (an SMS gets a short apology) and opens no session; the next message asks again.
  • The session expires after 24 hours without a message; the next text opens a new one, and asks again.

Verify the Signature

Each call-init request is HMAC-signed with the number’s server_url_secret (returned when you bind the number). Headers: X-TurnCall-Signature: v1=<hex> and X-TurnCall-Timestamp; the HMAC-SHA256 is computed over "{timestamp}.{raw_body}" — the same scheme as event webhooks.
Reject unverified requests — call-init decides which agent answers a real call.

Response Options

Response Fields

What Happens

1

call.initializing webhook event fires (informational)

2

Template {{variables}} are rendered into the system prompt

3

knowledge_context is prepended to the system prompt

4

metadata is stored on the call record

5

call.started event fires

6

Pipeline starts with the resolved configuration

Returning an inline agent

agent and agent_id are alternatives, not a merge: an inline agent replaces the configuration for that call rather than overriding parts of a stored one. Send the whole config, not a patch. Because an inline agent is not a stored agent, it has no row to point at, and that is visible to you:
Every event for such a call carries agent_id: null, and the call does not appear in per-agent listings. This is the correct answer to “which stored agent ran this call” — null means none of them, not not resolved yet.
Everything else still works. The configuration the call ran with is recorded on the call itself, so post-call analysis, the transcript and the call.ended webhook are unaffected. Correlate such calls through call_id, or through metadata you returned in the call-init response — that is what it is for. That recorded configuration is never shown back. It can carry credentials — MCP headers, an llm.api_key, AWS keys — so the call read and call.ended leave it out of metadata, and a text session’s is not in any session read. Only call-init can give a call an inline agent: metadata.dynamic_config on POST /v1/calls/outbound is refused with a 422. Knowledge bases linked to a stored agent do not apply, since the call does not run that agent. An inline agent names its own in knowledge_bases, with the same fields as a link (knowledge_base_id, mode, priority, top_k, similarity_threshold, tool_description):
Each id must be a knowledge base in the phone number’s project. One that is not, or an entry TurnCall cannot read, is skipped with a warning and the call still connects. See Knowledge Base. An inline agent can name the project’s skills in skills, as a stored agent does. A name the project has no published version of is skipped with a warning, and the call starts without it.
For persistent, searchable knowledge, use the Knowledge Base API instead of knowledge_context. Use knowledge_context for per-call dynamic data like CRM records or open tickets.