findEnvKeys (src/env-api-keys.ts)

pi · packages/ai/src/env-api-keys.ts · typescript · MIT
infra, tag:knn-classified

Utility for discovering API key environment variables across providers, handling Node/Bun specifics.

// Source: https://github.com/earendil-works/pi | License: MIT | Copyright 2025 Mario Zechner
// Provided via justclaw.it.com; keep this notice with the code.
// NEVER convert to top-level imports - breaks browser/Vite builds
let _existsSync: typeof import("node:fs").existsSync | null = null;
let _homedir: typeof import("node:os").homedir | null = null;
let _join: typeof import("node:path").join | null = null;

type DynamicImport = (specifier: string) => Promise<unknown>;

const dynamicImport: DynamicImport = (specifier) => import(specifier);
const NODE_FS_SPECIFIER = "node:" + "fs";
const NODE_OS_SPECIFIER = "node:" + "os";
const NODE_PATH_SPECIFIER = "node:" + "path";

// Eagerly load in Node.js/Bun environment only
if (typeof process !== "undefined" && (process.versions?.node || process

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key