Outbound Calls
Initiate telephony and SIP calls, handle dynamic variables, and recall existing sessions.
The call-initiation hooks are TanStack Query mutations. Each returns a call session object and automatically invalidates the call-history list on success. Use mutateAsync when you need to read the response — for example, to capture the session ID for live transcript streaming.
Telephony vs. SIP
ScaleAI supports two outbound call transports:
| Transport | Hook | When to use |
|---|---|---|
| Telephony | useInitiateTelephonyCall | Managed provider numbers (Twilio, Plivo, Exotel). The platform owns the DID. |
| SIP | useOriginateSipCall | Your own SIP trunk. You supply a registered caller_id from your project's numbers. |
Initiate a telephony call
useInitiateTelephonyCall() places a call through a managed telephony provider. The platform selects (or uses your specified) from-number and routes the call through the provider.
import { useInitiateTelephonyCall } from "@scalereal/sr-voice-engine-react-sdk/hooks";
export function StartCallButton({ agentId }: { agentId: string }) {
const { mutate, isPending } = useInitiateTelephonyCall();
return (
<button
type="button"
disabled={isPending}
onClick={() =>
mutate({
agent_id: agentId,
destination_number: "+14155552671",
telephony_provider: "twilio",
})
}
>
{isPending ? "Calling…" : "Start call"}
</button>
);
}Reading the session ID
Use mutateAsync to await the session ID and immediately open a live transcript:
import {
useInitiateTelephonyCall,
useCallTranscript,
} from "@scalereal/sr-voice-engine-react-sdk/hooks";
export function CallWithTranscript({ agentId }: { agentId: string }) {
const initiateCall = useInitiateTelephonyCall();
const transcript = useCallTranscript({ onCallEnded: () => console.info("ended") });
const handleCall = async () => {
const session = await initiateCall.mutateAsync({
agent_id: agentId,
destination_number: "+14155552671",
telephony_provider: "twilio",
});
// session.id is now available — open the live transcript immediately
transcript.startTranscriptSession(session.id);
};
return (
<button type="button" disabled={initiateCall.isPending} onClick={handleCall}>
Call and stream transcript
</button>
);
}Parameters — InitiateTelephonyCallRequest
| Parameter | Type | Required | Description |
|---|---|---|---|
agent_id | string | ✓ | The agent to run on the call. |
destination_number | string | ✓ | Callee number in E.164 format (e.g. "+14155552671"). |
telephony_provider | string | ✓ | Provider identifier — "twilio", "plivo", "exotel", etc. |
from_number | string | Caller ID in E.164. Required when is_platform_number is false. | |
is_platform_number | boolean | When true, the platform selects an available number from its pool. | |
dynamic_variables | Record<string, string> | Values to fill {{variable_name}} placeholders in the agent's prompt at call time. | |
override_availability | boolean | When true, bypasses the agent's configured availability windows. |
Response
{
id: string; // Call session ID — use with useCallTranscript / usePostCallSse
agent_id: string;
user_id: string;
workspace_id: string;
project_id: string;
status: string; // e.g. "initiated"
}Dynamic variables
Dynamic variables let you inject caller-specific context into the agent's prompt at call time without modifying the agent itself. Any {{variable_name}} placeholder in the prompt is replaced with the value you supply.
Dynamic variables are resolved at call time and are not stored on the agent. To persist reusable variable templates, use useAgentPromptVariables.
mutate({
agent_id: "agent-id",
destination_number: "+14155552671",
telephony_provider: "twilio",
dynamic_variables: {
customer_name: "Jane Smith",
account_tier: "enterprise",
outstanding_balance: "$320.00",
},
});If the agent's prompt contains Hello, {{customer_name}}!, the agent will greet the caller as Hello, Jane Smith! on this specific call.
Originate a SIP call
useOriginateSipCall() places a call through your own SIP trunk. You must provide a caller_id that is registered as a SIP number in your project.
import { useOriginateSipCall } from "@scalereal/sr-voice-engine-react-sdk/hooks";
export function SipCallButton({ agentId }: { agentId: string }) {
const { mutate, isPending } = useOriginateSipCall();
return (
<button
type="button"
disabled={isPending}
onClick={() =>
mutate({
agent_id: agentId,
destination_number: "+14155552671",
caller_id: "+14155550000",
})
}
>
{isPending ? "Calling…" : "Call via SIP"}
</button>
);
}Parameters — OriginateSipCallRequest
| Parameter | Type | Required | Description |
|---|---|---|---|
agent_id | string | ✓ | The agent to run on the call. |
destination_number | string | ✓ | Callee number in E.164 format. |
caller_id | string | ✓ | An E.164 SIP number registered in your project. Used as the call's caller ID. |
timeout | number | Seconds to wait for the callee to answer before abandoning. | |
variables | Record<string, string> | Dynamic prompt variable values, same semantics as dynamic_variables above. | |
override_availability | boolean | When true, bypasses the agent's configured availability windows. |
Response
{
id: string; // Call session ID
status: string;
destination: string;
created_at: string;
}Recall a call
useRecallCall() requests a redial of an existing call session. This is useful for "call again" flows in a call history UI.
import { useRecallCall } from "@scalereal/sr-voice-engine-react-sdk/hooks";
export function RecallButton({ callSessionId }: { callSessionId: string }) {
const { mutate, isPending, data } = useRecallCall();
return (
<button
type="button"
disabled={isPending}
onClick={() => mutate({ callSessionId })}
>
{isPending ? "Redialing…" : "Recall"}
</button>
);
}Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
callSessionId | string | ✓ | The session to redial. |
Response — RecallCallResponse
| Field | Type | Description |
|---|---|---|
id | string | null | New call session ID, or null when the recall was skipped. |
status | string | "initiated" when a new call starts; "skipped" when recall is disabled. |
destination | string | null | The number that was dialed. |
recalled_from | string | null | The original session ID that triggered the recall. |
A status of "skipped" means the original call session has recall disabled — for example, because it was a manually-ended test call. No error is thrown; check status in the response to distinguish the two outcomes.
Override availability
All three call hooks support override_availability. When set to true, the call proceeds regardless of the agent's scheduled availability windows. Use this for programmatic or administrative calls that must not be gated by operating hours.
mutate({
agent_id: "agent-id",
destination_number: "+14155552671",
telephony_provider: "twilio",
override_availability: true,
});Related pages
- Realtime — Stream live transcripts and post-call processing updates using the call session ID.
- Call History — Query past sessions and track the new call.
- Phone Numbers — Review project numbers and provider sync.
- Agents — Configure the agent that runs on the call.