Skip to content

fix: expose actual Kimi/Moonshot API errors and resolve \$ref schema - #23667

Closed
SOUMITRO-SAHA wants to merge 1 commit into
anomalyco:devfrom
SOUMITRO-SAHA:fix/issue-23665-kimi-provider-error
Closed

SOUMITRO-SAHA wants to merge 1 commit into
anomalyco:devfrom
SOUMITRO-SAHA:fix/issue-23665-kimi-provider-error

Conversation

@SOUMITRO-SAHA

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #23665

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

This PR fixes two issues with Kimi K2.6 (and other Moonshot models) when used with OpenCode Go:

  1. Error message issue: When the upstream API (Kimi/Moonshot) returns an error, the Vercel AI SDK wraps it with a generic "Provider returned error" message, hiding the actual error details. The fix extracts the real error from error.metadata.raw in packages/opencode/src/provider/error.ts.

  2. Schema validation issue: Moonshot/Kimi APIs reject JSON schemas that have $ref with additional keywords (like description) that conflict after $ref expansion. The fix resolves $ref inline before sending the schema to the API in packages/opencode/src/provider/transform.ts.

How did you verify your code works?

  • Applied the fix locally
  • Tested with Kimi K2.6 model
  • Confirmed error messages now show actual upstream error details instead of "Provider returned error"
  • Confirmed tool calls work without schema validation errors

Screenshots / recordings

2026-04-21.15-44-50.mp4

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

conflicts

- Extract actual error from metadata.raw when Vercel AI SDK wraps errors
- Resolve \$ref inline for Moonshot/Kimi to prevent conflicting keywords
  error

Fixes anomalyco#23665
@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Provider returned error" hides actual Kimi/Moonshot API errors | Opencode GO | kimi k2.6

1 participant