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 requests
2import json
3import base64
4
5def encode_audio_to_base64(audio_path):
6 with open(audio_path, "rb") as audio_file:
7 return base64.b64encode(audio_file.read()).decode('utf-8')
8
9url = "https://openrouter.ai/api/v1/chat/completions"
10headers = {
11 "Authorization": f"Bearer {API_KEY_REF}",
12 "Content-Type": "application/json"
13}
14
15# Read and encode the audio file
16audio_path = "path/to/your/audio.wav"
17base64_audio = encode_audio_to_base64(audio_path)
18
19messages = [
20 {
21 "role": "user",
22 "content": [
23 {
24 "type": "text",
25 "text": "Please transcribe this audio file."
26 },
27 {
28 "type": "input_audio",
29 "input_audio": {
30 "data": base64_audio,
31 "format": "wav"
32 }
33 }
34 ]
35 }
36]
37
38payload = {
39 "model": "{{MODEL}}",
40 "messages": messages
41}
42
43response = requests.post(url, headers=headers, json=payload)
44print(response.json())

Supported audio formats are:

  • wav
  • mp3