Gemini 3+/4 tool calls fail via @ai-sdk/openai-compatible: thought_signature dropped on replay
Summary
When a Gemini 3+/4 model is used through a custom @ai-sdk/openai-compatible provider (for example a LiteLLM proxy) whose provider id is not google, the thought_signature returned with a tool call is lost when the history is replayed. The next request then fails with:
Function call is missing a thought_signature in functionCall parts ... function call `default_api:read`
INVALID_ARGUMENT
Every tool call followed by another turn fails, so Gemini 3+/4 is unusable for tool calling through this setup.
Environment
- Kilo CLI 7.8.27 (macOS, arm64)
- Provider: custom id
litellm,npm: "@ai-sdk/openai-compatible",baseURL: http://localhost:4000/v1(LiteLLM proxy) - Models:
gemini-3.8-flashandgemini-4-argon(Vertex Gemini behind LiteLLM)
Evidence
- The proxy returns the signature on the streamed tool call:
tool_calls[0].extra_content.google.thought_signature = "AY89a19..." - Kilo captures it. In the compiled CLI the openai-compatible chat model stores it as
providerMetadata[<providerOptionsName>].thoughtSignature.providerOptionsNameis derived from the provider id, so the key islitellm. - On replay, the openai-compatible message converter reads it back from the hardcoded key
providerOptions.google.thoughtSignature:case "tool-call": { let h = f.providerOptions?.google?.thoughtSignature; p.push({ id, type: "function", function: {...}, ...(h ? { extra_content: { google: { thought_signature: String(h) } } } : {}) }) normalizeMessagesinpackages/opencode/src/provider/transform.tsonly remaps stored provider keys whensdkKey(model.api.npm)returns a key.sdkKey("@ai-sdk/openai-compatible")returnsundefined, so no remap happens andproviderOptions.litellm.thoughtSignatureis never moved toproviderOptions.google.- Reproduced with a real session, with the proxy logging what it receives:
kilo run -m litellm/gemini-3.8-flash "Use the read tool to read a.txt ..."The replayed assistant tool call reached the proxy with no signature (incoming_sig=False). A direct request to the proxy containing the same history without a signature returns the 400 above. The same history with a signature (or Google's dummyskip_thought_signature_validator) succeeds.
Expected
The signature round-trips: stored under the provider key, then written back as extra_content.google.thought_signature on replay, regardless of the provider id.
Suggested fix
Either of these:
- In the openai-compatible converter, read the signature from the provider's own options key (
providerOptionsName) as well asgoogle. - In
normalizeMessages, for@ai-sdk/openai-compatible, copythoughtSignaturefromproviderOptions[model.providerID]toproviderOptions.googlebefore conversion.
A regression test could replay a tool-call message with providerOptions: { <customProviderId>: { thoughtSignature } } through an openai-compatible model and assert extra_content.google.thought_signature is present in the request body.
Workaround
A LiteLLM async_pre_call_hook that injects extra_content.google.thought_signature = "skip_thought_signature_validator" on assistant tool calls that lack one. This unblocks tool calling but the model no longer receives its real reasoning signature across tool turns.
Related
#6018, #4639 (same error message, native Google provider path).
I'd like to take this one. From the issue, the stored signature lands under providerOptions.litellm.thoughtSignature while the openai-compatible converter only reads providerOptions.google.thoughtSignature, and normalizeMessages in packages/opencode/src/provider/transform.ts has no remap because sdkKey returns undefined for @ai-sdk/openai-compatible. My plan is to remap the custom provider's key to google for tool-call parts in that path, limited to the case where a signature is present, so other openai-compatible providers are unaffected. I'll add a unit test in the transform tests that replays a tool call stored under a non-google provider id and asserts extra_content.google.thought_signature is emitted. I'll follow the AI-assistance section of the contributing guide and will have run and reviewed the change myself before requesting review.