Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

client.ts

27 lines816 Bytes

1import { getApiKeyFromEnv } from '@tanstack/ai-utils'
2import type { ClientOptions } from 'openai'
3​
4/**
5 * OpenAI client configuration. Pass through to `new OpenAI(...)`. `apiKey`
6 * is required so the OpenAI adapters don't need to handle a missing-key
7 * case at construction time.
8 */
9export interface OpenAIClientConfig extends Omit<ClientOptions, 'apiKey'> {
10 apiKey: string
12​
13/**
14 * Gets OpenAI API key from environment variables
15 * @throws Error if OPENAI_API_KEY is not found
16 */
17export function getOpenAIApiKeyFromEnv(): string {
18 return getApiKeyFromEnv('OPENAI_API_KEY')
20​
21/**
22 * Gets the Azure OpenAI API key from environment variables
23 * @throws Error if AZURE_OPENAI_API_KEY is not found
24 */
25export function getAzureOpenAIApiKeyFromEnv(): string {
26 return getApiKeyFromEnv('AZURE_OPENAI_API_KEY')