Skip to content

KIMI K2.6 showing error in Opencode GO #27054

Closed

Description

@sankalp7135

[Bug] API Call Error with Moonshot AI Provider: JSON Schema $defs Mismatch in Tool Parameters

Description

When using the Moonshot AI provider in Agent/Tool mode, OpenCode fails to execute requests and returns a 400 Bad Request error.

The issue appears to stem from JSON Schema compatibility in tool parameter definitions.

Moonshot AI enforces a strict “Moonshot-flavored” JSON schema format where all schema references must use:

#/$defs/

However, OpenCode appears to generate or forward schemas containing references that do not follow this structure. The failure specifically points to:

properties.properties.properties.opacity.items.$ref

Because of this mismatch, the Moonshot API rejects the entire request payload before execution begins.


Steps to Reproduce

  1. Configure the AI provider as Moonshot AI using BYOK/API key.
  2. Enable or use any feature requiring tool/function calling (Composer, Agent mode, file operations, etc.).
  3. Submit any prompt.
  4. The request immediately fails with a streaming/API error.

Expected Behavior

OpenCode should generate tool parameter schemas compatible with the provider’s JSON schema requirements, allowing successful streaming responses and tool execution.


Actual Behavior

The request fails instantly with an invalid_request_error.

Error Response

{
  "error": {
    "message": "Error from provider: Provider returned error",
    "code": 400,
    "metadata": {
      "raw": "{\"error\":{\"message\":\"Invalid request: tools.function.parameters is not a valid moonshot flavored json schema, details: <At path 'properties.properties.properties.opacity.items.$ref': references must start with #/$defs/>\",\"type\":\"invalid_request_error\"}}",
      "provider_name": "Moonshot AI",
      "is_byok": true
    },
    "user_id": "[REDACTED]"
  }
}

Stack Trace

ERROR service=session.processor session.id=ses_1e419eb2cffeCwyOY6Sq1dEzlk
messageID=msg_e1be6151f002F714hecB3vR5wk
error=Error from provider: Provider returned error

stack=AI_APICallError: Error from provider: Provider returned error
    at file:///Applications/OpenCode.app/Contents/Resources/app.asar/out/main/chunks/node-BP-tJ87t.js:124883:14
    at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
    at async postToApi (file:///Applications/OpenCode.app/Contents/Resources/app.asar/out/main/chunks/node-BP-tJ87t.js:124811:28)

Environment

  • OS: macOS
  • Application: OpenCode
  • Provider: Moonshot AI (BYOK)
  • Mode: Agent / Tool Calling

Suggested Fix

Update the internal JSON Schema generator for tool definitions so that all $ref paths use:

#/$defs/

instead of legacy formats such as:

#/definitions/

This change should remain backward-compatible with standard OpenAI-compatible parsers while improving compatibility with stricter schema validators like Moonshot AI.

Potentially affected schemas may include UI/editor-related tool definitions involving properties such as:

opacity.items.$ref

which currently appear to violate Moonshot’s schema validation requirements.

Activity

  1. github-actions commented on May 12, 2026

    @github-actions
    Contributor

    This issue doesn't fully meet our contributing guidelines.

    What needs to be fixed:

    • The issue does not use one of the three required issue templates (Bug Report, Feature Request, or Question)
    • The description appears to be AI-generated — overly polished, structured with a detailed root-cause analysis and suggested fix that reads like AI output rather than a genuine reproduction report. AI-generated walls of text are not acceptable per our guidelines.
    • The title ("KIMI K2.6 showing error in Opencode GO") does not match the detailed body content, suggesting the body was generated separately

    Please edit this issue to address the above within 2 hours, or it will be automatically closed.


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

    If you believe this was flagged incorrectly, please let a maintainer know.

  2. sankalp7135 commented on May 12, 2026

    @sankalp7135
    Author

    The workaround is to disable your MCP and then initiate the session

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs:complianceThis means the issue will auto-close after 2 hours.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions