feat(ai): Support HTTP proxy through environment variables

This commit is contained in:
haoqixu 2026-01-25 15:47:24 +08:00
parent 3635e45ffd
commit 1e718e63ea
4 changed files with 314 additions and 13 deletions

View file

@ -14,6 +14,15 @@ import type {
export { getEnvApiKey } from "./env-api-keys.js";
// Set up http proxy according to env variables for `fetch` based SDKs in Node.js.
// Bun has builtin support for this.
if (typeof process !== "undefined" && process.versions?.node) {
import("undici").then((m) => {
const { EnvHttpProxyAgent, setGlobalDispatcher } = m;
setGlobalDispatcher(new EnvHttpProxyAgent());
});
}
function resolveApiProvider(api: Api) {
const provider = getApiProvider(api);
if (!provider) {