Skip to content

fix(deepseek): use native /anthropic/v1/messages endpoint and sanitize tools - #28176

Closed
FelipeRodriguesGare wants to merge 4 commits into
BerriAI:litellm_internal_stagingfrom
FelipeRodriguesGare:chore/deepseek-anthropic
Closed

fix(deepseek): use native /anthropic/v1/messages endpoint and sanitize tools#28176
FelipeRodriguesGare wants to merge 4 commits into
BerriAI:litellm_internal_stagingfrom
FelipeRodriguesGare:chore/deepseek-anthropic

Conversation

@FelipeRodriguesGare

@FelipeRodriguesGare FelipeRodriguesGare commented May 18, 2026

Copy link
Copy Markdown
Contributor

Relevant issues

Linear ticket

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/test_litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

CI (LiteLLM team)

CI status guideline:

  • 50-55 passing tests: main is stable with minor issues.
  • 45-49 passing tests: acceptable but needs attention
  • <= 40 passing tests: unstable; be careful with your merges and assess the risk.
  • Branch creation CI run
    Link:

  • CI run for the last commit
    Link:

  • Merge / cherry-pick CI run
    Links:

Screenshots / Proof of Fix

image image

Type

🆕 New Feature
🐛 Bug Fix

Changes

This PR adds a handler for deepseek anthropic APIs. Deepseek has already an endpoint that is anthropic compatible but the current implementation was fallbacking to the general handler and thus throwing errors for deepseek on claude code.

@CLAassistant

CLAassistant commented May 18, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@greptile-apps

greptile-apps Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds DeepSeekAnthropicMessagesConfig, a thin subclass of AnthropicMessagesConfig, so that LiteLLM routes DeepSeek provider calls through DeepSeek's Anthropic-compatible endpoint (https://api.deepseek.com/anthropic/v1/messages) instead of the generic fallback handler that was causing errors in Claude Code.

  • transformation.py overrides URL construction (normalising various api_base input forms to the canonical /anthropic/v1/messages path), env validation (using DEEPSEEK_API_KEY/DEEPSEEK_ANTHROPIC_API_BASE), and sanitises the {"type":"custom"} tool discriminator that DeepSeek rejects.
  • utils.py adds an unconditional DEEPSEEK branch to get_provider_anthropic_messages_config, consistent with how all other Anthropic-messages providers are registered.
  • __init__.py files and focused unit tests (no network calls) are included.

Confidence Score: 5/5

Safe to merge — the change is additive, isolated to a new DeepSeek config class, and does not touch any existing provider paths.

The implementation cleanly extends the established Anthropic messages config pattern without modifying existing provider logic. URL normalisation covers all documented input forms (verified by the accompanying tests), the tool-sanitisation path is narrow and well-tested, and the utils.py routing change mirrors the identical pattern already in place for Minimax, Bedrock, Vertex AI, and Azure AI. No auth path, no DB access, no backwards-incompatible change.

No files require special attention.

Important Files Changed

Filename Overview
litellm/llms/deepseek/messages/transformation.py New DeepSeekAnthropicMessagesConfig class that subclasses AnthropicMessagesConfig; overrides URL construction, env validation, and sanitizes the "custom" tool type discriminator that DeepSeek rejects.
litellm/utils.py Adds a new elif branch to get_provider_anthropic_messages_config to route DEEPSEEK provider calls to DeepSeekAnthropicMessagesConfig, consistent with the pattern used for all other providers.
tests/test_litellm/llms/deepseek/messages/test_deepseek_anthropic_messages_transformation.py Unit tests for URL building, header construction, provider routing, and tool sanitization — all purely local with no network calls.

Reviews (3): Last reviewed commit: "chore(deepseek): add test package marker..." | Re-trigger Greptile

Comment thread litellm/llms/deepseek/messages/transformation.py Outdated
@codecov

codecov Bot commented May 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.42857% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/llms/deepseek/messages/transformation.py 96.22% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@oss-pr-review-agent-shin

Copy link
Copy Markdown
Contributor

🤖 litellm-agent: This PR is currently BLOCKED from merge.

Score: 2/5

Why blocked:

  • 1 PR-related CI failure (lint) (pr_related_failures, -2 pts)
  • 1 unresolved reviewer concern (greptile) (unresolved_concern, -1 pts)

Details: Score docked for: 1 PR-related CI failure (lint); 1 unresolved reviewer concern (greptile).

Fix the issues above and push an update — the bot will re-review automatically.

Note: This bot is still in beta and might not always work as expected. Please share any feedback via Slack.

@FelipeRodriguesGare

Copy link
Copy Markdown
Contributor Author

@greptileai

@oss-pr-review-agent-shin

Copy link
Copy Markdown
Contributor

🤖 litellm-agent: This PR is currently BLOCKED from merge.

Score: 4/5

Why blocked:

  • 1 unresolved reviewer concern (greptile) (unresolved_concern, -1 pts)

Details: Score docked for: 1 unresolved reviewer concern (greptile).

Fix the issues above and push an update — the bot will re-review automatically.

Note: This bot is still in beta and might not always work as expected. Please share any feedback via Slack.

@FelipeRodriguesGare

Copy link
Copy Markdown
Contributor Author

@greptileai

@milan-berri milan-berri changed the title Chore/deepseek anthropic fix(deepseek): use native /anthropic/v1/messages endpoint and sanitize tools May 18, 2026
Add a DeepSeek-specific Anthropic Messages config so deepseek/... models use the native messages endpoint and preserve thinking blocks. Strip Anthropic custom tool type markers that DeepSeek rejects while keeping hosted tool types intact.
Handle OpenAI-style DeepSeek api_base values ending in /v1 or /v1/messages by stripping those suffixes before adding the /anthropic messages path.
@mateo-berri

Copy link
Copy Markdown
Contributor

This has been merged. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants