fix(deepseek): use native /anthropic/v1/messages endpoint and sanitize tools - #28176
Conversation
Greptile SummaryThis PR adds
Confidence Score: 5/5Safe 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.
|
| 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
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
🤖 litellm-agent: This PR is currently BLOCKED from merge. Score: 2/5 ❌ Why blocked:
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.
|
|
🤖 litellm-agent: This PR is currently BLOCKED from merge. Score: 4/5 ❌ Why blocked:
Details: Score docked for: 1 unresolved reviewer concern (greptile). Fix the issues above and push an update — the bot will re-review automatically.
|
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.
689cf82 to
b2a6ce7
Compare
|
This has been merged. Thank you! |
Relevant issues
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/test_litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewDelays 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)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Screenshots / Proof of Fix
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.