Skip to content

fix: uses anthropic endpoints in chat completion and responses in deepseek - #5176

Merged
akshaydeo merged 2 commits into
devfrom
07-14-fix_uses_anthropic_endpoints_in_chat_completion_and_responses_in_deepseek
Jul 18, 2026
Merged

akshaydeo merged 2 commits into
devfrom
07-14-fix_uses_anthropic_endpoints_in_chat_completion_and_responses_in_deepseek

Conversation

@sammaji

@sammaji sammaji commented Jul 14, 2026 •

Copy link
Copy Markdown
Member

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
  • Feature
  • Refactor
  • Documentation
  • Chore/CI

Affected areas

  • Core (Go)
  • Transports (HTTP)
  • Providers/Integrations
  • Plugins
  • UI (React)
  • Docs

How to test

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

  • 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

  • I read docs/contributing/README.md and followed the guidelines
  • I added/updated tests where appropriate
  • I updated documentation where needed
  • I verified builds succeed (Go and UI)
  • I verified the CI pipeline passes locally if applicable

@coderabbitai

coderabbitai Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

DeepSeek 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.

Changes

DeepSeek Anthropic compatibility

Layer / File(s) Summary
Anthropic provider routing
core/providers/deepseek/deepseek.go, core/providers/anthropic/...
DeepSeek chat and responses methods use Anthropic handlers, x-api-key authentication, /anthropic/v1/messages, streaming settings, request defaults, and feature flags.
Forced-tool thinking compatibility
core/providers/anthropic/chat.go, core/providers/anthropic/responses.go, plugins/compat/conversion.go
Forced DeepSeek tool choices disable thinking in Anthropic and OpenAI-compatible request handling, while the previous responses conversion override is removed.
Routing and tool-call validation
core/providers/deepseek/deepseek_anthropic_test.go, core/providers/deepseek/deepseek_test.go
Tests validate Anthropic and OpenAI endpoint routing, authentication, web search preservation, forced-tool thinking behavior, and multi-tool calling including streaming.

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
Loading

Possibly related PRs

  • maximhq/bifrost#5065: Both modify DeepSeek forced-tool handling during ResponsesRequest parameter conversion.
  • maximhq/bifrost#5208: Both add or validate DeepSeek routing through the Anthropic-compatible /anthropic/v1/messages endpoint.
  • maximhq/bifrost#5305: Both use shared Anthropic endpoint resolution and Anthropic-compatible request routing.

Suggested reviewers: akshaydeo, tejasghatte, danpiths, pratham-mishra04, roroghost17

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.77% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly states the main change: switching DeepSeek chat and responses to Anthropic endpoints.
Description check ✅ Passed The description matches the template well and covers summary, changes, testing, breaking changes, security, and checklist items.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 07-14-fix_uses_anthropic_endpoints_in_chat_completion_and_responses_in_deepseek

Comment @coderabbitai help to get the list of available commands.

@sammaji
sammaji marked this pull request as ready for review July 14, 2026 08:05
Copilot AI review requested due to automatic review settings July 14, 2026 08:05

sammaji commented Jul 14, 2026 •

Copy link
Copy Markdown
Member Author

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@greptile-apps

greptile-apps Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5

This is close, but the raw request path should be fixed before merging.

  • Typed DeepSeek requests now handle forced tool choice with thinking.
  • Raw Anthropic-compatible bodies can still bypass that handling.
  • A raw forced-tool request can still be rejected by DeepSeek.

core/providers/anthropic/requestbuilder.go

Important Files Changed

Filename Overview
core/providers/deepseek/deepseek.go Adds Anthropic endpoint routing for DeepSeek while preserving the OpenAI fallback path.
core/providers/anthropic/chat.go Adds typed DeepSeek thinking suppression for pinned tool choices, while raw bodies still bypass it.
core/providers/anthropic/responses.go Adds matching typed DeepSeek thinking suppression for responses requests.
core/providers/anthropic/requestbuilder.go Registers DeepSeek defaults and keeps the raw-body path separate from typed conversion.
core/providers/anthropic/types.go Adds an explicit DeepSeek capability entry for Anthropic request shaping.
plugins/compat/conversion.go Removes DeepSeek-specific thinking mutation from compat conversion.
core/providers/deepseek/deepseek_anthropic_test.go Adds local tests for DeepSeek Anthropic endpoint routing, auth, tools, and typed thinking suppression.
core/providers/deepseek/deepseek_test.go Enables multiple tool-call coverage for DeepSeek provider scenarios.

Reviews (12): Last reviewed commit: "fix: use anthropic endpoints in chat com..." | Re-trigger Greptile

Comment thread core/providers/deepseek/deepseek.go Outdated
Comment thread core/providers/deepseek/deepseek.go
Comment thread plugins/compat/conversion.go
Comment thread core/providers/deepseek/deepseek.go Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
core/providers/deepseek/deepseek_anthropic_test.go (1)

