feat(server): forward inbound Anthropic auth - #372
Conversation
Signed-off-by: Elyas Mehtabuddin <emehtabuddin@nvidia.com>
|
WalkthroughThe change adds ChangesAnthropic authentication forwarding
Estimated code review effort: 3 (Moderate) | ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@crates/libsy-llm-client/README.md`:
- Around line 216-220: Update the HttpBackendConfig::forward_auth documentation
to explicitly scope credential and anthropic-beta forwarding behavior to
Anthropic backends, particularly anthropic_messages clients, and clarify that it
does not apply to OpenAI backends.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 40554ecd-43d1-4be7-ac4e-166ad0b5b978
📒 Files selected for processing (8)
crates/libsy-llm-client/README.mdcrates/libsy-llm-client/src/backend.rscrates/libsy-llm-client/src/client.rscrates/switchyard-server/README.mdcrates/switchyard-server/src/config.rscrates/switchyard-server/tests/server.rsdocs/getting_started.mddocs/reference/toml_schema.md
| - `HttpBackendConfig::forward_auth` forwards the caller's `authorization` or | ||
| `x-api-key` header instead of using the backend's configured key. Leave it | ||
| disabled unless the configured upstream should receive each caller's credential. | ||
| It also forwards `oauth-*` markers from `anthropic-beta` while removing other | ||
| caller-supplied beta values. |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Limit this behavior to Anthropic backends.
HttpBackendConfig is shared by OpenAI and Anthropic backends, but forward_auth = true is supported for anthropic_messages clients. As written, this text can imply that OpenAI backends also forward caller credentials.
Proposed wording
-- `HttpBackendConfig::forward_auth` forwards the caller's `authorization` or
+- For an Anthropic backend, `HttpBackendConfig::forward_auth` forwards the caller's `authorization` or
`x-api-key` header instead of using the backend's configured key.📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| - `HttpBackendConfig::forward_auth` forwards the caller's `authorization` or | |
| `x-api-key` header instead of using the backend's configured key. Leave it | |
| disabled unless the configured upstream should receive each caller's credential. | |
| It also forwards `oauth-*` markers from `anthropic-beta` while removing other | |
| caller-supplied beta values. | |
| - For an Anthropic backend, `HttpBackendConfig::forward_auth` forwards the caller's `authorization` or | |
| `x-api-key` header instead of using the backend's configured key. Leave it | |
| disabled unless the configured upstream should receive each caller's credential. | |
| It also forwards `oauth-*` markers from `anthropic-beta` while removing other | |
| caller-supplied beta values. |
🤖 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 `@crates/libsy-llm-client/README.md` around lines 216 - 220, Update the
HttpBackendConfig::forward_auth documentation to explicitly scope credential and
anthropic-beta forwarding behavior to Anthropic backends, particularly
anthropic_messages clients, and clarify that it does not apply to OpenAI
backends.
When Claude Code sends an
Authorizationheader to/v1/messages, Switchyard removes the header before it calls this upstream. The same happens tox-api-key.The regression test records the upstream rejection:
This PR adds an opt-in
forward_auth = truesetting foranthropic_messagesclients. Switchyard then forwards the caller'sAuthorizationorx-api-keyheader instead of usingapi_key_env. Claude subscription OAuth also keepsoauth-*markers fromanthropic-beta; other inbound beta markers remain filtered.forward_authstays disabled by default. Configuration loading rejects it for non-Anthropic clients and rejects competing credentials fromapi_key_envorextra_headers.After enabling the setting,
anthropic_client_forwards_inbound_auth_when_configuredsends requests through/v1/messagesto a local Anthropic stub. The stub returns HTTP 200 for both an OAuth bearer credential and anx-api-key. The test also verifies that Switchyard setsanthropic-versionand removes an unrelated inbound beta marker.Closes #164
Summary by CodeRabbit
New Features
Documentation