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

client.ts

28 lines767 Bytes

1import { generateId as _generateId, getApiKeyFromEnv } from '@tanstack/ai-utils'
2​
3export interface OpenRouterClientConfig {
4 apiKey: string
5 baseURL?: string
6 httpReferer?: string
7 xTitle?: string
8}
9​
10export function getOpenRouterApiKeyFromEnv(): string {
11 return getApiKeyFromEnv('OPENROUTER_API_KEY')
13​
14export function generateId(prefix: string): string {
15 return _generateId(prefix)
17​
18export function buildHeaders(
19 config: OpenRouterClientConfig,
20): Record<string, string> {
21 const headers: Record<string, string> = {
22 Authorization: `Bearer ${config.apiKey}`,
23 'Content-Type': 'application/json',
24 }
25 if (config.httpReferer) headers['HTTP-Referer'] = config.httpReferer
26 if (config.xTitle) headers['X-Title'] = config.xTitle
27 return headers