Skip to content

fix(adapter): ensure root object type for Kimi tool schemas - #250

Merged
lidge-jun merged 1 commit into
lidge-jun:devfrom
Wibias:codex/fix-kimi-tool-schema
Jul 22, 2026
Merged

lidge-jun merged 1 commit into
lidge-jun:devfrom
Wibias:codex/fix-kimi-tool-schema

Conversation

@Wibias

@Wibias Wibias commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Problem

Issue #228: Kimi returns HTTP 400 when a Codex tool schema has no root type: "object". The error is tools.function.parameters.type is required and must be "object".

Codex tools like automation_update use valid JSON Schema with a root oneOf and no explicit root type. OpenCodex forwards that schema unchanged to Kimi's OpenAI-compatible function format. Kimi requires function.parameters.type to be exactly "object", so it rejects the complete request before the model can call the tool.

Root cause

In src/adapters/openai-chat.ts, toolsToChatFormat() passes t.parameters through unchanged for Kimi. There are already provider-specific schema paths for xAI and Zen, but Kimi currently uses the unmodified path.

Fix

Add provider-scoped normalization for api.kimi.com that ensures type: "object" at the root while preserving oneOf, $defs, descriptions, and other schema keys. Similar to the existing xAI and Zen schema handling.

Verification

  • bun x tsc --noEmit passes
  • The fix is a 28-line addition to src/adapters/openai-chat.ts
  • The reporter confirmed this approach works locally with both the minimized reproduction and the full automation_update schema

Kimi requires function.parameters.type to be exactly 'object' at the root.
Codex tools with oneOf/anyOf schemas (like automation_update) omit the root
type, causing 400 errors: 'tools.function.parameters.type is required and
must be object'.

Add provider-scoped normalization for api.kimi.com that ensures type: 'object'
at the root while preserving oneOf, \, descriptions, and other schema keys.
Similar to the existing xAI and Zen schema handling.

Fixes #228
@lidge-jun
lidge-jun merged commit 38f3789 into lidge-jun:dev Jul 22, 2026
8 checks passed
@Wibias
Wibias deleted the codex/fix-kimi-tool-schema branch July 25, 2026 07:00
agentHits pushed a commit to agentHits/opencodex that referenced this pull request Sep 17, 2026
…n#250)

fix(adapter): ensure root object type for Kimi tool schemas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants