Kimi Coding Plan: tool schema rejected — type should be defined in anyOf items instead of parent
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
- Configure Kimi Coding Plan key:
[providers.moonshot]
api_key = "sk-kimi-..."
auth_mode = "kimi_oauth"
- Switch to
moonshotprovider in TUI - 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.
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.
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.
Clarifying the schema fix literally: Kimi/Moonshot normalization now pushes type into anyOf/oneOf branches before provider submission.