The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
import { observeResponseHeaders, type ResponseHeadersListener } from "@/lib/http/observeResponseHeaders";
import openai from "openai";
import { getGatewayBaseUrl } from "@/components/networking";
import { buildPlaygroundHeaders, type CustomHeaders } from "@/components/llm_calls/request_headers";
import { toast } from "@/lib/toast";
export async function makeOpenAIAudioTranscriptionRequest(
audioFile: File,
updateUI: (transcription: string, model: string) => void,
selectedModel: string,
accessToken: string,
tags?: string[],
signal?: AbortSignal,
language?: string,
prompt?: string,
responseFormat?: string,
temperature?: number,
customBaseUrl?: string,
customHeaders?: CustomHeaders,
onResponseHeaders?: ResponseHeadersListener,
) {
// base url should be the current base_url
const isLocal = process.env.NODE_ENV === "development";
if (isLocal !== true) {
console.log = function () {};
}
const proxyBaseUrl = customBaseUrl || getGatewayBaseUrl();
const client = new openai.OpenAI({
apiKey: accessToken,
baseURL: proxyBaseUrl,
dangerouslyAllowBrowser: true,
defaultHeaders: buildPlaygroundHeaders(tags, customHeaders),
...(onResponseHeaders ? { fetch: observeResponseHeaders(onResponseHeaders) } : {}),
});
try {
const response = await client.audio.transcriptions.create(
{
model: selectedModel,
file: audioFile,
...(language ? { language: language } : {}),
...(prompt ? { prompt: prompt } : {}),
...(responseFormat ? { response_format: responseFormat as any } : {}),
...(temperature !== undefined ? { temperature: temperature } : {}),
},
{ signal },
);
// The response is a transcription object with a text field
if (response && response.text) {
updateUI(response.text, selectedModel);
toast.success(`Audio transcribed successfully`);
} else {
throw new Error("No transcription text in response");
}
} catch (error: any) {
console.error("Error making audio transcription request:", error);
if (signal?.aborted) {
} else {
let errorMessage = "Failed to transcribe audio";
if (error?.error?.message) {
errorMessage = error.error.message;
} else if (error?.message) {
errorMessage = error.message;
}
toast.fromError(`Audio transcription failed: ${errorMessage}`);
}
throw error; // Re-throw to allow the caller to handle the error
}
}