Add support for passing custom headers in clientOptions#1817
Merged
Conversation
🦋 Changeset detectedLatest commit: 424dc1a The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
Greptile SummaryThis PR exposes a new Key observations:
Confidence Score: 3/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["User sets clientOptions.headers"] --> B{Model path}
B -->|"provider/model format"| C["getAISDKLanguageModel\ncreator(clientOptions)"]
C --> D["AI SDK provider factory\n✅ headers forwarded"]
B -->|"Legacy model name"| E{Provider}
E -->|"openai / o1 / o3 / gpt-*"| F["new OpenAI(clientOptions)\n✅ headers forwarded"]
E -->|"anthropic/claude-*"| G["new Anthropic(clientOptions)\n✅ headers forwarded"]
E -->|"cerebras-*"| H["new OpenAI({...clientOptions})\n✅ headers forwarded"]
E -->|"groq-*"| I["new OpenAI({...clientOptions})\n✅ headers forwarded"]
E -->|"gemini-*"| J["new GoogleGenAI({apiKey only})\n❌ headers silently dropped"]
Last reviewed commit: 424dc1a |
Contributor
There was a problem hiding this comment.
No issues found across 2 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Architecture diagram
sequenceDiagram
participant User as Client Application
participant SDK as Stagehand SDK
participant API as LLM Provider (OpenAI/Anthropic)
Note over User,SDK: Model Initialization / Execution
User->>SDK: execute(prompt, clientOptions)
Note right of User: NEW: clientOptions now contains <br/>headers: Record<string, string>
SDK->>SDK: Prepare request context
SDK->>SDK: NEW: Merge base headers with custom clientOptions.headers
SDK->>API: HTTP POST (Completion Request)
Note right of SDK: Request includes:<br/>1. Standard Auth/Content-Type<br/>2. NEW: Custom User-defined Headers
alt Successful Request
API-->>SDK: 200 OK (Response Data)
SDK-->>User: Model Output
else Provider Error
API-->>SDK: 4xx/5xx Error
SDK-->>User: Error Exception
end
miguelg719
approved these changes
Mar 12, 2026
This was referenced Mar 12, 2026
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.
why
Allow users to pass custom headers in their LLM calls
what changed
Add headers to the model.ts types
test plan
Summary by cubic
Adds
headerssupport toClientOptionsso clients can send custom HTTP headers with every provider request. Useful for auth tokens or routing hints without changing global config.headers?: Record<string, string>toClientOptionsinpackages/core/lib/v3/types/public/model.ts; headers are sent with each request.Written for commit 424dc1a. Summary will update on new commits. Review in cubic