feat(llm): custom request headers for OpenAI-compatible endpoints via LLM_EXTRA_HEADERS - #936
Merged
Merged
Conversation
… LLM_EXTRA_HEADERS
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Contributor
Greptile SummaryAdds configurable custom HTTP headers for LLM requests.
Confidence Score: 5/5The PR appears safe to merge. The previously reported native OpenAI path now registers a header-bearing client regardless of whether a custom API base is configured, and no blocking failure remains. Important Files Changed
Reviews (2): Last reviewed commit: "fix(llm): apply LLM_EXTRA_HEADERS on nat..." | Re-trigger Greptile |
Contributor
Author
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 a generic
LLM_EXTRA_HEADERSknob so Strix can talk to OpenAI-compatiblegateways that require extra HTTP headers (attribution / tenant routing / etc.)
on top of the bearer token. Today Strix exposes
STRIX_LLM/LLM_API_KEY/LLM_API_BASEbut has no way to send arbitrary request headers, so such gatewaysare unreachable.
LLM_EXTRA_HEADERSis a JSON object applied to every LLM request, e.g.:What changed
LlmSettings.extra_headers: dict[str, str] | Nonebound toLLM_EXTRA_HEADERS(pydantic-settings JSON-decodes the env value).
configure_sdk_model_defaultsnow calls_configure_extra_headers(llm), whichinjects the headers on both routing paths so it works regardless of the
STRIX_LLMprefix:litellm/…, and any non-openai/provider) — merged intolitellm.headers(same mechanism the existing OpenRouter attribution uses).openai/…) — a defaultAsyncOpenAIclient carryingdefault_headersis registered viaset_default_openai_client.base_urldefaults to the real OpenAI endpoint when no custom
LLM_API_BASEis set.No behavior change when
LLM_EXTRA_HEADERSis unset (guarded by the early return).The bearer token still comes from
LLM_API_KEY; TLS is unchanged (use the standardSSL_CERT_FILEfor private CAs).Tests
New
tests/test_llm_extra_headers.py:extra_headers.litellm.headers(LiteLLM route).default_headers— both witha custom base and against the default OpenAI endpoint.
litellm.headersuntouched (no regression).Also validated end-to-end against a local mock OpenAI-compatible gateway that
rejects requests missing the header (401): headers arrive on both routes, with
tool-calling and streaming responses passing through correctly.
Docs
docs/advanced/configuration.mdx— newLLM_EXTRA_HEADERSparam.docs/llm-providers/local.mdx— "Gateways that require custom headers" example.Link to Devin session: https://app.devin.ai/sessions/54414ea3ecb34ade9189534e5c690969
Requested by: @0xallam