feat(llmcore): support api_key_header override for NativeClaudeSession - #751
Open
ZYDMYHZ wants to merge 1 commit into
Open
feat(llmcore): support api_key_header override for NativeClaudeSession#751ZYDMYHZ wants to merge 1 commit into
ZYDMYHZ wants to merge 1 commit into
Conversation
NativeClaudeSession now reads an optional 'api_key_header' config field
('auto' | 'x-api-key' | 'bearer'). Default 'auto' keeps existing behavior:
sk-ant- keys -> x-api-key header, others -> Authorization: Bearer.
This lets non-sk-ant- channels that expose an Anthropic /v1/messages
endpoint (e.g. opencode.ai) use x-api-key auth, so the full native Claude
protocol works there. Adds a mykey_template.py example (1b' section)
documenting the new field.
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.
Problem
NativeClaudeSession.raw_askchose the auth header purely by key prefix:sk-ant-keys →x-api-key, everything else →Authorization: Bearer.Channels that expose a full Anthropic
/v1/messagesendpoint but issuenon-
sk-ant-keys (e.g. opencode.ai'shttps://opencode.ai/zen/go/v1)were broken: the client sent
Bearer, the endpoint replied401 Missing API key, so the native Claude protocol (tools loop, thinking,context_management) could not be used against those relays.
Change
Add an optional
api_key_headerconfig field toNativeClaudeSession:auto(default) — existing behavior unchanged(
sk-ant-→x-api-key, otherwiseBearer)x-api-key— force thex-api-keyheaderbearer— forceAuthorization: BearerAlso documents the new field in
mykey_template.py(new 1b' exampletargeting an opencode.ai-style channel).
Testing
NativeClaudeSession+api_key_header='x-api-key'+https://opencode.ai/zen/go/v1→ HTTP 200, full native protocol reply.auto(sk-Gq key →Bearer→/chat/completions)still returns HTTP 200, unchanged behavior.