-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Description
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
- 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 - Store a mapping of truncated → original names
- When translating OpenAI responses back to Anthropic format, restore the original tool names using the mapping
- Handle this for both streaming and non-streaming responses
Reproduction Steps
- Configure LiteLLM proxy with an OpenAI model accessible via the Anthropic /v1/messages endpoint
- Send a request with a tool that has a name longer than 64 characters
- 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