How we get ad token? Overview <Azure OpenAI> pro...
# ask-ai
f
How we get ad token? Overview Azure OpenAI provides OpenAI services hosted on Azure. With LiveKit's Azure OpenAI TTS integration and the Agents framework, you can build voice AI applications that sound realistic and natural. To learn more about TTS and generating agent speech, see Agent speech. Quick reference This section includes a basic usage example and some reference material. For links to more detailed documentation, see Additional resources. Installation Support for Azure OpenAI TTS is available in the
openai
plugin. Install the plugin from PyPI:
Copy code
pip install "livekit-agents[openai]~=1.0"
Authentication The Azure OpenAI TTS requires authentication using an API key or a managed identity. Set the following environment variables in your
.env
file:
Copy code
AZURE_OPENAI_API_KEY=<azure-openai-api-key>
AZURE_OPENAI_AD_TOKEN=<azure-openai-ad-token>
AZURE_OPENAI_ENDPOINT=<azure-openai-endpoint>
Usage Use Azure OpenAI TTS within an
AgentSession
or as a standalone speech generator. For example, you can use this TTS in the Voice AI quickstart.
Copy code
from livekit.plugins import openai

session = AgentSession(
   tts=openai.TTS.with_azure(
      model="gpt-4o-mini-tts",
      voice="coral",
   )
   # ... llm, stt, etc.
)
t
Thanks for reaching out, Baymurat. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To obtain an Azure OpenAI AD token for LiveKit integration, follow these steps: 1. Create an Azure OpenAI Resource: Set up an Azure OpenAI resource in the Azure Portal to get your API key and endpoint. 2. Register an Azure AD Application: In Azure Active Directory, register a new application under "App Registrations" and note the Application (client) ID and Directory (tenant) ID. 3. Create a Client Secret: Add a new client secret under "Certificates & secrets" in your application and copy the secret value immediately. 4. Assign Permissions: Grant the application permissions like _user_impersonation_ for Azure OpenAI and ensure it has access to your OpenAI resource. 5. Generate the Azure AD Token: Use the client ID, client secret, and tenant ID to authenticate and obtain an access token via OAuth 2.0 endpoints or tools like Postman. 6. Configure LiveKit: Set the environment variable
AZURE_OPENAI_AD_TOKEN
with the obtained token. Ensure the token has the necessary permissions and is securely handled. For more details, refer to Azure's official documentation on obtaining an AD token.
f
should I provider this token as well? AZURE_OPENAI_AD_TOKEN=<azure-openai-ad-token> if I am already providing API key?
t
Just a quick heads-up: if you’re already using an API key for your Azure OpenAI setup, you don’t need to worry about the
AZURE_OPENAI_AD_TOKEN
. You can use either the API key or the Active Directory token to sign in—no need for both. Hope that helps! Sources: Azure OpenAI STT integration guide | LiveKit Docs