https://retellai.com/?utm_source=discord&utm_medium=seo logo
I’m using the Retell Web SDK with a Cloudflare Wor...
# ❓・ai-evy-support
h
@AI Evy I’m using the Retell Web SDK with a Cloudflare Worker backend to run browser-based async voice interviews (win/loss analysis). Current setup: HubSpot sends buyers an interview link with a query parameter (ntid). Cloudflare Worker looks up metadata from Make.com/Google Sheets. On button click (“Start Interview”), the browser calls a /create-call-token endpoint on my Worker. The Worker calls create-web-call with my agent_id and passes dynamic metadata variables. The Worker responds with access_token → client immediately calls retellWebClient.startCall(). Questions: Is this the right architecture for security and token timing, given your 30-second token expiry? What’s your recommended best practice for passing deal-specific metadata to the agent? For multi-tenant use (different clients/agents), should I spin up separate Workers with unique API keys per client, or is there a better approach? Are there any SDK-level gotchas with Cloudflare Workers (modules, fetch, CORS) that I should account for? Any recommended error-handling patterns if the token creation fails client-side or server-side?
a
Thanks for tagging me @hotfudge99. I'll look through relevant sources and get back to you shortly.
### Answer Your architecture aligns well with Retell AI's recommended approach. Let me address your specific questions: ## Architecture and Token Timing Your setup is correct for web calls [(1) ]() . The flow should be: 1. Create web call server-side using the create-web-call endpoint [(2) ]() 2. Pass the access_token to your frontend [(1) ]() 3. Start the call immediately with
retellWebClient.startCall()
Copy code
javascript
await retellWebClient.startCall({
 accessToken: createCallResponse.access_token,
 sampleRate: 24000, // (Optional) set sample rate of the audio capture and playback
 // (Optional) device id of the mic.
 captureDeviceId: "default",
 // (Optional) device id of the speaker
 playbackDeviceId: "0ec1807fd0fe6e51b990660ec4e2ebb78sdfcba51e279815d00c423ce03407ff",
 // (Optional) Whether to emit "audio" events that contain raw pcm audio bytes represented by Float32Array
 emitRawAudioSamples: false,
}) ;
## Metadata Best Practices For deal-specific metadata, use the
metadata
and
retell_llm_dynamic_variables
fields when creating the web call [(2) ]() : - `metadata`: Store arbitrary data like your internal customer ID for later retrieval - `retell_llm_dynamic_variables`: Inject dynamic variables into your Response Engine prompt and tool descriptions
Copy code
json
{ "customer_name": "John Doe" }
## Multi-Tenant Architecture The documentation doesn't specify multi-tenant patterns, but you can use different
agent_id
values per client when creating calls . Each agent can have its own configuration, voice settings, and response engine [(3) ]() . ## Error Handling Implement proper error handling for the web client [(1) ]() :
Copy code
javascript
retellWebClient.on("error", (error) => {
 console.error("An error occurred:", error) ;
 // Stop the call
 retellWebClient.stopCall() ;
}) ;
## Token Timing Considerations Based on community discussions, there have been issues with timing between token creation and
startCall()
[(4) ]() . Ensure minimal delay between receiving the access_token and calling
startCall()
to avoid connection issues . For Cloudflare Worker-specific considerations and detailed multi-tenant patterns, I'd recommend checking the [GitHub examples]() or contacting support for implementation guidance specific to your infrastructure.
​ To learn more, see the sources I considered: [[1] Connect to web call](https://docs.retellai.com/deploy/web-call) [[2] Create Web Call](https://docs.retellai.com/api-references/create-web-call) [[3] Create Agent](https://docs.retellai.com/api-references/create-agent) [[4] Error_user_not_joined](https://discord.com/channels/1186424376300679209/1392872855372435671) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.