-
Notifications
You must be signed in to change notification settings - Fork 746
Description
Bug description
BidiGeminiLiveModel fails with APIError: 1007 Request contains an invalid argument when used with gemini-3.1-flash-live-preview. The connection establishes successfully but the first text input causes the error.
Two root causes
1. _send_text_content uses send_client_content — rejected by Gemini 3.1
_send_text_content unconditionally routes text through send_client_content:
async def _send_text_content(self, text: str) -> None:
content = genai_types.Content(role="user", parts=[genai_types.Part(text=text)])
await self._live_session.send_client_content(turns=content)Gemini 3.1 Flash Live only allows send_client_content for seeding initial context history. Mid-session text must use send_realtime_input(text=...) instead.
This worked with Gemini 2.5 models which accepted send_client_content throughout the session.
Fix: Use send_realtime_input(text=text) for Gemini 3.1+ models.
2. _build_live_config injects session_resumption: {"handle": None}
config_dict["session_resumption"] = {"handle": kwargs.get("live_session_handle")}When no session handle is provided, this sends {"handle": None} to the API. Gemini 3.1 rejects this; 2.5 silently accepted it. The field should be omitted entirely when no handle exists.
3. (Minor) _resolve_client_config defaults to api_version: "v1alpha"
if "http_options" not in resolved:
resolved["http_options"] = {"api_version": "v1alpha"}v1alpha is not a documented Gemini Developer API version. The correct default is v1beta.
Reproduction
from strands.experimental.bidi.models.gemini_live import BidiGeminiLiveModel
from strands.experimental.bidi import BidiAgent
model = BidiGeminiLiveModel(
model_id="gemini-3.1-flash-live-preview",
client_config={"api_key": "<key>", "http_options": {"api_version": "v1beta"}},
)
agent = BidiAgent(model=model, tools=[], system_prompt="Say hello.")
await agent.start()
# Auto-greeting or any BidiTextInputEvent triggers the errorError:
google.genai.errors.APIError: 1007 None. Request contains an invalid argument.
Traceback path: BidiAgent.send(BidiTextInputEvent) → _send_text_content → send_client_content → 1007
Confirmed fix
# send_realtime_input works for text on 3.1
await session.send_realtime_input(text="Hello") # ✅ returns audio
await session.send_client_content(turns=content) # ❌ error 1007Environment
strands-agentsv1.33.0google-genaiv1.69.0- Python 3.14.3
- Model:
gemini-3.1-flash-live-preview
Workaround
Subclass BidiGeminiLiveModel and override _send_text_content and _build_live_config:
class PatchedGeminiLiveModel(BidiGeminiLiveModel):
def _build_live_config(self, system_prompt=None, tools=None, **kwargs):
config = super()._build_live_config(system_prompt, tools, **kwargs)
if config.get("session_resumption") == {"handle": None}:
del config["session_resumption"]
return config
async def _send_text_content(self, text: str) -> None:
await self._live_session.send_realtime_input(text=text)