Skip to content

[Bug] OpenCode Go: Kimi K2.6 rejects tool schemas with if/then/else conditionals #31580

Closed as not planned

Description

@josegil1909

[Bug] OpenCode Go: Kimi K2.6 rejects tool schemas with if/then/else conditionals

Description

OpenCode Go does not transform tool schemas for Moonshot AI models (kimi-k2.6, kimi-k2.5), causing 400 Bad Request errors when any client sends standard OpenAI-compatible tool definitions that contain conditional schemas.

The error occurs at the Moonshot API validation layer before the request reaches the model.

Environment

  • Provider: OpenCode Go (https://opencode.ai/zen/go/v1)
  • Model: kimi-k2.6 (also kimi-k2.5)
  • Client: pi (earendil-works/pi) v0.79.1 via litellm 1.85.0
  • API mode: chat_completions

Error Message

400 litellm.BadRequestError: OpenAIException - Error from provider: 
Conflict in schema definitions for key 'if'. 
Previous: {'required': ['expand']}, New: {'required': ['collect']}

The error is wrapped by the Vercel AI SDK as AI_APICallError: Error from provider: Provider returned error in some clients (see #23665).

Root Cause

Moonshot AI's JSON Schema validator is stricter than standard OpenAI:

  • It does not accept if/then/else conditional schemas in tool definitions
  • It does not accept description after $ref expansion
  • It does not accept properties.variantOptions patterns
  • It expects a "moonshot flavored JSON schema" (quoted from their error messages)

Comparison with Other Models (Same Provider)

Model OpenCode Go Tool Schemas Status
deepseek-v4-pro ✅ ✅ Works perfectly
glm-5.1 ✅ ✅ Works perfectly
qwen3.5-plus ✅ ✅ Works perfectly
minimax-m2.5 ✅ ✅ Works perfectly
kimi-k2.6 ✅ ❌ Fails with 400
kimi-k2.5 ✅ ❌ Fails with 400

Expected Behavior

OpenCode Go should transform or sanitize tool schemas for Kimi models before forwarding to Moonshot AI, similar to how it handles thinking/reasoning mode conversions (see #5169 fix).

Suggested Fix

  1. Provider-side schema normalization: When model starts with kimi-*, transform the incoming OpenAI tool schemas to Moonshot-compatible format:

    • Remove if/then/else blocks (flatten to anyOf/oneOf if possible)
    • Remove description after $ref
    • Strip variantOptions patterns
    • Simplify nested required arrays
  2. Or: Document the limitation and provide a client-side workaround option

Related Issues

Additional Context

  • This is not the same as the previous thinking-mode issue. That was fixed by pi (client side). This requires server-side schema transformation.
  • litellm's drop_params: true does not help because the issue is in the JSON Schema structure, not in parameters.
  • The error is deterministic — it happens on every tool request with kimi-k2.6/k2.5.

Activity

  1. github-actions commented on Jun 10, 2026

    @github-actions
    Contributor

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

    If your issue is specifically about if/then/else conditional schemas being rejected and not covered by the above, feel free to clarify how it differs so it can be tracked separately.

  2. github-actions commented on Aug 9, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 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