fix(google_genai): strip id from FunctionCall/FunctionResponse wire format#1582
Merged
RealKai42 merged 3 commits intoMoonshotAI:mainfrom Mar 25, 2026
Merged
Conversation
… format Gemini API returns HTTP 400 when `id` is included in `function_call` or `function_response` parts. Unlike OpenAI, Gemini uses positional matching rather than explicit IDs to pair calls with responses. Remove `id=tool_call.id` from `FunctionCall()` and `id=message.tool_call_id` from `FunctionResponse()` in the outbound message conversion. The internal kosong `tool_call_id` tracking is unchanged; only the wire format sent to Gemini is affected. Add a dedicated test asserting neither field appears in the request body.
Signed-off-by: Kai <me@kaiyi.cool>
x5iu
pushed a commit
to x5iu/kimi-cli
that referenced
this pull request
Mar 25, 2026
… format (MoonshotAI#1582) Signed-off-by: Kai <me@kaiyi.cool> Co-authored-by: Kai <me@kaiyi.cool>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issue
N/A — discovered through manual testing with Gemini models via third-party proxy endpoints.
Description
Gemini API returns HTTP 400 when
idis included inFunctionCallorFunctionResponseparts of the request body. This causes all Gemini models to crash after the first tool call — the first step succeeds, but the second step (which replays the conversation history containing function_call withid) is rejected by the API.Root Cause
message_to_google_genai()and_tool_message_to_function_response_part()passedid=...toFunctionCall()/FunctionResponse()constructors. Thegoogle-genaiSDK accepts the kwarg, but the Gemini REST API rejects it on the wire:Gemini matches function calls to responses by array position, not by
id(unlike OpenAI). The internaltool_call_idtracking in kosong'sMessageobjects is unaffected — only the outbound wire format changes.Fix
Remove
id=...fromFunctionCallandFunctionResponseconstructors (2 lines). The SDK'smodel_dump(exclude_none=True)serialization automatically omitsNonefields, so theidkey no longer appears in the wire JSON.Manual Verification
Tested on a machine with 6 Gemini model configurations through qianxun proxy:
gemini-3-pro-previewgemini-2.5-progemini-2.5-flashgemini-3-flash-previewgemini-3-progemini-3-flashChecklist
make gen-changelogto update the changelog.