Skip to content

feat(llmcore): support api_key_header override for NativeClaudeSession - #751

Open
ZYDMYHZ wants to merge 1 commit into
lsdefine:mainfrom
ZYDMYHZ:feat/api-key-header
Open

feat(llmcore): support api_key_header override for NativeClaudeSession#751
ZYDMYHZ wants to merge 1 commit into
lsdefine:mainfrom
ZYDMYHZ:feat/api-key-header

Conversation

@ZYDMYHZ

@ZYDMYHZ ZYDMYHZ commented Aug 9, 2026

Copy link
Copy Markdown

Problem

NativeClaudeSession.raw_ask chose the auth header purely by key prefix:
sk-ant- keys → x-api-key, everything else → Authorization: Bearer.

Channels that expose a full Anthropic /v1/messages endpoint but issue
non-sk-ant- keys
(e.g. opencode.ai's https://opencode.ai/zen/go/v1)
were broken: the client sent Bearer, the endpoint replied
401 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_header config field to NativeClaudeSession:

  • auto (default) — existing behavior unchanged
    (sk-ant-x-api-key, otherwise Bearer)
  • x-api-key — force the x-api-key header
  • bearer — force Authorization: Bearer

Also documents the new field in mykey_template.py (new 1b' example
targeting an opencode.ai-style channel).

Testing

  • New path: NativeClaudeSession + api_key_header='x-api-key' +
    https://opencode.ai/zen/go/v1 → HTTP 200, full native protocol reply.
  • Regression: default auto (sk-Gq key → Bearer/chat/completions)
    still returns HTTP 200, unchanged behavior.

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

2 participants