File size: 564 Bytes
8f1b6ce
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import OpenAI from 'openai';
import type { ClientOptions } from 'openai';

export type GatewayOptions = ClientOptions;
export class Gateway extends OpenAI {
  constructor(options: GatewayOptions = {}) {
    const baseURL = options.baseURL ?? process.env.GATEWAY_BASE_URL;
    const apiKey = options.apiKey ?? process.env.GATEWAY_API_KEY;
    if (!baseURL || !apiKey) throw new Error('Set GATEWAY_BASE_URL and GATEWAY_API_KEY or pass both explicitly.');
    super({ ...options, baseURL, apiKey, maxRetries: options.maxRetries ?? 0 });
  }
}
export default Gateway;