Repository navigation
[BUG]: Gemini 3 Pro function calling fails - missing thoughtSignature support #4832
Description
[BUG]: Gemini 3 Pro function calling fails - missing thoughtSignature support
Description
When using Gemini 3 Pro models (gemini-3-pro-preview) with function calling/tool use, requests fail with error:
Unable to submit request because function call `default_api:webfetch` in the 4. content block is missing a `thought_signature`.
Root Cause
Gemini 3 Pro requires thoughtSignature to be preserved and passed back during multi-step function calling. This is a mandatory validation introduced in Gemini 3 (unlike Gemini 2.5 where it was optional).
How Gemini 3 Thought Signatures Work
- When model responds with a
functionCall, it includes athoughtSignaturefield - Client MUST preserve this signature and include it in the next request when sending
functionResponse - If signature is missing → API returns 400 error
Reference: https://ai.google.dev/gemini-api/docs/thought-signatures
Expected Flow
Turn 1, Step 1:
Request: user_prompt
Response: functionCall + thoughtSignature
Turn 1, Step 2:
Request: user_prompt + (functionCall + thoughtSignature) + functionResponse ← signature MUST be here
Response: text_output or another functionCall + signature
Current Behavior in OpenCode
OpenCode does not preserve thoughtSignature from Gemini API responses when building subsequent requests in conversation history.
The contents array in requests to Gemini API is missing the thoughtSignature field in functionCall parts.
Affected Models
gemini-3-pro-preview(mandatory - will error)gemini-2.5-pro/gemini-2.5-flash(optional but recommended for reasoning quality)
Proposed Fix
Option 1: Preserve thoughtSignature in Message History
When storing model responses that contain functionCall parts, also store the thoughtSignature field. When building the next request, include the signature in the corresponding content part:
{
"contents": [
{
"role": "model",
"parts": [
{
"functionCall": { "name": "webfetch", "args": {...} },
"thoughtSignature": "<preserved_signature>" // ← Add this
}
]
}
]
}Option 2: Dummy Signature Workaround
According to Google's documentation, for cases where signatures cannot be preserved (e.g., transferring from another model), you can use dummy signatures:
"skip_thought_signature_validator"
or
"context_engineering_is_the_way_to_go"
This skips validation but may degrade reasoning quality.
Steps to Reproduce
- Configure opencode with Gemini 3 Pro (
gemini-3-pro-preview) - Ask a question that triggers tool/function calling (e.g., web search, file operations)
- When model makes a function call and receives response, the next request fails
Environment
- OpenCode version: latest
- Model:
gemini-3-pro-preview - Provider: Google AI / Vertex AI
Additional Context
- This issue affects any multi-step agentic workflow with Gemini 3
- The Gemini CLI and official Google Gen AI SDKs handle this automatically via chat history management
- OpenCode's custom provider/plugin architecture needs to explicitly handle this
Activity
github-actions commentedon Nov 27, 2025
This issue might be a duplicate of existing issues. Please check:
ids were found withouttool_result` blocks #4802: "tool_useids were found withouttool_resultblocks" - Related to tool use/function calling message structure issues across multiple modelsBoth issues indicate problems with how OpenCode handles function calling/tool use responses from LLM providers, which is the core issue described here regarding
thoughtSignaturehandling.Feel free to ignore if none of these address your specific case.
rekram1-node commentedon Nov 29, 2025
I can't replicate issue with your reproduction steps
andreigiura commentedon Dec 2, 2025
@rekram1-node i think this happens when using gemini 3 pro with openrouter
rekram1-node commentedon Dec 2, 2025
what version of OC are you using
s16173760 commentedon Dec 7, 2025
I suggest using this method first. langgenius/dify-official-plugins#2120
andreigiura commentedon Dec 10, 2025
@rekram1-node i am using the latest version 1.0.141. The error i get is:
{"code":400,"message":"Provider returned error","type":null,"param":null,"metadata":{"raw":"{\n "error": {\n "code": 400,\n "message": "Corrupted thought signature.",\n "status": "INVALID_ARGUMENT"\n }\n}\n","provider_name":"Google AI Studio"}}
rekram1-node commentedon Dec 10, 2025
@andreigiura under what circumstances? Any reproduction steps?
andreigiura commentedon Dec 10, 2025
@rekram1-node i have tried to build a hello world app. then tried to enhence its design. it builds the hello world with react for example, but at some point it fails and never recover. just need to work with it a little bit in order to reproduce it. it only happes on openrouter provider, not directly with google gemini
rekram1-node commentedon Dec 10, 2025
Oh well that makes sense then
rekram1-node commentedon Dec 10, 2025
OpenRouter just did some bug fixes for their provider and I merged their fix in today. it will be in next release
matthewijordan commentedon Dec 15, 2025
@rekram1-node have you got a link to the changes? I've just jumped to the latest release and I'm still seeing this issue
rekram1-node commentedon Dec 15, 2025
@matthewijordan you are encountering issues with gemini specifically through openrouter? Can you explain steps to reproduce?
rekram1-node commentedon Dec 15, 2025
here is one of the last fixes they did:
OpenRouterTeam/ai-sdk-provider#288
ramarivera commentedon Dec 23, 2025
Not sure if related at all, but when using Zen + Gemini 3 Pro I get
on every request 🤔
Not sure where logs would get stored, but lemme know if I can provide more info?
8 remaining items
jakobbjelver commentedon Feb 18, 2026
I am also getting the same error. Version 1.2.6 with Google Gemini Pro and Flash using OpenRouter. No external plugins or anything, vanilla OpenCode config.
This is what I can see from the logs:
{ "error": { "code": 400, "message": "Unable to submit request because Thought signature is not valid.. Learn more: https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/gemini", "status": "INVALID_ARGUMENT" } }Anyone got an update on this? Seems it should have been fixed?
VitorNaidek commentedon Feb 24, 2026
I am also receiving this error when using gemini-3-flash-preview through the ollama cloud. I did not encounter the same issue with other ollama models.
BrianJM commentedon Feb 24, 2026
I am also receiving the same issue with Gemini models on OpenRouter.
nguyenvulong commentedon Mar 17, 2026
Same problem with Google Vertex AI with Gemini 3.1 Pro Preview
I just used very few
skillsfrom Claude. No other additional plugins were used.CCRcmcpe commentedon Mar 25, 2026
Same issue with Vertex Gemini 3.1 Pro Preview on clean opencode installation
gintasz commentedon Apr 15, 2026
Same issue, still getting a whole bunch of random thought signature errors on opencode 1.4.3, at least 20 times today, gemini 3.1 pro preview on openrouter.
czln commentedon May 4, 2026
Still having the same issue at latest version1.14.33. I'm using gemini over my own proxy on my server, which I believe all content has been routed to the gemini server. I myself would not change the json content.
rekram1-node commentedon May 4, 2026
openrouter sdk had bugs we updated sdk recently.
For ur custom one kinda need more info for ur proxy
czln commentedon May 11, 2026
@rekram1-node
well, it's a really simple proxy. I can just paste part of my source code here:
the content of http request would never be changed
rmbusddollar commentedon May 11, 2026
Have this been fixed?
rekram1-node commentedon May 11, 2026
if ur still having the issue send me a session u got it in?
opencode export > session.jsonreview prompt: friendly green callouts + per-section severity emojis …
cyberfox1 commentedon Aug 12, 2026
Still get this issue, latest version of opencode and 3.5 flash.
rekram1-node commentedon Aug 12, 2026
@cyberfox1 As the msg above states, plz:
if ur still having the issue send me a session u got it in? opencode export > session.json
cyberfox1 commentedon Aug 12, 2026
I looked into this a bit more it seems my provider had switched from google to openai-compatible, switching it back to google resolved it.