Skip to main content

Audio Input

How to send audio files to OneRoute models.

OneRoute supports sending audio files to compatible models via the API. This guide shows you how to process audio using our API.

Note: The audio file must be base64-encoded — raw URLs are not supported for audio content.

Audio Input

Using the /api/v1/chat/completions API with the input_audio content type, you can send requests that include audio files to compatible models. The audio file must be base64-encoded and include a format specifier. Only models with audio processing capabilities can handle these requests.

Send an Audio File

Here is how to send an audio file for processing:

import openai
import base64

client = openai.OpenAI(
api_key="YOUR_ONEROUTE_API_KEY",
base_url="https://gw.1route.ai/v1",
)

# Encode an audio file to base64
def encode_audio_to_base64(audio_path: str) -> str:
with open(audio_path, "rb") as audio_file:
return base64.b64encode(audio_file.read()).decode("utf-8")

# Read and encode the audio file
audio_path = "path/to/your/audio.wav"
base64_audio = encode_audio_to_base64(audio_path)

result = client.chat.completions.create(
model="your-model",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "Please transcribe this audio file."
},
{
"type": "input_audio",
"input_audio": {
"data": base64_audio,
"format": "wav"
}
}
]
}
]
)

print(result.choices[0].message.content)

Supported Audio Formats

Supported audio formats vary by provider. Common formats include:

FormatDescription
wavWAV audio
mp3MP3 audio
aiffAIFF audio
aacAAC audio
oggOGG Vorbis audio
flacFLAC audio
m4aM4A audio
pcm16PCM16 audio
pcm24PCM24 audio

Note: Check your model's documentation to confirm which audio formats are supported. Not all models support all formats.