Skip to content

API Error 400: Invalid tool_use.id format when switching from Kimi K2 thinking to Anthropic/Opus #964

@acoliver

Description

@acoliver

Description

When switching from Kimi K2 thinking model to Anthropic/Opus and then posting a prompt, an API error occurs.

Error Message

✕ [API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.4.content.0.tool_use.id: String should match pattern '^[a-zA-Z0-9_-]+$'"},"request_id":"req_011CWe1EvaWj2nvLhrxW8LtM"} (Status: 400)]

Steps to Reproduce

  1. Start a conversation using Kimi K2 thinking model
  2. Switch to Anthropic/Opus model
  3. Post a prompt
  4. Observe the API error

Expected Behavior

The prompt should be processed successfully after switching models.

Actual Behavior

API returns a 400 error indicating the tool_use.id field contains invalid characters (doesn't match pattern ^[a-zA-Z0-9_-]+$).

Root Cause Hypothesis

The tool_use.id generated by Kimi K2 thinking model likely contains characters that are not compatible with Anthropic's API validation (which only allows alphanumeric characters, underscores, and hyphens). When the conversation history is sent to Anthropic after the model switch, these invalid IDs cause the request to fail.

Suggested Fix

Sanitize or regenerate tool_use.id values when switching between providers to ensure compatibility with each provider's validation requirements.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions