Skip to content

[Bug]: Cannot use claude-code + LiteLLM with openai models #17904

@talalryz

Description

@talalryz

What happened?

Problem

When using LiteLLM's Anthropic-compatible /v1/messages endpoint to route requests to OpenAI models (like GPT-4,
GPT-5.2), requests fail with a ContextWindowExceededError if any tool name exceeds OpenAI's 64-character limit for function names.

This commonly occurs when using Claude Code or other Anthropic clients that define tools with long descriptive
names (e.g., computer_tool_with_very_long_name_that_exceeds_openai_64_character_limit).

Error Message

litellm.ContextWindowExceededError: litellm.BadRequestError: ContextWindowExceededError: OpenAIException - Invalid
'tools[24].function.name': string too long. Expected a string with maximum length 64, but got a string with length
90 instead.

Root Cause

The Anthropic API does not have the same 64-character restriction on tool names that OpenAI enforces. When LiteLLM's Anthropic adapter translates requests from Anthropic format to OpenAI format, it passes tool names through unchanged, causing OpenAI to reject requests with long tool names.

Expected Behavior

LiteLLM should automatically truncate tool names that exceed 64 characters when translating Anthropic requests to OpenAI format, and restore the original names when translating responses back to Anthropic format.

Proposed Solution

  1. When translating Anthropic tools to OpenAI format, truncate any tool name > 64 chars using a deterministic
    format like {55-char-prefix}_{8-char-hash} to avoid collisions
  2. Store a mapping of truncated → original names
  3. When translating OpenAI responses back to Anthropic format, restore the original tool names using the mapping
  4. Handle this for both streaming and non-streaming responses

Reproduction Steps

  1. Configure LiteLLM proxy with an OpenAI model accessible via the Anthropic /v1/messages endpoint
  2. Send a request with a tool that has a name longer than 64 characters
  3. Observe the ContextWindowExceededError

Environment

  • LiteLLM version: v1.80.9-nightly
  • Python version: 3.13
  • Target model: Any OpenAI model (gpt-4, gpt-5.2, etc.)

Relevant log output

Are you a ML Ops Team?

Yes

What LiteLLM version are you on ?

v1.80.9-nightly

Twitter / LinkedIn details

No response

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