CodeWhale icon indicating copy to clipboard operation
CodeWhale copied to clipboard

Kimi Coding Plan: tool schema rejected — type should be defined in anyOf items instead of parent

Open A-Corner opened this issue 6 months ago • 3 comments

Description

When using the moonshot provider with a Kimi Coding Plan API key (prefix sk-kimi-), every request fails with HTTP 400:

{"error":{"message":"tools.function.parameters is not a valid moonshot flavored json schema, details: <At path root: when using anyOf, type should be defined in anyOf items instead of the parent schema>","type":"invalid_request_error"}}

Root Cause

CodeWhale generates tool function schemas where type is placed at the root level alongside anyOf:

{
  "type": "object",
  "anyOf": [
    {"properties": {...}},
    {"properties": {...}}
  ]
}

Kimi's API (both https://api.kimi.com/coding/v1 and the standard Moonshot endpoint) enforces stricter JSON Schema validation and requires type to be inside each anyOf item:

{
  "anyOf": [
    {"type": "object", "properties": {...}},
    {"type": "object", "properties": {...}}
  ]
}

Reproduction

  1. Configure Kimi Coding Plan key:
[providers.moonshot]
api_key = "sk-kimi-..."
auth_mode = "kimi_oauth"
  1. Switch to moonshot provider in TUI
  2. Send any message (even "hi") — fails immediately because tool definitions are always sent with requests

The issue affects ALL providers when pointing at Kimi's API (tested with moonshot, vllm). Plain curl without tools works fine.

Environment

  • CodeWhale v0.8.47
  • Kimi Coding Plan API: https://api.kimi.com/coding/v1
  • Model: kimi-for-coding (Kimi-k2.6)

Relevant Code

The tool schema generation logic likely lives in the tool registry or LLM client layer. The fix would need to move type declarations from the parent schema level into each anyOf/oneOf item for Kimi/Moonshot compatibility.

Note

z.ai / GLM Coding Plan (via openai provider) works fine — they accept the current schema format. The issue is Kimi-specific strictness.

A-Corner avatar May 31 '26 14:05 A-Corner

Thanks @A-Corner — this is a very helpful repro because it names the exact provider path, key flavor, model, and schema validation error. I do not see this fixed by the recent model/provider merges, so I am leaving it open as a focused Kimi/Moonshot tool-schema compatibility bug.

The likely next step is a provider-scoped schema normalization pass that rewrites root anyOf/oneOf object schemas into the stricter shape Kimi expects, with a regression test around a tool schema that currently fails. The note that z.ai accepts the current schema is useful too; we should keep this targeted so we do not accidentally loosen working providers.

Hmbown avatar May 31 '26 20:05 Hmbown

Fixed on main for v0.8.49. Kimi/Moonshot schema normalization now pushes into / branches before provider submission (bea701c6a), with nested regression coverage in dde865453. Thanks @A-Corner for the original report and @idling11 for the PR.

Hmbown avatar Jun 01 '26 09:06 Hmbown

Clarifying the schema fix literally: Kimi/Moonshot normalization now pushes type into anyOf/oneOf branches before provider submission.

Hmbown avatar Jun 01 '26 09:06 Hmbown