livekit.plugins.openai - ERROR - OpenAI Realtime A...
# ask-ai
g
livekit.plugins.openai - ERROR - OpenAI Realtime API returned an error Error(message=‘Only model output audio messages can be truncated’, type=‘invalid_request_error’, code=‘unsupported_content_type’, event_id=None, param=None) Why is this error happening when I am using gpt-realtime model for live voice calls
t
Thanks for reaching out, Yaseen. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're seeing that error because the Realtime API only allows truncating (interrupting) responses that are audio. The runtime attempted to truncate a non-audio (text) response from the GPT‑realtime model, and the API rejected it with "Only model output audio messages can be truncated." What to check and how to fix it • Are you configuring the model for audio output? If you're using
modalities=["text"]
, the model will produce text and truncation will fail. Use
modalities=["audio"]
and set a
voice
if you want audio responses. • If you want text responses + TTS, keep
modalities=["text"]
but perform TTS outside the Realtime API (a separate TTS plugin/engine). Handle interruptions at the TTS stream level instead of calling the Realtime truncation API. • If you sometimes pre-load conversation history, verify that it isn't causing the model to respond in text mode even when you requested audio. • Add a guard around your interrupt logic so you only call session interrupt/truncate when the current output is audio, and handle
unsupported_content_type
errors gracefully. If you share: • the Realtime model configuration you’re using (modalities, voice), • whether you load history, and • the code path where you call interrupt/truncate, I can point out the exact change to avoid this error. Would you like that? Sources: OpenAI Realtime API plugin guide | LiveKit docs | Agents (Node.js) | livekit/livekit_composite | DeepWiki | OpenAI and LiveKit partner to turn Advanced Voice into an API | examples/voice_agents | livekit/livekit_composite | DeepWiki | Realtime model plugins | LiveKit Docs
g
llm = RealtimeModel.with_azure( azure_deployment=“gpt-realtime”, api_version=“2024-10-01-preview”, voice=“echo”, input_audio_transcription=InputAudioTranscription( model=“whisper-1", language=“en”, ), )
t
Thanks — looking at your RealtimeModel config, you're requesting audio (you set
voice="echo"
), and you have transcription enabled. That means the model should produce audio responses — so the truncation error occurs when the session tries to interrupt a response that is actually being sent as non-audio (text). What to check next • Confirm the model is actually returning audio frames at runtime. If any messages are coming back as text (tool calls, metadata, or text-only responses) and your code calls
interrupt()
or truncation the same way, the API will raise that error. • Verify you are not preloading conversation history that forces text-mode responses. • Ensure your interrupt logic only calls
interrupt()
when the current output message has
content_type: "audio"
. Quick changes to try • Add a runtime check before truncation:
Copy code
if current_message.content_type == "audio":
    realtime_session.interrupt()
else:
    # handle text interruption (e.g., stop TTS or send a follow-up)
• If you sometimes want text + external TTS, explicitly request
modalities=["text"]
and perform TTS outside the Realtime API; then handle interruptions at the TTS stream level. If you share: • a short snippet showing where you call
interrupt()
and • whether you load prior messages into the session, I’ll point out the exact conditional or config change to stop this error. Would you like me to review that snippet?
g
After investigating our codebase and logs, I found: 1. Realtime Model Configuration: - Using Azure OpenAI Realtime with
voice="echo"
- NOT explicitly setting
modalities
parameter (defaults to [“text”, “audio”]) - Location: backend/src/main_new.py, lines 252-260 2. Conversation History: - NO preloading of conversation history ✅ 3. Interrupt Code Path: - ONE location calling
session.interrupt(force=True)
in Part 2 timing logic - Location: backend/src/agents/ielts_examiner_agent_new.py, line 64 - NO content type check before calling interrupt 4. Evidence from Logs: - Confirmed: Model IS returning text responses despite audio modality request - Error: “Text message received from Realtime API with audio modality” - This happens right before the truncation error Planned Fix: Implementing Option 1 (add guard around interrupt) + Option 2 (verify Azure voice name and add modalities=[“audio”])
t
Thanks — this is a great summary. You're on the right track. Based on what you found, here's a concise, prioritized plan and exact changes to prevent the truncation error. What to change (high priority) 1. Explicitly request audio-only from the model • Set
modalities=["audio"]
when creating the RealtimeModel to avoid text-only responses:
Copy code
llm = RealtimeModel.with_azure(
    azure_deployment="gpt-realtime",
    api_version="2024-10-01-preview",
    voice="echo",
    modalities=["audio"],
    input_audio_transcription=InputAudioTranscription(...)
)
1. Guard the interrupt call by content type • Check the current outgoing message or playback state before calling `session.interrupt(force=True)`:
Copy code
if current_message.content_type == "audio":
    session.interrupt(force=True)
else:
    # fallback: stop external TTS or send a follow-up command
Additional fixes (recommended) • Verify
voice="echo"
is a valid Azure voice name for your deployment. If it's invalid, the model may fall back to text. Update to a supported voice if needed. • Add error handling for
unsupported_content_type
around interrupt calls to avoid uncaught exceptions:
Copy code
try:
    session.interrupt(force=True)
except Exception as e:
    if "unsupported_content_type" in str(e):
        # handle gracefully (e.g., stop TTS or ignore)
    else:
        raise
Handling unexpected text responses • If text responses still appear, stream or convert them to audio via your TTS and control interruptions at the TTS layer instead of calling the Realtime API truncate. • Log the message
content_type
and any model metadata when this happens to help triage. Next step • If you want, paste the small snippet around line 64 where
session.interrupt
is called and the code that tracks `current_message`/playback state. I’ll point out the minimal edit to add the guard and error handling.