feat(embed): add default_headers support to OpenAIEmbeddingConfig#705
Draft
micmarty-deepsense wants to merge 2 commits intomainfrom
Draft
feat(embed): add default_headers support to OpenAIEmbeddingConfig#705micmarty-deepsense wants to merge 2 commits intomainfrom
micmarty-deepsense wants to merge 2 commits intomainfrom
Conversation
Adds an optional default_headers: dict[str, SecretStr] field to OpenAIEmbeddingConfig. When set, the headers are extracted via .get_secret_value() and passed as default_headers= to the OpenAI SDK constructor, attaching them to every request. This enables custom OpenAI-compatible endpoints that require non-standard auth headers alongside the Bearer token.
…sync_client Covers: no headers (kwarg absent), headers present (SecretStr unwrapped to str), both sync and async client construction paths.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes
unstructured_ingest/embed/openai.pydefault_headers: Optional[dict[str, SecretStr]]toOpenAIEmbeddingConfigget_client()andget_async_client(): extracts header values via.get_secret_value()and passesdefault_headers=to the OpenAI SDK constructormodel_dump) to avoid SecretStr serialization to"**********"The OpenAI SDK's
default_headersconstructor param attaches extra headers to every request without interfering with Bearer token construction. This enables custom OpenAI-compatible endpoints that require additional auth headers.Test plan
get_client()passes extracted headers whendefault_headersis setget_client()omitsdefault_headerskwarg when field isNonedefault_headerspointing at a custom endpoint, confirm headers appear on requestsNote
Medium Risk
Medium risk because it changes how OpenAI clients are constructed and can alter outbound authentication/headers for all embedding requests when configured.
Overview
Adds optional
default_headerstoOpenAIEmbeddingConfigand threads it throughget_client()/get_async_client()so extra per-request HTTP headers can be sent to OpenAI (or OpenAI-compatible) endpoints.Header values are stored as
SecretStrand explicitly unwrapped via.get_secret_value()before passingdefault_headersinto the OpenAI SDK constructors.Reviewed by Cursor Bugbot for commit 065980c. Bugbot is set up for automated code reviews on this repo. Configure here.