Skip to content

feat: Anthropic-native provider passthrough mode#4

Open
beardthelion wants to merge 1 commit into
ajsai47:mainfrom
beardthelion:feat/anthropic-native-passthrough
Open

feat: Anthropic-native provider passthrough mode#4
beardthelion wants to merge 1 commit into
ajsai47:mainfrom
beardthelion:feat/anthropic-native-passthrough

Conversation

@beardthelion

Copy link
Copy Markdown

Summary

Adds PROVIDER_API_FORMAT setting (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 via POST /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

File Change
src/proxy/config.py +4 lines — provider_api_format field
src/proxy/client.py +25 lines — stream_anthropic() with retry
src/proxy/routes.py +31 lines — format branch + _stream_passthrough()
.env.example +6 lines — documented config
tests/test_passthrough.py New — 6 tests (raw SSE passthrough, retry, config)

16/16 tests pass. Backward compatible — defaults to "openai", preserving all current behavior.

Dependencies

⚠️ This PR builds on top of the changes in:

It uses _backoff, RETRYABLE_STATUS, and _resolve_model from 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

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

1 participant