-
Notifications
You must be signed in to change notification settings - Fork 2.7k
fix(google): improve error message for model/API mismatch in Realtime API #4611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
… API When users configure a Gemini API model (e.g., gemini-2.5-flash-native-audio-preview-09-2025) with VertexAI, or vice versa, they receive a cryptic WebSocket 1008 policy violation error. This makes it difficult to diagnose the root cause. This change detects 1008 errors that likely indicate a model/API mismatch and appends a helpful hint to the error message, suggesting the correct model name to use. The hint only appears when: - A WebSocket 1008 policy violation occurs - The model name pattern doesn't match the API being used Example improved error: ``` Failed to connect to Gemini Live Hint: Model 'gemini-2.5-flash-native-audio-preview-09-2025' appears to be a Gemini API model, but VertexAI is enabled. VertexAI requires different model names (prefixed with 'gemini-live-'). Try using model='gemini-live-2.5-flash-preview-native-audio-09-2025' instead. ``` Fixes: livekit/livekit#4026
📝 WalkthroughWalkthroughAdded model/API compatibility checks and contextual error hints to the Google realtime plugin: introduced KNOWN_VERTEXAI_MODELS and KNOWN_GEMINI_API_MODELS, added _validate_model_api_match and _get_1008_error_hint helpers, run validation before options construction, and append hint text to logged/raised errors (including WebSocket 1008 and API connection errors). Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (1)**/*.py📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧬 Code graph analysis (1)livekit-plugins/livekit-plugins-google/livekit/plugins/google/realtime/realtime_api.py (2)
🔇 Additional comments (6)
✏️ Tip: You can disable this entire section by setting Comment |
| is_vertexai_model = model.startswith("gemini-live-") | ||
| is_gemini_api_model = model.startswith(("gemini-2.", "gemini-1.")) | ||
|
|
||
| if use_vertexai and is_gemini_api_model: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this logic doesn't seem very robust. we do not know how google is going to name their future models.
if you intend to do this, I would suggest:
- keeping a list known of vertex models and another list of gemini
- when specifically detect for mismatch, and throw an exception if a user is using vertext with gemini and vice versa
alternatively, translating the error code and log a clear message (this model isn't supported)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good, it makes sense. Will adapt and resubmit. Thanks for the review!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi David, the first solutions was indeed too specific and made assumptions about future model naming patterns.
I refactored it to be more generic:
- Added
KNOWN_VERTEXAI_MODELSandKNOWN_GEMINI_API_MODELSas explicit frozensets with the models we know today - Created
_validate_model_api_match()that checks if the model is in the wrong list and raises aValueErrorright away in__init__- so devs get a clear error before even trying to connect - Simplified the 1008 error hint to just be a generic message for unknown models that slip through
The idea is: if we know the model, fail fast with a clear message. If we don't know it, let it through and give a helpful hint if it fails with 1008.
I tried to optimize for developer experience, getting a ValueError at initialization is way better than debugging a cryptic WebSocket error later.
Let me know if you think it's overcomplicated or not generic enough. Happy to iterate on it!
This is my first time contributing to the project, so I picked a small issue to learn the process and get to know the maintainers and other contributors. Really appreciate your feedback, it helped me understand the codebase better. Looking forward to more reviews!
Address review feedback by: - Adding KNOWN_VERTEXAI_MODELS and KNOWN_GEMINI_API_MODELS frozensets with explicit lists of known models - Adding _validate_model_api_match() to raise ValueError early in __init__ when a known model is used with the wrong API configuration - Simplifying the 1008 error hint to be generic (for unknown models) This approach is more robust because it: - Doesn't make assumptions about future model naming patterns - Fails fast at initialization for known mismatches - Still provides helpful hints for unknown models on 1008 errors
Summary
This PR improves error messages when users accidentally configure a Gemini API model with VertexAI (or vice versa) in the Google Realtime plugin. Currently, users receive a cryptic WebSocket 1008 policy violation error that doesn't explain the root cause.
Problem
When using the Google Realtime plugin with incorrect model/API combinations:
websockets.exceptions.ConnectionClosedError: received 1008 (policy violation)Example Scenario
A user tries to use VertexAI with a Gemini API model name:
Current error:
After this fix:
Solution
Added a helper function
_get_model_mismatch_hint()that:The hint is appended to both:
APIConnectionErrorexceptionsThis provides immediate, actionable feedback without blocking any valid configurations or making assumptions about future model naming patterns.
Testing
Fixes livekit/livekit#4026
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.