fix: uses anthropic endpoints in chat completion and responses in deepseek - #5176
Conversation
📝 WalkthroughWalkthroughDeepSeek chat and responses operations now support Anthropic-compatible routing alongside OpenAI-compatible fallbacks. The changes add authentication, streaming configuration, feature metadata, forced-tool thinking suppression, and tests for routing, web search, tool choices, and multi-tool calls. ChangesDeepSeek Anthropic compatibility
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant DeepSeekProvider
participant AnthropicHandlers
participant DeepSeekAPI
Client->>DeepSeekProvider: Send chat or responses request
DeepSeekProvider->>AnthropicHandlers: Convert and build Anthropic messages request
DeepSeekProvider->>DeepSeekAPI: POST /anthropic/v1/messages with x-api-key
DeepSeekAPI-->>AnthropicHandlers: Return Anthropic response
AnthropicHandlers-->>Client: Return normalized completion or responses result
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Confidence Score: 4/5This is close, but the raw request path should be fixed before merging.
core/providers/anthropic/requestbuilder.go Important Files Changed
Reviews (12): Last reviewed commit: "fix: use anthropic endpoints in chat com..." | Re-trigger Greptile |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
core/providers/deepseek/deepseek_anthropic_test.go (1)
50-283: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winSolid new coverage; consider extending to streaming paths.
These tests are clear and deterministic. Since
ChatCompletionStream/ResponsesStreamroute through separate Anthropic streaming handlers (with their ownproviderName/header-filtering wiring), consider adding equivalent streaming test cases — this would have caught theproviderNamedivergence noted ondeepseek.go.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@core/providers/deepseek/deepseek_anthropic_test.go` around lines 50 - 283, Extend the DeepSeek Anthropic coverage with equivalent tests for ChatCompletionStream and ResponsesStream, using the existing httptest setup patterns in TestChatCompletion_UsesAnthropicEndpoint and TestResponses_UsesAnthropicEndpointAndKeepsWebSearch. Assert the streaming requests use /anthropic/v1/messages and x-api-key, and verify streamed responses succeed; include tool preservation where applicable to cover the separate streaming handlers’ providerName and header-filtering paths.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@core/providers/deepseek/deepseek_anthropic_test.go`:
- Around line 50-283: Extend the DeepSeek Anthropic coverage with equivalent
tests for ChatCompletionStream and ResponsesStream, using the existing httptest
setup patterns in TestChatCompletion_UsesAnthropicEndpoint and
TestResponses_UsesAnthropicEndpointAndKeepsWebSearch. Assert the streaming
requests use /anthropic/v1/messages and x-api-key, and verify streamed responses
succeed; include tool preservation where applicable to cover the separate
streaming handlers’ providerName and header-filtering paths.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: b246dad0-681f-4183-ad45-0a8a466b449e
📒 Files selected for processing (4)
core/providers/deepseek/deepseek.gocore/providers/deepseek/deepseek_anthropic_test.gocore/providers/deepseek/deepseek_test.goplugins/compat/conversion.go
💤 Files with no reviewable changes (1)
- plugins/compat/conversion.go
cda389d to
46eed16
Compare
46eed16 to
215f151
Compare
215f151 to
7fe0b4e
Compare
7fe0b4e to
5692d79
Compare
cbedc82 to
9be779a
Compare
1422dfc to
68d4683
Compare
9be779a to
d660a54
Compare
68d4683 to
491ce5e
Compare
491ce5e to
e6b494b
Compare
d660a54 to
2af938f
Compare
Merge activity
|
The base branch was changed.
…pseek (maximhq#5176) ## Summary The DeepSeek provider previously used OpenAI-compatible endpoints for all requests. DeepSeek exposes an Anthropic-compatible API at `/anthropic/v1/messages` that supports richer features (extended thinking, native tool handling, web search, etc.). This PR migrates the DeepSeek provider to use that Anthropic-compatible endpoint, enabling proper thinking/tool-choice handling and multiple tool calls. ## Changes - Replaced all OpenAI handler calls (`HandleOpenAIChatCompletionRequest`, `HandleOpenAIChatCompletionStreaming`) in the DeepSeek provider with their Anthropic equivalents (`HandleAnthropicChatCompletionRequest`, `HandleAnthropicChatCompletionStreaming`, `HandleAnthropicResponsesRequest`, `HandleAnthropicResponsesStream`). - Updated the request path from `/chat/completions` to `/anthropic/v1/messages` and switched authentication from a Bearer token header to `x-api-key`. - The `Responses` and `ResponsesStream` methods now call Anthropic handlers directly instead of delegating to `ChatCompletion`/`ChatCompletionStream` with a fallback conversion flag. - Moved the `disableThinkingWithToolChoice` logic out of the compat plugin and into the Anthropic request builder, which already handles this concern natively for Anthropic-compatible providers. The compat plugin no longer needs to special-case DeepSeek for thinking suppression. - Enabled `MultipleToolCalls` in the DeepSeek integration test suite, as the Anthropic-compatible endpoint supports this correctly. - Added `deepseek_anthropic_test.go` with unit tests that spin up a local HTTP server to verify: the correct endpoint and `x-api-key` header are used, web search tools are preserved in the outbound body, and thinking is disabled when a forced tool choice is present (for both chat and responses APIs). ## Type of change - [ ] Bug fix - [x] Feature - [x] Refactor - [ ] Documentation - [ ] Chore/CI ## Affected areas - [x] Core (Go) - [ ] Transports (HTTP) - [x] Providers/Integrations - [x] Plugins - [ ] UI (React) - [ ] Docs ## How to test ```sh go test ./core/providers/deepseek/... go test ./plugins/compat/... go test ./... ``` The new `deepseek_anthropic_test.go` tests use `httptest.NewServer` and require no external credentials. They verify: - `ChatCompletion` and `Responses` route to `/anthropic/v1/messages` with `x-api-key` authentication. - Web search tools are forwarded correctly in the outbound request body. - Forced tool choice causes `thinking: {type: disabled}` to be set in the outbound body for both chat and responses requests. ## Breaking changes - [x] Yes - [ ] No DeepSeek requests are now sent to the `/anthropic/v1/messages` endpoint instead of `/chat/completions`. Any custom `BaseURL` configurations that pointed to an OpenAI-compatible DeepSeek endpoint will need to be updated to point to a host that serves the Anthropic-compatible API. The `BifrostContextKeyPassthroughExtraParams` and `BifrostContextKeyIsResponsesToChatCompletionFallback` context flags are no longer set by the DeepSeek provider. ## Related issues N/A ## Security considerations Authentication now uses `x-api-key` instead of a `Bearer` token. The key value handling is unchanged — it is read from `schemas.Key` and never logged. ## Checklist - [x] I read `docs/contributing/README.md` and followed the guidelines - [x] I added/updated tests where appropriate - [x] I updated documentation where needed - [x] I verified builds succeed (Go and UI) - [x] I verified the CI pipeline passes locally if applicable
…pseek (maximhq#5176) ## Summary The DeepSeek provider previously used OpenAI-compatible endpoints for all requests. DeepSeek exposes an Anthropic-compatible API at `/anthropic/v1/messages` that supports richer features (extended thinking, native tool handling, web search, etc.). This PR migrates the DeepSeek provider to use that Anthropic-compatible endpoint, enabling proper thinking/tool-choice handling and multiple tool calls. ## Changes - Replaced all OpenAI handler calls (`HandleOpenAIChatCompletionRequest`, `HandleOpenAIChatCompletionStreaming`) in the DeepSeek provider with their Anthropic equivalents (`HandleAnthropicChatCompletionRequest`, `HandleAnthropicChatCompletionStreaming`, `HandleAnthropicResponsesRequest`, `HandleAnthropicResponsesStream`). - Updated the request path from `/chat/completions` to `/anthropic/v1/messages` and switched authentication from a Bearer token header to `x-api-key`. - The `Responses` and `ResponsesStream` methods now call Anthropic handlers directly instead of delegating to `ChatCompletion`/`ChatCompletionStream` with a fallback conversion flag. - Moved the `disableThinkingWithToolChoice` logic out of the compat plugin and into the Anthropic request builder, which already handles this concern natively for Anthropic-compatible providers. The compat plugin no longer needs to special-case DeepSeek for thinking suppression. - Enabled `MultipleToolCalls` in the DeepSeek integration test suite, as the Anthropic-compatible endpoint supports this correctly. - Added `deepseek_anthropic_test.go` with unit tests that spin up a local HTTP server to verify: the correct endpoint and `x-api-key` header are used, web search tools are preserved in the outbound body, and thinking is disabled when a forced tool choice is present (for both chat and responses APIs). ## Type of change - [ ] Bug fix - [x] Feature - [x] Refactor - [ ] Documentation - [ ] Chore/CI ## Affected areas - [x] Core (Go) - [ ] Transports (HTTP) - [x] Providers/Integrations - [x] Plugins - [ ] UI (React) - [ ] Docs ## How to test ```sh go test ./core/providers/deepseek/... go test ./plugins/compat/... go test ./... ``` The new `deepseek_anthropic_test.go` tests use `httptest.NewServer` and require no external credentials. They verify: - `ChatCompletion` and `Responses` route to `/anthropic/v1/messages` with `x-api-key` authentication. - Web search tools are forwarded correctly in the outbound request body. - Forced tool choice causes `thinking: {type: disabled}` to be set in the outbound body for both chat and responses requests. ## Breaking changes - [x] Yes - [ ] No DeepSeek requests are now sent to the `/anthropic/v1/messages` endpoint instead of `/chat/completions`. Any custom `BaseURL` configurations that pointed to an OpenAI-compatible DeepSeek endpoint will need to be updated to point to a host that serves the Anthropic-compatible API. The `BifrostContextKeyPassthroughExtraParams` and `BifrostContextKeyIsResponsesToChatCompletionFallback` context flags are no longer set by the DeepSeek provider. ## Related issues N/A ## Security considerations Authentication now uses `x-api-key` instead of a `Bearer` token. The key value handling is unchanged — it is read from `schemas.Key` and never logged. ## Checklist - [x] I read `docs/contributing/README.md` and followed the guidelines - [x] I added/updated tests where appropriate - [x] I updated documentation where needed - [x] I verified builds succeed (Go and UI) - [x] I verified the CI pipeline passes locally if applicable

Summary
The DeepSeek provider previously used OpenAI-compatible endpoints for all requests. DeepSeek exposes an Anthropic-compatible API at
/anthropic/v1/messagesthat supports richer features (extended thinking, native tool handling, web search, etc.). This PR migrates the DeepSeek provider to use that Anthropic-compatible endpoint, enabling proper thinking/tool-choice handling and multiple tool calls.Changes
HandleOpenAIChatCompletionRequest,HandleOpenAIChatCompletionStreaming) in the DeepSeek provider with their Anthropic equivalents (HandleAnthropicChatCompletionRequest,HandleAnthropicChatCompletionStreaming,HandleAnthropicResponsesRequest,HandleAnthropicResponsesStream)./chat/completionsto/anthropic/v1/messagesand switched authentication from a Bearer token header tox-api-key.ResponsesandResponsesStreammethods now call Anthropic handlers directly instead of delegating toChatCompletion/ChatCompletionStreamwith a fallback conversion flag.disableThinkingWithToolChoicelogic out of the compat plugin and into the Anthropic request builder, which already handles this concern natively for Anthropic-compatible providers. The compat plugin no longer needs to special-case DeepSeek for thinking suppression.MultipleToolCallsin the DeepSeek integration test suite, as the Anthropic-compatible endpoint supports this correctly.deepseek_anthropic_test.gowith unit tests that spin up a local HTTP server to verify: the correct endpoint andx-api-keyheader are used, web search tools are preserved in the outbound body, and thinking is disabled when a forced tool choice is present (for both chat and responses APIs).Type of change
Affected areas
How to test
The new
deepseek_anthropic_test.gotests usehttptest.NewServerand require no external credentials. They verify:ChatCompletionandResponsesroute to/anthropic/v1/messageswithx-api-keyauthentication.thinking: {type: disabled}to be set in the outbound body for both chat and responses requests.Breaking changes
DeepSeek requests are now sent to the
/anthropic/v1/messagesendpoint instead of/chat/completions. Any customBaseURLconfigurations that pointed to an OpenAI-compatible DeepSeek endpoint will need to be updated to point to a host that serves the Anthropic-compatible API. TheBifrostContextKeyPassthroughExtraParamsandBifrostContextKeyIsResponsesToChatCompletionFallbackcontext flags are no longer set by the DeepSeek provider.Related issues
N/A
Security considerations
Authentication now uses
x-api-keyinstead of aBearertoken. The key value handling is unchanged — it is read fromschemas.Keyand never logged.Checklist
docs/contributing/README.mdand followed the guidelines