[Bug] Numeric enum values not stringified for Gemini API #8881

Open
opened 2026-02-16 18:11:05 -05:00 by yindo · 2 comments
Owner

Originally created by @nxxxsooo on GitHub (Feb 9, 2026).

Originally assigned to: @rekram1-node on GitHub.

Bug Description

When using Gemini models (gemini-3-pro-preview, gemini-2.5-flash, etc.), OpenCode sends numeric enum values in tool schemas as numbers instead of strings, causing 400 Bad Request errors from the Gemini API.

Error Message

Invalid value at 'tools[0].function_declarations[59].parameters.properties[1].value.enum[0]' (TYPE_STRING), 1
Invalid value at 'tools[0].function_declarations[59].parameters.properties[1].value.enum[1]' (TYPE_STRING), 2
Invalid value at 'tools[0].function_declarations[59].parameters.properties[1].value.enum[2]' (TYPE_STRING), 3
...

Root Cause

Gemini API requires all enum values to be strings. When OpenCode has numeric enum values like [0, 1, 2, 3, 4], they must be converted to ["0", "1", "2", "3", "4"] before sending to Gemini.

Environment

  • OpenCode version: Latest (as of Feb 2026)
  • OS: macOS
  • Model: google/gemini-3-pro-preview, google/gemini-2.5-flash

Reproduction Steps

  1. Configure OpenCode to use a direct Google AI Studio API key
  2. Try to use any Gemini model with tool calling
  3. Observe 400 Bad Request errors with the above message

Expected Behavior

Numeric enum values should be automatically stringified when sending tool schemas to Gemini API.

Notes

  • This bug exists in OpenCode core, not in plugins like opencode-antigravity-auth
  • Issue was confirmed by disabling all plugins and testing with direct Google API connection
Originally created by @nxxxsooo on GitHub (Feb 9, 2026). Originally assigned to: @rekram1-node on GitHub. ## Bug Description When using Gemini models (gemini-3-pro-preview, gemini-2.5-flash, etc.), OpenCode sends numeric enum values in tool schemas as numbers instead of strings, causing 400 Bad Request errors from the Gemini API. ## Error Message ``` Invalid value at 'tools[0].function_declarations[59].parameters.properties[1].value.enum[0]' (TYPE_STRING), 1 Invalid value at 'tools[0].function_declarations[59].parameters.properties[1].value.enum[1]' (TYPE_STRING), 2 Invalid value at 'tools[0].function_declarations[59].parameters.properties[1].value.enum[2]' (TYPE_STRING), 3 ... ``` ## Root Cause Gemini API requires all enum values to be strings. When OpenCode has numeric enum values like `[0, 1, 2, 3, 4]`, they must be converted to `["0", "1", "2", "3", "4"]` before sending to Gemini. ## Environment - OpenCode version: Latest (as of Feb 2026) - OS: macOS - Model: google/gemini-3-pro-preview, google/gemini-2.5-flash ## Reproduction Steps 1. Configure OpenCode to use a direct Google AI Studio API key 2. Try to use any Gemini model with tool calling 3. Observe 400 Bad Request errors with the above message ## Expected Behavior Numeric enum values should be automatically stringified when sending tool schemas to Gemini API. ## Notes - This bug exists in OpenCode core, not in plugins like opencode-antigravity-auth - Issue was confirmed by disabling all plugins and testing with direct Google API connection
Author
Owner

@github-actions[bot] commented on GitHub (Feb 9, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #11413: "question" tool schema causes "400 Bad Request" with Gemini/Vertex AI - Related to schema compatibility issues with Gemini API
  • #12295: Gemini API rejects JSON Schema containing $ref references - Another Gemini schema serialization issue
  • #9233: LiteLLM Proxy: Vertex AI Gemini models fail for tools with empty parameters - Related to tool schema formatting for Gemini

These issues all involve Gemini API's strict schema validation requirements. Your numeric enum issue may be part of a broader pattern of Gemini schema serialization problems.

Feel free to ignore if your specific case differs from these.

@github-actions[bot] commented on GitHub (Feb 9, 2026): This issue might be a duplicate of existing issues. Please check: - #11413: "question" tool schema causes "400 Bad Request" with Gemini/Vertex AI - Related to schema compatibility issues with Gemini API - #12295: Gemini API rejects JSON Schema containing $ref references - Another Gemini schema serialization issue - #9233: LiteLLM Proxy: Vertex AI Gemini models fail for tools with empty parameters - Related to tool schema formatting for Gemini These issues all involve Gemini API's strict schema validation requirements. Your numeric enum issue may be part of a broader pattern of Gemini schema serialization problems. Feel free to ignore if your specific case differs from these.
Author
Owner

@rekram1-node commented on GitHub (Feb 9, 2026):

are u sure they should be converted to strings? What tool are u using that can handle that? Why not just drop enum and send it as a number field?

@rekram1-node commented on GitHub (Feb 9, 2026): are u sure they should be converted to strings? What tool are u using that can handle that? Why not just drop enum and send it as a number field?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8881