MCPcopy Create free account
hub / github.com/TanStack/ai / getApiKeyFromEnv

Function getApiKeyFromEnv

packages/ai-utils/src/env.ts:1–18  ·  view source on GitHub ↗
(envVarName: string)

Source from the content-addressed store, hash-verified

1export function getApiKeyFromEnv(envVarName: string): string {
2 const env =
3 typeof globalThis !== 'undefined' && (globalThis as any).window?.env
4 ? (globalThis as any).window.env
5 : typeof process !== 'undefined'
6 ? process.env
7 : undefined
8
9 const apiKey = env?.[envVarName]
10
11 if (!apiKey) {
12 throw new Error(
13 `${envVarName} is not set. Please set the ${envVarName} environment variable or pass the API key directly.`,
14 )
15 }
16
17 return apiKey
18}

Callers 9

getGrokApiKeyFromEnvFunction · 0.90
getFalApiKeyFromEnvFunction · 0.90
getOpenAIApiKeyFromEnvFunction · 0.90
getGeminiApiKeyFromEnvFunction · 0.90
getGroqApiKeyFromEnvFunction · 0.90
env.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected