Open History to see the last commit
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')
12}
13
14export function generateId(prefix: string): string {
15 return _generateId(prefix)
16}
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
28}