Tool Calling Specification Violation on Moonshot API

Hi.

I’m one of the developers of the tool calling implementation for Kilocode. The Kimi models are popular, and K2-Thinking seems very strong and popular.

However, I note that the inference implementation that moonshot AI uses for K2-Thinking does not follow the tool calling specification, and is breaking function calls.

Specifically, the OpenAI API specification notes that the definitions must follow the JSON Schema document. That document defines boolean as a valid type.

However, when sending a request to the moonshot ai API endpoints that includes a tool definition with boolean, the API responds with an error that the scalar type boolean is not permitted.

Beyond that, “null” is rejected as a type, despite that also being explicitly permitted.) in the specification.

Are you aware of these bugs? If so, is there a timeline to correct it?

Thank you very much for your feedback. As soon as we received your issue, we started troubleshooting, and the problem has been resolved at present.
Please try again, and if the problem still exists, please provide us with detailed input and output feedback to help us further resolve the issue. Thank you.

Thanks for the quick response. the tool definition parsing appears to be fixed.

1 Like

Similar to OpenAI, we provided limited support for JSON Schema. Some features, such as referencing external network resources, are restricted due to engineering and interpretability considerations.

Here, we recommend using our walle project to verify our support for features.

You can install this tool using

go install github.com/moonshotai/walle/cmd/walle@latest

and then

walle -schema '{"type": "object"}' -level strict

or

walle -schema-file your_schema.json

to check if our service fully supports this definition.

Hope it helps.

1 Like

I believe your colleague above fixed it last night.

Last night, the parser was rejecting this, for example:

{
“type”: “object”,
“properties”: {
“mode_slug”: {
“type”: “string”,
“description”: “Slug of the mode to switch to (e.g., code, ask, architect)”
},
“reason”: {
“type”: [
“string”,
“null”
],
“description”: “Explanation for why the mode switch is needed”
}
},
“required”: [
“mode_slug”,
“reason”
],
“additionalProperties”: false
}

Despite the fact that walle validates it. It was rejecting the “null” as a type option.

Hi mcowger,

Thank you for your update. However, our team was unable to reproduce the original issue with the schema you provided (the one with "type": ["string", "null"]).

To help us verify the fix is complete and prevent future regressions, could you please share a complete, minimal chat completions request that previously failed? For example, a curl command like this:

curl https://api.moonshot.ai/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $MOONSHOT_API_KEY" \
  -d '{
    "model": "kimi-k2-thinking-turbo",
    "messages": [{"role": "user", "content": "test"}],
    "tools": [{
      "type": "function",
      "function": {
        "name": "switch_mode",
        "parameters": {
          "type": "object",
          "properties": {
            "mode_slug": {"type": "string"},
            "reason": {"type": ["string", "null"]}
          },
          "required": ["mode_slug", "reason"]
        }
      }
    }]
  }'

Please include:

  • The exact endpoint URL
  • The specific model ID you were using
  • The full tool definition that triggered the error

:warning: Important: Remember to remove your API key before sharing.

This will help us ensure we’ve fully resolved the issue. Thanks again for your help!