Audio
How to send and receive audio with Linkora models
Linkora supports both sending audio files to compatible models and receiving audio responses via the API. This guide covers how to work with audio inputs and outputs.
Audio Inputs
Send audio files to compatible models for transcription, analysis, and processing. Audio input requests use the Responses API (/api/v1/responses) with the input_audio content type. Audio files must be base64-encoded and include the format specification.
Note: Audio files must be base64-encoded - direct URLs are not supported for audio content.
You can search for models that support audio input by filtering to audio input modality on our Models page.
Sending Audio Files
Here's how to send an audio file for processing:
import { Linkora } from '@linkora/sdk';
import fs from "fs/promises";
const linkora = new Linkora({
apiKey: '<LINKORA_API_KEY>',
});
async function encodeAudioToBase64(audioPath: string): Promise<string> {
const audioBuffer = await fs.readFile(audioPath);
return audioBuffer.toString("base64");
}
// Read and encode the audio file
const audioPath = "path/to/your/audio.wav";
const base64Audio = await encodeAudioToBase64(audioPath);
const result = await linkora.responses.send({
responsesRequest: {
model: "google/gemini-2.5-flash",
input: [
{
role: "user",
content: [
{
type: "input_text",
text: "Please transcribe this audio file.",
},
{
type: "input_audio",
inputAudio: {
data: base64Audio,
format: "wav",
},
},
],
},
],
stream: false,
},
});
console.log(result);Supported Audio Input Formats
The Responses API (/api/v1/responses) accepts two format values for input_audio:
wav- WAV audiomp3- MP3 audio
Chat Completions (/api/v1/chat/completions) accepts any format string the provider supports, such as aiff, aac, ogg, flac, m4a, pcm16, or pcm24, in the input_audio.format field of its content parts.
Note: Check your model's documentation to confirm which audio formats it supports. Not all models support all formats.
Audio Output
Linkora supports receiving audio responses from models that have audio output capabilities. To request audio output, include the modalities and audio parameters in your request. Audio output uses the Chat Completions API (/api/v1/chat/completions), because the Responses API does not accept the audio parameter.
You can search for models that support audio output by filtering to audio output modality on our Models page.
Requesting Audio Output
To receive audio output, set modalities to ["text", "audio"] and provide the audio configuration with your desired voice and format:
import requests
import json
import base64
url = "https://link-ora.net/api/v1/chat/completions"
headers = {
"Authorization": f"Bearer {API_KEY_REF}",
"Content-Type": "application/json"
}
payload = {
"model": "openai/gpt-4o-audio-preview",
"messages": [
{
"role": "user",
"content": "Say hello in a friendly tone."
}
],
"modalities": ["text", "audio"],
"audio": {
"voice": "alloy",
"format": "wav"
},
"stream": True
}
# Audio output requires streaming — the response is delivered as SSE chunks
response = requests.post(url, headers=headers, json=payload, stream=True)
audio_data_chunks = []
transcript_chunks = []
for line in response.iter_lines():
if not line:
continue
decoded = line.decode("utf-8")
if not decoded.startswith("data: "):
continue
data = decoded[len("data: "):]
if data.strip() == "[DONE]":
break
chunk = json.loads(data)
delta = chunk["choices"][0].get("delta", {})
audio = delta.get("audio", {})
if audio.get("data"):
audio_data_chunks.append(audio["data"])
if audio.get("transcript"):
transcript_chunks.append(audio["transcript"])
transcript = "".join(transcript_chunks)
print(f"Transcript: {transcript}")
# Combine and decode the base64 audio chunks, then save
full_audio_b64 = "".join(audio_data_chunks)
audio_bytes = base64.b64decode(full_audio_b64)
with open("output.wav", "wb") as f:
f.write(audio_bytes)Streaming Chunk Format
Audio output requires streaming (stream: true). Audio data and transcript are delivered incrementally via the delta.audio field in each chunk:
{
"choices": [
{
"delta": {
"audio": {
"data": "<base64-encoded audio chunk>",
"transcript": "Hello"
}
}
}
]
}Audio Configuration Options
The audio parameter accepts the following options:
| Option | Description |
|---|---|
| `voice` | The voice to use for audio generation (e.g., `alloy`, `echo`, `fable`, `onyx`, `nova`, `shimmer`). Available voices vary by model. |
| `format` | The audio format for the output (e.g., `wav`, `mp3`, `flac`, `opus`, `pcm16`). Available formats vary by model. |
