You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Request: default_headers for the OpenAI provider #549
OpenAILanguageModel creates its openai.OpenAI client from api_key, base_url and organization only, and extra keyword arguments are sent as Chat Completions parameters. So there's no way to send HTTP headers with every request. OpenAI-compatible proxies and gateways often need them: routing or project headers, cost attribution, or a per-job id so a gateway can track or limit what one extraction job spends across LangExtract's parallel workers.
Related to an issue?
Not that I found.
Possible solutions and alternatives
Add an optional default_headers argument to OpenAILanguageModel, passed to openai.OpenAI(default_headers=...) (not into the request params). It would be reachable through language_model_params={"default_headers": {...}} like the other provider kwargs. Default None, so nothing changes for existing users.
Alternative: subclassing the provider or passing a custom client, which is heavier for a one-line need.
Priority and timeline considerations
Nice to have; small and backwards compatible.
Additional context
I've opened #548 with the change and tests. Disclosure: I maintain Inferrail, an open-source OpenAI-compatible gateway that uses such headers for per-job cost limits, but the change is generic.
Would you like to contribute to the project and work on this request? Yes, PR #548.
Activity