Skip to content

Add fetch-native proxy support (HTTPS_PROXY / HTTP_PROXY / NO_PROXY)#382

Open
robgruen wants to merge 6 commits into
mainfrom
fetch-native-proxy-support
Open

Add fetch-native proxy support (HTTPS_PROXY / HTTP_PROXY / NO_PROXY)#382
robgruen wants to merge 6 commits into
mainfrom
fetch-native-proxy-support

Conversation

@robgruen

@robgruen robgruen commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds optional proxy support for the model endpoints on the native fetch stack, and consolidates the OpenAI factory's optional arguments into a single LanguageModelOptions bag. This supersedes #55 and #73, both written against the old axios-based model.ts (axios has since been removed).

Proxy support

  • createLanguageModel(env) auto-detects the standard HTTPS_PROXY / HTTP_PROXY / ALL_PROXY variables and honors NO_PROXY, using undici's EnvHttpProxyAgent.
  • createOpenAILanguageModel / createAzureOpenAILanguageModel accept an explicit { proxyUrl }.
  • The proxy is supplied as the fetch dispatcher — the only supported proxy hook for Node's native fetch (which is itself undici).
  • undici is an optional, lazily-imported dependency (optional peer dep). Non-proxy users are unaffected; a clear "run npm install undici" error is thrown if a proxy is configured without it.

Why undici

Node's built-in fetch is undici and exposes no proxy option other than a dispatcher, which must be an undici agent. https-proxy-agent (used by #55) returns an http.Agent, which native fetch ignores — so undici is the natural choice once the project is on fetch.

API consolidation

LanguageModelOptions now also carries useResponsesApi, replacing the positional useResponsesApi parameter on createOpenAILanguageModel:

// before (unreleased):
createOpenAILanguageModel(apiKey, model, endPoint?, org?, useResponsesApi?, options?)
// after:
createOpenAILanguageModel(apiKey, model, endPoint?, org?, options?)  // { proxyUrl?, useResponsesApi? }

The positional useResponsesApi and the options object were both introduced after the published 0.1.2 (whose signature is createOpenAILanguageModel(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 typechat to 0.1.3.

Testing

Validated end-to-end with a local mock endpoint + CONNECT-tunneling proxy:

Scenario Result Routed through proxy?
no proxy success no (direct)
{ proxyUrl } / HTTP_PROXY set success yes
empty proxy string ("") success no — no agent constructed (fixes #55's crash-on-default)
NO_PROXY matches host success no — bypassed
NO_PROXY does not match success yes

tsc -p src, tsc -p test, and the model test suite (19 tests) all pass.

Notes

  • EnvHttpProxyAgent is currently flagged experimental by undici and prints a one-time warning; the core ProxyAgent / dispatcher path is stable.
  • No new required dependencies for existing users.

Opening as a draft for discussion.

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.
@robgruen robgruen marked this pull request as draft July 6, 2026 19:14
robgruen added 2 commits July 6, 2026 12:26
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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, honoring NO_PROXY) and support an explicit proxyUrl option via undici dispatchers.
  • Replace the positional useResponsesApi parameter with options.useResponsesApi on createOpenAILanguageModel.
  • 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

Comment thread typescript/examples/README.md Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@robgruen robgruen marked this pull request as ready for review July 6, 2026 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants