better-sandwich-65834
10/22/2025, 8:18 AMtall-airline-16756
10/22/2025, 8:18 AMtall-airline-16756
10/22/2025, 8:19 AMRealtimeModel.with_azure for testing using pytest, here’s a simple step-by-step guide:
1. First, make sure you have the necessary packages installed:
pip install pytest pytest-asyncio
1. Next, you can use this test pattern that includes an agent session context manager to keep things organized:
import pytest
from livekit.plugins.openai.realtime import RealtimeModel
from livekit.agents.testing import AgentSession
@pytest.mark.asyncio
async def test_azure_realtime_agent():
async with (
RealtimeModel.with_azure(
azure_deployment="gpt-realtime",
azure_endpoint="https://yourendpoint.azure.com",
api_version="2024-10-01-preview",
api_key="your-api-key",
modalities=["text"] # Important for testing
) as rt_llm,
AgentSession(llm=rt_llm, userdata=userdata) as sess,
):
await sess.start(YourAgent(userdata=userdata))
result = await sess.run(user_input="...")
1. Be sure to configure your Azure parameters correctly, like this:
RealtimeModel.with_azure(
azure_deployment="gpt-realtime",
azure_endpoint="https://yourendpoint.azure.com",
api_version="2024-10-01-preview",
api_key="your-api-key",
modalities=["text"]
)
1. For security, it’s best to use environment variables for sensitive info such as:
• AZURE_OPENAI_ENDPOINT for your Azure endpoint
• AZURE_OPENAI_API_KEY for your API key
• OPENAI_API_VERSION for the API version
1. If you encounter warnings that you want to suppress during testing, you can add:
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)
warnings.filterwarnings("ignore", category=ResourceWarning)
If you have any questions or need a hand with any of these steps, please don’t hesitate to reach out—I’m here to help!
Sources: Using the Testing Framework with Realtime Models | livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/real... | Testing and evaluation | LiveKit Docsbetter-sandwich-65834
10/22/2025, 8:20 AMtall-airline-16756
10/22/2025, 8:21 AMinput_audio_transcription parameter needs to be an instance of the InputAudioTranscription class when you're working with the 2024-10-01-preview API version. Don’t worry, I’m here to help you fix it! Here’s what you can do:
1. First, make sure you’re importing the right class:
from openai.types.beta.realtime.session import InputAudioTranscription
1. Next, when setting up your model, use the InputAudioTranscription class like this:
model = RealtimeModelBeta(
azure_endpoint="https://yourendpoint.azure.com",
api_version="2024-10-01-preview",
api_key="your-api-key",
input_audio_transcription=InputAudioTranscription(
model="whisper-1" # Use whisper-1 for Azure
),
# ... other parameters
)
1. If you’d rather keep things simple, you can also leave out the input_audio_transcription parameter altogether:
model = RealtimeModelBeta(
azure_endpoint="https://yourendpoint.azure.com",
api_version="2024-10-01-preview",
api_key="your-api-key"
)
Please feel free to reach out if anything’s unclear or if you want me to walk you through it step-by-step. I’m happy to help!
Sources: livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/real...