diff --git a/astrbot/core/provider/sources/openai_source.py b/astrbot/core/provider/sources/openai_source.py index 6848c5d43a..48a6e222f7 100644 --- a/astrbot/core/provider/sources/openai_source.py +++ b/astrbot/core/provider/sources/openai_source.py @@ -307,6 +307,14 @@ async def _query_stream( state = ChatCompletionStreamState() async for chunk in stream: + # Fix for #6661: Add missing 'index' field to tool_call deltas + # Gemini and some OpenAI-compatible proxies omit this field + if chunk.choices: + for choice in chunk.choices: + if choice.delta and choice.delta.tool_calls: + for idx, tc in enumerate(choice.delta.tool_calls): + if not hasattr(tc, "index") or tc.index is None: + tc.index = idx try: state.handle_chunk(chunk) except Exception as e: