Skip to content

fix: Anthropic via LiteLLM/proxies rejects requests with tool history but no tools param #8246

@seilk

Description

@seilk

When using Anthropic/Claude models via LiteLLM-based proxies (e.g., custom gateways), requests fail with:
UnsupportedParamsError: Anthropic doesn't support tool calling without tools= param specified
This happens when:

  1. Message history contains previous tool calls (tool-call / tool-result)
  2. Current request has no tools (e.g., compaction, title generation)

Root Cause

LiteLLM validates that if message history contains tool calls, the tools parameter must be present. Anthropic's native API now handles this gracefully, but many users route through LiteLLM proxies which enforce stricter validation.

Proposed Solution

Add a dummy tool when:

  • Model is Anthropic/Claude (checked via providerID, api.id, or api.npm)
  • Message history contains tool-call or tool-result
  • No tools are provided (tools is empty)
    The dummy tool is excluded from activeTools so LLM won't actually call it.

Reproduction

curl -X POST "https://your-litellm-gateway" \
  -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "model_name_for_claude",
    "messages": [
      {"role": "user", "content": "What is 2+2?"},
      {"role": "assistant", "content": null, "tool_calls": [{"id": "call_123", "type": "function", "function": {"name": "calc", "arguments": "{}"}}]},
      {"role": "tool", "tool_call_id": "call_123", "content": "4"},
      {"role": "assistant", "content": "The answer is 4."},
      {"role": "user", "content": "Thanks!"}
    ]
  }'
# Returns 400: UnsupportedParamsError

Relates to

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions