export type CreateApiV1AudioSpeechArgs = {'Idempotency-Key'?: string | undefined, body: {model: string, input: string, voice: unknown, instructions?: string | undefined, response_format?: ('mp3' | 'wav' | 'pcm') | undefined, speed?: number | undefined}}; export type CreateApiV1AudioSpeechOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; /** * OpenAI audio speech * * POST /v1/audio/speech * * Also accepts auth: apiKey */ export const createApiV1AudioSpeech = async (args: CreateApiV1AudioSpeechArgs, options?: CreateApiV1AudioSpeechOptions) => { const {baseUrl = "https://api.agentlab.cresclab.com", fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "audio/mpeg") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/audio/speech${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.blob() };