Skip to content

Request: default_headers for the OpenAI provider #549

Open

Description

@domondi1

Describe the overall idea and motivation

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址