feat: Anthropic-native provider passthrough mode#4
Open
beardthelion wants to merge 1 commit into
Open
Conversation
Adds PROVIDER_API_FORMAT setting (default 'openai') to support providers that speak Anthropic's native Messages API without translation. When set to 'anthropic', Claude Code requests are relayed to the provider untouched via POST /messages — no content block mapping, no SSE conversion, no stop reason translation. All Backdoor features (retry, housekeeping mocking, background model routing, health check) still apply. Includes: - stream_anthropic() in ProviderClient with retry support - Format branch in create_message route - Passthrough stream helper with error handling - Tests for raw line passthrough, retry, and config - Updated .env.example Note: depends on PR ajsai47#1 (retry), PR ajsai47#2 (background routing), PR ajsai47#3 (tool_choice fix)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
PROVIDER_API_FORMATsetting (default"openai") to support providers that speak Anthropic's native Messages API — no translation needed.When set to
"anthropic", Claude Code requests are relayed to the provider untouched viaPOST /messages. No content block mapping, no SSE format conversion, no stop reason translation. All existing Backdoor features (retry, housekeeping mocking, background model routing, health check) still apply.Why
Backdoor currently only supports OpenAI-compatible providers. Every request goes through a bidirectional translation layer. But some providers (vLLM, OpenCode Go, OpenRouter Anthropic endpoints) already speak Anthropic's native API. For those, the translation layer is unnecessary overhead and can introduce bugs (wrong stop reasons, dropped cache_control, broken tool call serialization).
With this, Backdoor becomes a universal proxy — work with any provider in either format.
Changes
src/proxy/config.pyprovider_api_formatfieldsrc/proxy/client.pystream_anthropic()with retrysrc/proxy/routes.py_stream_passthrough().env.exampletests/test_passthrough.py16/16 tests pass. Backward compatible — defaults to
"openai", preserving all current behavior.Dependencies
It uses
_backoff,RETRYABLE_STATUS, and_resolve_modelfrom those PRs.Example
# .env — point at an Anthropic-native provider PROVIDER_API_FORMAT=anthropic PROVIDER_BASE_URL=https://opencode-go.example.com/v1 PROVIDER_API_KEY=sk-xxx PROVIDER_MODEL=qwen-3.7-max