Skip to content

feat: add extra_headers_from_state to ClientConfig#1048

Open
samsja wants to merge 1 commit intomainfrom
feature/extra-headers-from-state
Open

feat: add extra_headers_from_state to ClientConfig#1048
samsja wants to merge 1 commit intomainfrom
feature/extra-headers-from-state

Conversation

@samsja
Copy link
Member

@samsja samsja commented Mar 21, 2026

Summary

  • Adds extra_headers_from_state field to ClientConfig that maps HTTP header names to state field names
  • For each inference request, headers are dynamically built from the rollout state dict
  • Enables sticky routing (e.g. X-Session-ID from example_id) without monkey-patching client classes

Usage

ClientConfig(extra_headers_from_state={"X-Session-ID": "example_id"})

Or in TOML:

[orchestrator.client]
extra_headers_from_state = {"X-Session-ID" = "example_id"}

Changes

  • types.py: New extra_headers_from_state field on ClientConfig
  • clients/client.py: Store config ref, add _build_state_headers(), inject headers in get_response()
  • clients/openai_chat_completions_client.py: Pass extra_headers to chat.completions.create()
  • clients/openai_chat_completions_token_client.py: Pass extra_headers to both fallback and token paths

Test plan

  • Verify ClientConfig(extra_headers_from_state={"X-Session-ID": "example_id"}) works
  • Verify headers appear on outgoing requests when state has the field
  • Verify no headers added when state field is missing
  • Verify no regression for clients without extra_headers_from_state

🤖 Generated with Claude Code

Adds per-request dynamic HTTP headers derived from state fields.
This enables use cases like sticky routing (X-Session-ID from example_id)
without monkey-patching client classes.

Usage:
  ClientConfig(extra_headers_from_state={"X-Session-ID": "example_id"})

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@samsja samsja force-pushed the feature/extra-headers-from-state branch from e7d9f7e to 9ee9aaf Compare March 21, 2026 02:38
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.

1 participant