Skip to content

feat: support custom HTTP headers for model providers - #1473

Merged
bolinfest merged 1 commit into
mainfrom
pr1473
Jul 7, 2025
Merged

bolinfest merged 1 commit into
mainfrom
pr1473

Conversation

@bolinfest

@bolinfest bolinfest commented Jul 7, 2025 •

Copy link
Copy Markdown
Collaborator

This adds support for two new model provider config options:

  • http_headers for hardcoded (key, value) pairs
  • env_http_headers for headers whose values should be read from environment variables

This also updates the built-in openai provider to use this feature to set the following headers:

  • originator => codex_cli_rs
  • version => [CLI version]
  • OpenAI-Organization => OPENAI_ORGANIZATION env var
  • OpenAI-Project => OPENAI_PROJECT env var

for consistency with the TypeScript implementation:

defaultHeaders: {
originator: ORIGIN,
version: CLI_VERSION,
session_id: this.sessionId,
...(OPENAI_ORGANIZATION
? { "OpenAI-Organization": OPENAI_ORGANIZATION }
: {}),
...(OPENAI_PROJECT ? { "OpenAI-Project": OPENAI_PROJECT } : {}),
},

While here, this also consolidates some logic that was duplicated across client.rs and chat_completions.rs by introducing ModelProviderInfo.create_request_builder().

Resolves #1152

@bolinfest bolinfest changed the title feat: add support for http_headers and env_key_http_headers feat: support custom HTTP headers for model providers Jul 7, 2025
@bolinfest
bolinfest merged commit c221eab into main Jul 7, 2025
@bolinfest
bolinfest deleted the pr1473 branch July 7, 2025 20:09
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant