Audio Inputs

How to send audio files to OpenRouter models

OpenRouter supports sending audio files to compatible models via the API. This guide will show you how to work with audio using our API.

Note: Audio files must be base64-encoded - direct URLs are not supported for audio content.

Audio Inputs

Requests with audio files to compatible models are available via the /api/v1/chat/completions API with the input_audio content type. Audio files must be base64-encoded and include the format specification. Note that only models with audio processing capabilities will handle these requests.

You can search for models that support audio by filtering to audio input modality on our Models page.

Sending Audio Files

Here’s how to send an audio file for processing:

1import { OpenRouter } from '@openrouter/sdk';
2import fs from "fs/promises";
3
4const openRouter = new OpenRouter({
5 apiKey: '{{API_KEY_REF}}',
6});
7
8async function encodeAudioToBase64(audioPath: string): Promise<string> {
9 const audioBuffer = await fs.readFile(audioPath);
10 return audioBuffer.toString("base64");
11}
12
13// Read and encode the audio file
14const audioPath = "path/to/your/audio.wav";
15const base64Audio = await encodeAudioToBase64(audioPath);
16
17const result = await openRouter.chat.send({
18 model: "{{MODEL}}",
19 messages: [
20 {
21 role: "user",
22 content: [
23 {
24 type: "text",
25 text: "Please transcribe this audio file.",
26 },
27 {
28 type: "input_audio",
29 inputAudio: {
30 data: base64Audio,
31 format: "wav",
32 },
33 },
34 ],
35 },
36 ],
37 stream: false,
38});
39
40console.log(result);

Supported audio formats are:

  • wav
  • mp3