#can we implement dynamic variables in a call transfer?
1 messages · Page 1 of 1 (latest)
Short answer: Yes—with a few constraints.
What works
- Dynamic variables are supported across the conversation and in tool parameters. They can be used to personalize prompts, first messages, and tool calls. This applies during transfers as well. (elevenlabs.io)
- After an agent-to-agent transfer, system variables (for example, system__current_agent_id) update automatically; custom dynamic variables remain available in the conversation context. Ensure the destination agent is configured to use them. (elevenlabs.io)
- For human transfers, the transfer_to_number tool accepts client_message and agent_message parameters, which you can populate using dynamic variables because tool parameters support them. (elevenlabs.io)
Key limitations to be aware of
- The transfer phone number itself must match one of the numbers preconfigured in the tool’s transfer rules; it isn’t arbitrary at runtime. Configure the allowed destinations first, then select among them. (elevenlabs.io)
- If the target agent requires a dynamic variable that isn’t present at transfer time, the call can fail with “Missing dynamic variable after agent transfer.” Define required vars (or defaults) on every agent that might receive a transfer. (help.elevenlabs.io)
Relevant docs
- Dynamic variables overview and usage in tool parameters. (elevenlabs.io)
- Agent-to-agent transfer workflow. (elevenlabs.io)
- Transfer to human (transfer_to_number) tool. (elevenlabs.io)
- Help Center error reference for missing variables after transfer. (help.elevenlabs.io)
Sources:
Dynamic variables | ElevenLabs Documentation
Dynamic variables | ElevenLabs Documentation
Transfer to human | ElevenLabs Documentation
Transfer to human | ElevenLabs Documentation
Where can I locate the reason for my call failing? – ElevenLabs
Dynamic variables | ElevenLabs Documentation
Agent transfer | ElevenLabs Documentation
Transfer to human | ElevenLabs Documentation
Where can I locate the reason for my call failing? – ElevenLabs
how to override the voice id/stability in next js?
Short answer:
- Text-to-Speech (HTTP): pass the voice you want in the URL and override stability per request with voice_settings in the JSON body. The override applies only to that request. (elevenlabs.io)
- Text-to-Speech (WebSocket): connect with the desired voice_id and send a first message that includes voice_settings (e.g., stability) to set it for the stream; you can also override per subsequent message. (elevenlabs.io)
- Conversational AI agents: you can override the voice at session start using tts.voice_id (or the widget’s override-voice-id). Stability override for agents is not documented; set stability in the voice’s settings or synthesize via the TTS API if you need per-request control. (elevenlabs.io)
How to do it in a Next.js app without exposing your API key:
- Server route for HTTP TTS override (example shape):
- Request: POST https://api.elevenlabs.io/v1/text-to-speech/{voice_id}
- Headers: xi-api-key: YOUR_API_KEY, Content-Type: application/json
- Body (minimal): { "text": "Hello", "model_id": "eleven_turbo_v2_5", "output_format": "mp3_44100_128", "voice_settings": { "stability": 0.35 } }
- Return the audio stream to the client. The voice_id in the path selects the voice; voice_settings.stability overrides the stored voice stability for this request. (elevenlabs.io)
- If you’re streaming via WebSocket from the client, generate a short‑lived signed URL on your Next.js server (never expose your API key) and on connect send a JSON message with voice_settings: { stability: … }. (elevenlabs.io)
Useful references:
- Create speech (POST /v1/text-to-speech/:voice_id) and voice_settings field (“applied only on the given request”). (elevenlabs.io)
- WebSocket streaming guide showing voice_settings in the first message and per-message overrides. (elevenlabs.io)
- Get voice settings / default voice settings endpoints (to inspect current stability/similarity). (elevenlabs.io)
- Agent overrides for voice_id and widget override-voice-id. (elevenlabs.io)
- Next.js guidance: obtain signed URL server-side; never expose your API key client-side. (elevenlabs.io)
If you’re using agents and specifically need per-session stability changes, there is no official agent override documented for stability today; use the TTS API workflow above or adjust the voice’s settings. (elevenlabs.io)
// Enhanced configuration with full voice settings
const enhancedConfig = {
agentId,
apiKey,
baseUrl: EU_RESIDENCY_BASE_URL,
serverLocation: 'eu-residency',
conversationConfigOverride: {
agent: {
prompt: {
prompt: conversationConfigOverride?.agent?.prompt?.prompt || "
},
firstMessage: conversationConfigOverride?.agent?.first_message ||
language: conversationConfigOverride?.agent?.language || voiceSettings?.language ||
},
tts: {
voiceId: finalVoiceId, // Use camelCase voiceId instead of voice_id
voice_settings: {
stability: conversationConfigOverride?.tts?.voice_settings?.stability ?? (voiceSettings?.stability ?? 0.5),
similarity_boost: conversationConfigOverride?.tts?.voice_settings?.similarity_boost ?? 0.8,
use_speaker_boost: conversationConfigOverride?.tts?.voice_settings?.use_speaker_boost ?? false,
style: conversationConfigOverride?.tts?.voice_settings?.style ?? 0.0
},
speed: conversationConfigOverride?.tts?.speed ?? voiceSettings?.speed ?? 1.0,
model_id: conversationConfigOverride?.tts?.model_id || "eleven_flash_v2_5"
}
},
Why isnt this overrifde object working? the voice isnt getting override
Short answer: your override isn’t taking effect because the Conversational AI overrides schema only accepts tts.voice_id (snake_case) for voice selection. Keys like tts.voiceId, tts.voice_settings, tts.speed, and tts.model_id aren’t documented override fields and are ignored.
What to fix
- Use snake_case and only pass tts.voice_id in conversation_config_override.
- Enable “Voice ID” (and any other) overrides in the agent’s Security tab; an override for a field that isn’t enabled will be rejected.
- Omit fields you don’t want to override (don’t pass empty strings/nulls).
Minimal working example
- conversation_config_override:
- agent: { prompt: { prompt: "…" }, first_message: "…", language: "en" }
- tts: { voice_id: "<your-voice-id>" }
Why
- Official overrides docs show the accepted shape and examples, and only list Voice ID under tts. They also require enabling overrides in Security and recommend omitting unused fields. (elevenlabs.io)
- The WebSocket example for conversation initiation likewise shows only tts.voice_id in overrides. (elevenlabs.io)
- Twilio personalization examples (same initiation payload) also only support tts.voice_id. (elevenlabs.io)
About stability/similarity/speed/model
- These are TTS voice settings (stability, similarity_boost, style, speed) in the TTS API, but they’re not documented as runtime overrides for Conversational AI. Adjust them in the agent/voice configuration, not via conversation_config_override. (elevenlabs.io)
EU residency note
- If you’re targeting EU residency, connect to the EU residency environment (separate domain/workspace) rather than relying on a custom serverLocation flag. See the data residency docs for the EU environment URL and access details. (elevenlabs.io)
Sources:
Overrides | ElevenLabs Documentation
Agent WebSockets | ElevenLabs Documentation
Twilio personalization | ElevenLabs Documentation
Create speech | ElevenLabs Documentation
Data residency | ElevenLabs Documentation
This conversation failed with the following reason:
Invalid message received
Short answer: your override object doesn’t match the supported schema, and the first WebSocket message likely wasn’t the expected “conversation_initiation_client_data”, which triggers “Invalid message received.”
What overrides are supported
- At conversation start you can override only these fields:
- agent.prompt.prompt
- agent.first_message
- agent.language
- tts.voice_id
The keys are snake_case. There is no per‑conversation override for tts.voice_settings (stability, similarity_boost, style), speed, or model_id. Use only tts.voice_id in overrides. (elevenlabs.io)
Correct structure (JS SDK)
- Pass overrides via startSession, not as conversationConfigOverride on your own:
- startSession({ agentId, overrides: { agent: {...}, tts: { voice_id: "…" } } })
Use snake_case keys like first_message and voice_id. (elevenlabs.io)
- startSession({ agentId, overrides: { agent: {...}, tts: { voice_id: "…" } } })
Enable permission for overrides
- In the agent’s Security tab, explicitly enable overrides for the fields you plan to override (e.g., Voice ID). If not enabled, the platform rejects the override (you may see “Override is not allowed for this AI agent”). (elevenlabs.io)
Why you saw “Invalid message received”
- The real‑time connection expects the first frame to be of type conversation_initiation_client_data and to follow the documented schema (including conversation_config_override with the allowed fields). Sending any other shape (wrong casing, unsupported keys, or missing type) results in “Invalid message received.” Let the SDK send this for you, or match the spec exactly if you’re writing your own client. (elevenlabs.io)
How to change stability/speed/model
- These are part of the agent’s TTS configuration, not per‑conversation overrides. Set them on the agent (e.g., via Agents API update/get) or in voice settings; speed is supported with a 0.7–1.2 range. (elevenlabs.io)
Minimal fix for your snippet
- Replace camelCase keys with snake_case and remove unsupported fields from overrides:
- tts: { voice_id: finalVoiceId }
- agent: { first_message: "...", language: "..." }
- Ensure the agent has Voice ID override enabled in Security, and pass these via the SDK’s overrides option at startSession. (elevenlabs.io)
If you also need dynamic variables (e.g., during transfers), include all required variables in the dynamic_variables object of the initiation payload or your webhook; missing required variables will cause failures. (elevenlabs.io)
Sources:
Overrides | ElevenLabs Documentation
Chat Mode | ElevenLabs Documentation
Overrides | ElevenLabs Documentation
Agent WebSockets | ElevenLabs Documentation
Update agent | ElevenLabs Documentation
Overrides | ElevenLabs Documentation
Twilio Personalization — ElevenLabs Documentation