Add fetch-native proxy support (HTTPS_PROXY / HTTP_PROXY / NO_PROXY)#382
Open
robgruen wants to merge 6 commits into
Open
Add fetch-native proxy support (HTTPS_PROXY / HTTP_PROXY / NO_PROXY)#382robgruen wants to merge 6 commits into
robgruen wants to merge 6 commits into
Conversation
Route model requests through a proxy using undici's ProxyAgent as the fetch dispatcher. createLanguageModel auto-detects the standard HTTPS_PROXY / HTTP_PROXY / ALL_PROXY variables and honors NO_PROXY via EnvHttpProxyAgent; createOpenAILanguageModel and createAzureOpenAILanguageModel accept an explicit { proxyUrl } via a new LanguageModelOptions argument. undici is an optional, lazily-imported dependency, so non-proxy users are unaffected.
Supersedes #55 and #73, which were built on the removed axios stack.
Replace the positional useResponsesApi parameter on createOpenAILanguageModel with a useResponsesApi field on LanguageModelOptions, collapsing the trailing (flag, options) pair into a single options bag. Neither the parameter nor the options object shipped in the published 0.1.2, so this is not a breaking change.
This was referenced Jul 6, 2026
Closed
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds optional HTTP(S) proxy support for the TypeScript language-model factories when using Node’s native fetch (undici), and consolidates OpenAI factory optional parameters into a single LanguageModelOptions object (including useResponsesApi and proxyUrl). It also bumps the TypeScript package version to 0.1.3.
Changes:
- Add proxy discovery from standard env vars (
HTTPS_PROXY/HTTP_PROXY/ALL_PROXY, honoringNO_PROXY) and support an explicitproxyUrloption via undici dispatchers. - Replace the positional
useResponsesApiparameter withoptions.useResponsesApioncreateOpenAILanguageModel. - Update package version and dependencies/docs/tests accordingly.
Show a summary per file
| File | Description |
|---|---|
typescript/src/model.ts |
Introduces LanguageModelOptions, proxy resolution (env + explicit URL), and threads an undici dispatcher into fetch calls. |
typescript/tests/model.test.mjs |
Updates a test to use the new options.useResponsesApi API. |
typescript/package.json |
Bumps version to 0.1.3 and adds undici as an optional peer dependency (and dev dependency for development/tests). |
typescript/package-lock.json |
Lockfile updates for version bump and dev dependency changes. |
typescript/examples/README.md |
Documents proxy usage via env vars and direct factory options. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Files not reviewed (1)
- typescript/package-lock.json: Generated file
- Files reviewed: 4/5 changed files
- Comments generated: 1
- Review effort level: Low
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.
Summary
Adds optional proxy support for the model endpoints on the native
fetchstack, and consolidates the OpenAI factory's optional arguments into a singleLanguageModelOptionsbag. This supersedes #55 and #73, both written against the old axios-basedmodel.ts(axios has since been removed).Proxy support
createLanguageModel(env)auto-detects the standardHTTPS_PROXY/HTTP_PROXY/ALL_PROXYvariables and honorsNO_PROXY, using undici'sEnvHttpProxyAgent.createOpenAILanguageModel/createAzureOpenAILanguageModelaccept an explicit{ proxyUrl }.fetchdispatcher— the only supported proxy hook for Node's nativefetch(which is itself undici).undiciis an optional, lazily-imported dependency (optional peer dep). Non-proxy users are unaffected; a clear "runnpm install undici" error is thrown if a proxy is configured without it.Why undici
Node's built-in
fetchis undici and exposes no proxy option other than adispatcher, which must be an undici agent.https-proxy-agent(used by #55) returns anhttp.Agent, which nativefetchignores — so undici is the natural choice once the project is onfetch.API consolidation
LanguageModelOptionsnow also carriesuseResponsesApi, replacing the positionaluseResponsesApiparameter oncreateOpenAILanguageModel:The positional
useResponsesApiand the options object were both introduced after the published0.1.2(whose signature iscreateOpenAILanguageModel(apiKey, model, endPoint?, org?)), so this is not a breaking change to any released API. Doing it now — before either ships — avoids a future breaking change.Version
Bumps
typechatto 0.1.3.Testing
Validated end-to-end with a local mock endpoint + CONNECT-tunneling proxy:
{ proxyUrl }/HTTP_PROXYset"")NO_PROXYmatches hostNO_PROXYdoes not matchtsc -p src,tsc -p test, and the model test suite (19 tests) all pass.Notes
EnvHttpProxyAgentis currently flagged experimental by undici and prints a one-time warning; the coreProxyAgent/dispatcherpath is stable.Opening as a draft for discussion.