@custom_llm.route("/chat/completions", methods=["POST"])def custom_llm_openai_sse_handler(): data = request.get_json() Elixir.track_conversation(data["call"]["id"])
5
Send audio to Elixir
After the call ends, use Elixir.upload_audio(conversation_id: str, audio_url: str) to send call recording to Elixir. This can be used in one of two ways:
Send a publicly accessible call recording URL.
Upload the file directly (if recording link is not public).
Examples:
Pipecat + Twilio (File Upload)
bot_runner.py
@app.post("/twilio_recording", response_class=PlainTextResponse)async def twilio_recording(request: Request): print("POST /twilio_recording") data = {} try: # shouldnt have received json, twilio sends form data form_data = await request.form() data = dict(form_data) except Exception: pass callId = data.get("CallSid") recordingUrl = data.get("RecordingUrl") if not callId or not recordingUrl: raise HTTPException( status_code=500, detail="Missing 'CallSid' or 'RecordingUrl' in request" ) # Download the recording from Twilio async with aiohttp.ClientSession() as session: async with session.get( f"{recordingUrl}.mp3?RequestedChannels=2", auth=aiohttp.BasicAuth(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN), ) as response: if response.status == 200: recording_content = await response.read() content_type = response.headers.get("Content-Type") print( f"Recording content: {content_type}, {len(recording_content)} bytes" ) await Elixir.upload_audio( conversation_id=callId, audio_buffer=recording_content, audio_content_type=content_type, ) else: raise HTTPException( status_code=500, detail="Failed to download recording from Twilio" )