Conversation
Routing gateways in front of a model API sometimes require extra HTTP headers (e.g. opencode Zen/Go answers 400 MissingSessionID on /responses without x-opencode-session). This carries operator-defined headers from [llm] config through the runtime and selector into the OpenAI chat and responses adapters. Adapter-managed framing (Authorization/Content-Type/Accept) always wins. Covered by offline tests.
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 operator-defined
extra_headersfor OpenAI-family text providers(
openaichat-completions andopenai_responses), plumbed from[llm]config through the runtime (
LlmRuntimeConfig) and selector(
ProviderConfig/ProviderBuildContext) into request headers.Adapter-managed framing (
Authorization/Content-Type/Accept)always wins; the merge is case-insensitive.
Motivation (verified against a live gateway)
The opencode Zen/Go gateway requires
x-opencode-sessionon/responsesand answers
400 MissingSessionIDwithout it:{"type":"error","error":{"type":"MissingSessionID","message":"Error from provider (Console Go): Request is missing x-opencode-session and cannot be routed efficiently."}}OpenSquilla had no way to send custom headers — no CLI flag, no schema
field (
headersexists only onMemoryEmbeddingRemoteConfig) — so anymodel behind such a gateway was unusable through it. Verified live with
curl: same key + endpoint + model fails without the header and succeedswith it. After this change (plus the header in config),
opensquilla agentcompletes against that gateway.
Usage
Never store secrets in
extra_headers;Authorizationcannot beoverridden through it. CLI wizard / Web UI fields for this are intentionally
left out to keep this change small — happy to follow up if wanted.
Tests
tests/test_provider_extra_headers.py: 10 offline tests(MockTransport wire assertions for both adapters including
list_models,reserved-header protection, selector plumbing, config parsing). 10/10 pass.
ruff checkclean on all touched files.test_provider_openai_responses+test_provider_selector(56 passed),test_provider_stream_contract+test_gateway_config_default_provider(43 passed).suite includes live tests — leaving those to CI).
Linked Issues: None