Skip to content

feat: add custom headers support for API requests #1439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

GregBrimble
Copy link

Add support for custom headers in API requests via:

  • custom_headers field in ModelProviderInfo config
  • CODEX_CUSTOM_HEADERS environment variable with format "key: value\nkey2: value2"

Headers from both sources are merged, with env var taking precedence. Both Chat Completions and Responses APIs now include custom headers.

Resolves #1152

Copy link

github-actions bot commented Jul 1, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@GregBrimble
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Jul 1, 2025
@GregBrimble GregBrimble force-pushed the feat/custom-headers-support branch 3 times, most recently from 3a9c7e0 to d09f526 Compare July 2, 2025 03:01
- Support provider-specific environment variables (OPENAI_CUSTOM_HEADERS, GROQ_CUSTOM_HEADERS, etc.)
- Environment variables take precedence over provider config headers
- Implemented in both TypeScript and Rust implementations
- Added comprehensive test coverage for all supported providers
- Header format: "key: value\nkey2: value2"
@GregBrimble GregBrimble force-pushed the feat/custom-headers-support branch from d09f526 to 854d556 Compare July 2, 2025 03:12
@bolinfest
Copy link
Collaborator

To date, we generally favor configuration via config.toml and the -c command-line flag rather than environment variables. Is there a compelling reason why environment variables should be supported for this option?

@GregBrimble
Copy link
Author

Nope! No strong reason at all — I was just taking inspiration from how Claude Code works. But I'm more than happy to go config-only if that's what y'all prefer. I'll update this PR.

@bolinfest
Copy link
Collaborator

Actually, it turns out that we have some logic of our own that needs this behavior:

...(OPENAI_PROJECT ? { "OpenAI-Project": OPENAI_PROJECT } : {}),

I'm going to go ahead and add two separate fields to ModelProviderInfo:

  • http_headers
  • env_key_http_headers

The former will be used for hardcoded values; the latter will be used for values that should come from environment variables.

@bolinfest
Copy link
Collaborator

@GregBrimble see #1473

@bolinfest
Copy link
Collaborator

This functionality is now available in the 0.3.0 release.

@bolinfest bolinfest closed this Jul 8, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Jul 8, 2025
@bolinfest
Copy link
Collaborator

@GregBrimble thanks for the push+inspiration to make this happen!

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.

2 participants