Audio Input Agent

Send an MP3 to gpt-audio through a local LiteLLM proxy with LiteLLMOpenAI.

Download an MP3 and pass it as audio input to a gpt-audio model served by a local LiteLLM proxy.

OPENAI_API_KEY belongs to the upstream OpenAI account. LITELLM_API_KEY is the agent client's proxy bearer value: local-proxy is a placeholder for this local server, which has no authentication configured by these commands. If you configure proxy authentication, supply its accepted key instead. Exporting a client key alone does not configure server authentication.

audio_input_agent.py
"""
Please first install litellm[proxy] by running: uv pip install 'litellm[proxy]'

Before running this script, you need to start the LiteLLM server:

litellm --model gpt-audio --host 127.0.0.1 --port 4000
"""

import requests
from agno.agent import Agent, RunOutput  # noqa
from agno.media import Audio
from agno.models.litellm import LiteLLMOpenAI

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------

# Fetch the QA audio file and convert it to a base64 encoded string
url = "https://agno-public.s3.us-east-1.amazonaws.com/demo_data/QA-01.mp3"
response = requests.get(url)
response.raise_for_status()
mp3_data = response.content

# Provide the agent with the audio file and get result as text
# Note: Audio input requires specific audio-enabled models like gpt-audio
agent = Agent(
    model=LiteLLMOpenAI(id="gpt-audio"),
    markdown=True,
)
agent.print_response(
    "What is in this audio?", audio=[Audio(content=mp3_data, format="mp3")], stream=True
)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    pass

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno "litellm[proxy]" openai requests

Export your API keys

export LITELLM_API_KEY="local-proxy"
export OPENAI_API_KEY="your_openai_api_key_here"

Start LiteLLM

In the first terminal, with OPENAI_API_KEY set, start the audio proxy below and leave it running:

litellm --model gpt-audio --host 127.0.0.1 --port 4000

Point the client at the local proxy

Add base_url="http://127.0.0.1:4000" to LiteLLMOpenAI(...) in the saved file. In a second terminal, activate the same virtual environment and set LITELLM_API_KEY as above before running the agent. The foreground proxy uses the model selected by its CLI command.

Run the example

Save the code above as audio_input_agent.py, then run:

python audio_input_agent.py

Full source: cookbook/90_models/litellm_openai/audio_input_agent.py