feat(config): extra HTTP headers for LLM API calls (#3526 salvage) - #841
Merged
Conversation
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
Salvage of PR NousResearch#3526 by @jneeee ("support extra headers"), reimplemented against current main. Named providers /
custom_providersentries inconfig.yamlnow accept anextra_headersdict scoped to that endpoint — for reverse proxies, API gateways, and custom auth schemes (e.g. Cloudflare Access service tokens).model.extra_headersis also accepted as an alias of the existing globalmodel.default_headers.Scope decisions vs. the original PR:
model.default_headers(Custom OpenAI-compatible provider can fail when upstream blocks OpenAI Python SDK default headers NousResearch/hermes-agent#40033); the remaining gap this PR fills is per-provider headers. Instead of threading a newextra_headerskwarg throughAIAgent.__init__→ cli.py → gateway → smart routing (the original approach, 7 call sites), headers are resolved from config by base_url at client-construction time, mirroring the established per-provider TLS plumbing (apply_custom_provider_tls_to_client_kwargs). This automatically covers CLI, gateway, smart routing, credential swaps, and client rebuilds with zero signature churn.default_headerskwarg). Native Anthropic / Bedrock clients are explicitly scoped out, matching the existingmodel.default_headersbehavior._apply_client_headers_for_base_urlre-application (credential rotation, interrupt rebuilds) — the original PR only set them at first construction.extra_headers) flagged in the original PR review is included, with a regression test.Changes
hermes_cli/config.py— acceptextra_headersin_normalize_custom_provider_entry(+ providers-dict translation, known-keys list); newget_custom_provider_extra_headers()/apply_custom_provider_extra_headers_to_client_kwargs()helpers (base_url match: case + trailing-slash insensitive, no substring bypass)hermes_cli/runtime_provider.py— surfaceextra_headersin resolved runtimes for named custom providers: providers dict, legacycustom_providerslist, and the credential-pool pathrun_agent.py/agent/agent_init.py— merge per-provider headers onto OpenAI clientdefault_headersat construction and on every header re-application; most-specific level winsagent/auxiliary_client.py—model.extra_headersalias formodel.default_headers(merged, alias wins)cli-config.yaml.example— commented documentation + examplescripts/release.py— AUTHOR_MAP attribution for @jneeeetests/hermes_cli/test_custom_provider_extra_headers.py(7 new),tests/run_agent/test_custom_provider_extra_headers_client.py(4 new), +6 resolution tests intests/hermes_cli/test_runtime_provider_resolution.pyValidation
scripts/run_tests.sh tests/hermes_cli/test_custom_provider_extra_headers.py tests/run_agent/test_custom_provider_extra_headers_client.py -qscripts/run_tests.sh tests/hermes_cli/test_runtime_provider_resolution.py -q(153 incl. 6 new)test_custom_provider_tls.py,test_provider_attribution_headers.py,test_auxiliary_user_default_headers.py,test_provider_config_validation.pyruff checkon all touched filesInfographic
Nous Research
Mirror-of: NousResearch#57038
NousResearch#57038