how i can setup RealtimeModel.with_azure to test i...
# ask-ai
b
how i can setup RealtimeModel.with_azure to test in using pytest
t
Thanks for reaching out, Aleh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To help you get started with setting up
RealtimeModel.with_azure
for testing using pytest, here’s a simple step-by-step guide: 1. First, make sure you have the necessary packages installed:
Copy code
pip install pytest pytest-asyncio
1. Next, you can use this test pattern that includes an agent session context manager to keep things organized:
Copy code
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:
Copy code
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:
Copy code
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 Docs
b
i get raise ValueError(\nValueError: input_audio_transcription must be an instance of InputAudioTranscription for api-version 2024-10-01-preview", "level": "ERROR", "name": "livekit.agents", "pid": 76945, "job_id": "AJ_LKQATSvn4Ynx", "timestamp": "2025-10-20T082609.695145+00:00"}
t
It looks like this error pops up because the
input_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:
Copy code
from openai.types.beta.realtime.session import InputAudioTranscription
1. Next, when setting up your model, use the
InputAudioTranscription
class like this:
Copy code
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:
Copy code
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...