50-283: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Solid new coverage; consider extending to streaming paths.

These tests are clear and deterministic. Since ChatCompletionStream/ResponsesStream route through separate Anthropic streaming handlers (with their own providerName/header-filtering wiring), consider adding equivalent streaming test cases — this would have caught the providerName divergence noted on deepseek.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

📥 Commits

Reviewing files that changed from the base of the PR and between ddc26fb and cda389d.

📒 Files selected for processing (4)
  • core/providers/deepseek/deepseek.go
  • core/providers/deepseek/deepseek_anthropic_test.go
  • core/providers/deepseek/deepseek_test.go
  • plugins/compat/conversion.go
💤 Files with no reviewable changes (1)
  • plugins/compat/conversion.go

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 14, 2026
@sammaji
sammaji force-pushed the 07-14-fix_uses_anthropic_endpoints_in_chat_completion_and_responses_in_deepseek branch from cda389d to 46eed16 Compare July 14, 2026 12:08
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 14, 2026
Comment thread plugins/compat/conversion.go
@sammaji
sammaji force-pushed the 07-14-fix_uses_anthropic_endpoints_in_chat_completion_and_responses_in_deepseek branch from 46eed16 to 215f151 Compare July 14, 2026 19:44
@CLAassistant

CLAassistant commented Jul 14, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Comment thread core/providers/anthropic/chat.go
@sammaji
sammaji force-pushed the 07-14-fix_uses_anthropic_endpoints_in_chat_completion_and_responses_in_deepseek branch from 215f151 to 7fe0b4e Compare July 14, 2026 19:49
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 14, 2026
@sammaji
sammaji force-pushed the 07-14-fix_uses_anthropic_endpoints_in_chat_completion_and_responses_in_deepseek branch from 7fe0b4e to 5692d79 Compare July 16, 2026 11:06
Comment thread core/providers/anthropic/requestbuilder.go
@sammaji
sammaji changed the base branch from 07-16-fix_moves_vllm_to_native_responses_api to graphite-base/5176 July 17, 2026 14:53
@sammaji
sammaji force-pushed the graphite-base/5176 branch from cbedc82 to 9be779a Compare July 17, 2026 14:54
@sammaji
sammaji force-pushed the 07-14-fix_uses_anthropic_endpoints_in_chat_completion_and_responses_in_deepseek branch from 1422dfc to 68d4683 Compare July 17, 2026 14:54
@sammaji
sammaji changed the base branch from graphite-base/5176 to 07-16-fix_adds_sgl_anthropic_compatible_apis_via_key_level_setting July 17, 2026 14:54
@sammaji
sammaji force-pushed the 07-16-fix_adds_sgl_anthropic_compatible_apis_via_key_level_setting branch from 9be779a to d660a54 Compare July 17, 2026 19:09
@sammaji
sammaji force-pushed the 07-14-fix_uses_anthropic_endpoints_in_chat_completion_and_responses_in_deepseek branch from 68d4683 to 491ce5e Compare July 17, 2026 19:09
@sammaji
sammaji force-pushed the 07-14-fix_uses_anthropic_endpoints_in_chat_completion_and_responses_in_deepseek branch from 491ce5e to e6b494b Compare July 18, 2026 04:19
@sammaji
sammaji force-pushed the 07-16-fix_adds_sgl_anthropic_compatible_apis_via_key_level_setting branch from d660a54 to 2af938f Compare July 18, 2026 04:19
Comment thread core/providers/anthropic/chat.go
akshaydeo
akshaydeo previously approved these changes Jul 18, 2026

akshaydeo commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Merge activity

  • Jul 18, 4:02 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jul 18, 4:03 PM UTC: @akshaydeo merged this pull request with Graphite.

@akshaydeo
akshaydeo changed the base branch from 07-16-fix_adds_sgl_anthropic_compatible_apis_via_key_level_setting to graphite-base/5176 July 18, 2026 16:02
@akshaydeo
akshaydeo changed the base branch from graphite-base/5176 to dev July 18, 2026 16:02
@akshaydeo
akshaydeo dismissed stale reviews from coderabbitai[bot] and themself July 18, 2026 16:02

The base branch was changed.

@akshaydeo
akshaydeo merged commit 78dc353 into dev Jul 18, 2026
10 of 11 checks passed
@akshaydeo
akshaydeo deleted the 07-14-fix_uses_anthropic_endpoints_in_chat_completion_and_responses_in_deepseek branch July 18, 2026 16:03
@coderabbitai coderabbitai Bot mentioned this pull request Jul 27, 2026
18 tasks
akhsaul pushed a commit to akhsaul/bifrost that referenced this pull request Aug 27, 2026
…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
occcat pushed a commit to occcat/bifrost that referenced this pull request Sep 2, 2026
…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
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.

4 participants