colossal-rose-18633
11/01/2025, 4:56 PMtall-airline-16756
11/01/2025, 4:56 PMtall-airline-16756
11/01/2025, 4:56 PMcolossal-rose-18633
11/01/2025, 5:09 PMtall-airline-16756
11/01/2025, 5:10 PMllm = openai.LLM(model="gpt-4.1", temperature=0.3)
With this configuration:
from livekit.plugins.openai import LLM
llm = LLM.with_azure(
model="gpt-4.1",
azure_endpoint="https://your-azure-endpoint.openai.azure.com",
api_key="your-azure-api-key",
api_version="2024-05-01-preview",
azure_deployment="your-gpt-4-1-deployment-name"
)
Just a couple of important things to double-check:
• Make sure you’ve deployed the GPT-4.1 model in your Azure OpenAI resource.
• Confirm that the azure_endpoint, api_key, and azure_deployment values exactly match your Azure setup.
• You can also use environment variables like AZURE_OPENAI_API_KEY and AZURE_OPENAI_ENDPOINT for authentication and endpoint settings, if that’s easier for you.
If you have any questions or need a hand with anything else, just let me know—I’m here to help!
Sources: plugins/openai/src/llm.ts | examples/voice_agents/realtime_load_chat_history.py | OpenAI LLM models | LiveKit Docs | Build voice, video, and physical AI | LiveKit | Large language models (LLM) | LiveKit Docscolossal-rose-18633
11/01/2025, 5:14 PMtall-airline-16756
11/01/2025, 5:14 PMmax_completion_tokens parameter. Here’s a little example to help you include it in your configuration:
from livekit.plugins.openai import LLM
llm = LLM.with_azure(
model="gpt-4.1",
azure_endpoint="https://your-azure-endpoint.openai.azure.com",
api_key="your-azure-api-key",
api_version="2024-05-01-preview",
azure_deployment="your-gpt-4-1-deployment-name",
max_completion_tokens=500 # Set the maximum number of tokens in the response
)
If you have any questions or need a hand with anything else, just let me know—I’m here to help!
Sources: tests/test_config.py | OpenAI LLM models | LiveKit Docs | Build voice, video, and physical AI | LiveKit | DeepSeek LLM | LiveKit Docscolossal-rose-18633
11/01/2025, 5:24 PMtall-airline-16756
11/01/2025, 5:24 PMazure_endpoint parameter should be a string, but a tuple was passed instead. This causes the rstrip method to fail when building the URL. Let’s work through this together to get it sorted out:
1. First, double-check the value and type of azure_endpoint before you pass it to LLM.with_azure. You can do this with:
import os
endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
print(f"Type: {type(endpoint)}, Value: {endpoint}")
1. Make sure that azure_endpoint is indeed a properly formatted string URL. If you’re using environment variables, please verify that AZURE_OPENAI_ENDPOINT is set correctly and isn’t accidentally being wrapped or parsed as a tuple somewhere in your setup.
2. It’s also a good idea to confirm the type of azure_endpoint right before calling with_azure like this:
if not isinstance(azure_endpoint, str):
raise TypeError(f"azure_endpoint must be a string, got {type(azure_endpoint)}")
If you run into any other questions or need a hand walking through these steps, please don’t hesitate to reach out—I’m here to help!
Sources: livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/__init__.py | Azure OpenAI LLM plugin guide | LiveKit docscolossal-rose-18633
11/01/2025, 5:55 PMtall-airline-16756
11/01/2025, 5:55 PMLLM.with_azure method doesn’t directly support the max_completion_tokens parameter. But don’t worry, you can still include this parameter by setting up the LLM class manually instead of using with_azure. Here’s a friendly example to guide you:
from livekit.plugins.openai import LLM
llm_instance = LLM(
model="gpt-4.1",
api_key="your-azure-api-key",
base_url="https://your-azure-endpoint.openai.azure.com/openai/deployments/your-deployment-name",
max_completion_tokens=500, # Set the maximum number of tokens
temperature=0.7
)
If you’re working with the LiveKit Inference service instead, you can pass max_completion_tokens through extra_kwargs like this:
from livekit.agents.inference import LLM as InferenceLLM
llm_instance = InferenceLLM(
model="openai/gpt-4.1",
provider="azureopenai",
extra_kwargs={"max_completion_tokens": 500}
)
Please feel free to reach out if you’d like me to walk you through a full example tailored to your needs or if you have any other questions. I’m here to help!
Sources: livekit-agents/livekit/agents/llm/llm.py | OpenAI LLM models | LiveKit Docs | DeepSeek LLM | LiveKit Docs | Google Gemini LLM | LiveKit Docscolossal-rose-18633
11/02/2025, 5:39 AMtall-airline-16756
11/02/2025, 5:40 AMwithAzure Method (Recommended)
This is the easiest way, as it automatically sets up the Azure OpenAI client for you:
from livekit.plugins.openai import LLM
llm = LLM.with_azure(
model="gpt-4.1",
azure_endpoint="https://neuravoice.openai.azure.com",
api_key="your-azure-api-key",
api_version="2025-01-01-preview",
azure_deployment="gpt-4.1"
)
Method 2: Using Your Custom AzureOpenAI Client
If you already have your AzureOpenAI client set up and prefer to use it, you can easily pass it to LiveKit's LLM class like this:
from livekit.plugins.openai import LLM
from openai import AzureOpenAI
# Your AzureOpenAI client code
client = AzureOpenAI(
azure_endpoint="https://neuravoice.openai.azure.com",
azure_ad_token_provider=token_provider,
api_version="2025-01-01-preview"
)
# Use the client with LiveKit's LLM
llm = LLM(
model="gpt-4.1",
client=client,
temperature=0.7
)
Environment Variables
Both methods also support automatic configuration through environment variables, which can make your setup even smoother:
AZURE_API_KEY=your-azure-api-key
AZURE_OPENAI_ENDPOINT=https://neuravoice.openai.azure.com
OPENAI_API_VERSION=2025-01-01-preview
If you’d like, I’m here to help with a complete example tailored to your needs or to answer any other questions you might have!
Sources: plugins/openai/src/llm.ts | OpenAI LLM models | LiveKit Docs | Build voice, video, and physical AI | LiveKit | OpenAI and LiveKit | LiveKit Docs