Repository navigation
Description
[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
- Configure the AI provider as Moonshot AI using BYOK/API key.
- Enable or use any feature requiring tool/function calling (Composer, Agent mode, file operations, etc.).
- Submit any prompt.
- 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
github-actions commentedon May 12, 2026
This issue doesn't fully meet our contributing guidelines.
What needs to be fixed:
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:
invalid moonshot flavored json schemaerror classtools.function.parameters is not a valid moonshot flavored json schemaerrorIf you believe this was flagged incorrectly, please let a maintainer know.
sankalp7135 commentedon May 12, 2026
The workaround is to disable your MCP and then initiate the session