> ## Documentation Index
> Fetch the complete documentation index at: https://docs.anannas.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Audio Inputs

> How to send audio files to Anannas models

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

<Note>
  Audio files must be **base64-encoded** - direct URLs are not supported for audio content.
</Note>

### Audio Inputs

Requests with audio files to compatible models are available via the `/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](https://anannas.ai/models).

### Sending Audio Files

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

<CodeGroup>
  ```python Python theme={null}
  import requests
  import base64
  from pathlib import Path

  def transcribe_audio(file_path, model_id, max_tokens=4096):
      """Transcribe audio file using Anannas API."""
      
      # Read and encode audio file
      with open(file_path, 'rb') as f:
          audio_data = base64.b64encode(f.read()).decode('utf-8')
      
      # Get file extension for format (e.g., .mp3 -> mp3)
      file_ext = Path(file_path).suffix.lstrip('.').lower()
      
      # Prepare payload
      payload = {
          'model': model_id,
          'messages': [{
              'role': 'user',
              'content': [
                  {
                      'type': 'text',
                      'text': 'Transcribe and summarize this audio.'
                  },
                  {
                      'type': 'input_audio',
                      'input_audio': {
                          'data': audio_data,
                          'format': file_ext
                      }
                  }
              ]
          }],
          'max_tokens': max_tokens
      }
      
      # Make API request
      response = requests.post(
          'https://api.anannas.ai/v1/chat/completions',
          headers={
              'Authorization': f'Bearer {API_KEY_REF}',
              'Content-Type': 'application/json'
          },
          json=payload,
          timeout=60
      )
      
      if response.status_code == 200:
          result = response.json()
          content = result['choices'][0]['message']['content']
          print(content)
          
          # Print token usage if available
          if 'usage' in result:
              print(f"\nTokens used: {result['usage'].get('total_tokens', 'N/A')}")
          return content
      else:
          print(f'Error: {response.status_code} - {response.text}')
          return None

  # Example usage
  transcribe_audio('path/to/your/audio.wav', 'google/gemini-3-flash-preview', max_tokens=20000)
  ```

  ```typescript Typescript theme={null}
  import fs from 'fs/promises';
  import path from 'path';

  async function transcribeAudio(
    filePath: string,
    modelId: string,
    maxTokens: number = 4096
  ): Promise<string | null> {
    // Read and encode audio file
    const buffer = await fs.readFile(filePath);
    const base64Audio = buffer.toString('base64');
    
    // Get file extension for format (e.g., .mp3 -> mp3)
    const fileExt = path.extname(filePath).slice(1).toLowerCase();
    
    // Make API request
    const response = await fetch('https://api.anannas.ai/v1/chat/completions', {
      method: 'POST',
      headers: {
        Authorization: `Bearer ${API_KEY_REF}`,
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        model: modelId,
        messages: [
          {
            role: 'user',
            content: [
              {
                type: 'text',
                text: 'Transcribe and summarize this audio.',
              },
              {
                type: 'input_audio',
                input_audio: {
                  data: base64Audio,
                  format: fileExt,
                },
              },
            ],
          },
        ],
        max_tokens: maxTokens,
      }),
    });
    
    if (response.ok) {
      const result = await response.json();
      const content = result.choices[0].message.content;
      console.log(content);
      
      // Print token usage if available
      if (result.usage) {
        console.log(`\nTokens used: ${result.usage.total_tokens || 'N/A'}`);
      }
      return content;
    } else {
      const error = await response.text();
      console.error(`Error: ${response.status} - ${error}`);
      return null;
    }
  }

  // Example usage
  await transcribeAudio('path/to/your/audio.wav', 'google/gemini-3-flash-preview', 20000);
  ```
</CodeGroup>

### Format Detection

The audio format is typically determined from the file extension. Extract the format by removing the leading dot from the file extension (e.g., `.mp3` → `mp3`, `.wav` → `wav`).

### Supported Formats

Supported audio formats vary by provider. Common formats include:

* `wav` - WAV audio
* `mp3` - MP3 audio
* `aiff` - AIFF audio
* `aac` - AAC audio
* `ogg` - OGG Vorbis audio
* `flac` - FLAC audio
* `m4a` - M4A audio
* `pcm16` - PCM16 audio
* `pcm24` - PCM24 audio

<Card title="Check Format Support" icon="book">
  Note: Check your model's documentation to confirm which audio formats it supports. Not all models support all formats. Visit [anannas.ai/models](https://anannas.ai/models) to see capabilities by model.
</Card>

<div
  style={{ 
marginTop: '2rem',
display: 'flex',
alignItems: 'center',
gap: '0.75rem',
fontSize: '14px',
color: '#6b7280'
}}
>
  <span>Was this page helpful?</span>

  <button
    id="feedback-yes-btn"
    onClick={() => {
  console.log('Positive feedback');
  document.getElementById('feedback-yes-btn').style.background = 'rgba(156, 163, 175, 0.1)';
  document.getElementById('feedback-yes-btn').style.backdropFilter = 'blur(10px)';
  document.getElementById('feedback-yes-btn').style.border = '1px solid rgba(156, 163, 175, 0.2)';
  document.getElementById('feedback-no-btn').style.background = 'transparent';
  document.getElementById('feedback-no-btn').style.backdropFilter = 'none';
  document.getElementById('feedback-no-btn').style.border = 'none';
}}
    style={{
  background: 'transparent',
  border: 'none',
  cursor: 'pointer',
  padding: '6px 12px',
  fontSize: '14px',
  borderRadius: '8px',
  transition: 'all 0.2s ease',
  display: 'flex',
  alignItems: 'center',
  gap: '6px',
  color: '#6b7280'
}}
  >
    <span style={{ fontSize: '16px' }}>👍</span>
    Yes
  </button>

  <button
    id="feedback-no-btn"
    onClick={() => {
  console.log('Negative feedback');
  document.getElementById('feedback-no-btn').style.background = 'rgba(156, 163, 175, 0.1)';
  document.getElementById('feedback-no-btn').style.backdropFilter = 'blur(10px)';
  document.getElementById('feedback-no-btn').style.border = '1px solid rgba(156, 163, 175, 0.2)';
  document.getElementById('feedback-yes-btn').style.background = 'transparent';
  document.getElementById('feedback-yes-btn').style.backdropFilter = 'none';
  document.getElementById('feedback-yes-btn').style.border = 'none';
}}
    style={{
  background: 'transparent',
  border: 'none',
  cursor: 'pointer',
  padding: '6px 12px',
  fontSize: '14px',
  borderRadius: '8px',
  transition: 'all 0.2s ease',
  display: 'flex',
  alignItems: 'center',
  gap: '6px',
  color: '#6b7280'
}}
  >
    <span style={{ fontSize: '16px' }}>👎</span>
    No
  </button>
</div>
