Skip to content

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

Closed

Description

@nxxxsooo

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

Activity

  1. github-actions commented on Feb 9, 2026

    @github-actions
    Contributor

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

    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.

  2. added a commit that references this issue on Feb 9, 2026
    97dff40
  3. rekram1-node commented on Feb 9, 2026

    @rekram1-node
    Collaborator

    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?

  4. github-actions commented on Apr 11, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions