I am trying to connect azure voice live web socket api from my frontend and i am integrating ai foundry agent with it

Vishal Rawat 40 Reputation points
2025-11-14T11:52:51.57+00:00

I am trying to connect azure voice live web socket api from my frontend and i am integrating ai foundry agent with it. The url i am using is wss://name-resource.services.ai.azure.com/voice-live/realtime?api-version=2025-10-01&agent_id=asst_agentid&api-key=api_key&project_name=name
The web socket connection is successful but then its getting disconnected with this error -
{"event_id":"event_6BWYRNV1zUWapTZtyqvcS2","type":"error","error":{"message":"Missing required agent connection string or project name","type":"invalid_request_error","code":"invalid_request_error","param":null,"event_id":null}}

Help me with this issue.

Azure AI Speech
Azure AI Speech
An Azure service that integrates speech processing into apps and services.
{count} votes

Answer accepted by question author
  1. Jerald Felix 9,835 Reputation points
    2025-11-16T16:56:52.43+00:00

    Hello Vishal Rawat,

    The WebSocket connection succeeding but disconnecting with "Missing required agent connection string or project name" error in your Azure Voice Live API call (integrated with AI Foundry agent) indicates the query parameters are incomplete or incorrectly formatted—Voice Live requires both agent_id and project_name (not project_name as in your URL; it's project_id or project_name per docs), plus proper agent access token for authentication when using Foundry agents. The api-key is for basic auth, but agent binding needs Entra ID token in headers or query. Here's the fix:

    Step-by-Step Resolution

    1. Correct WebSocket URL Format:
      • Use the exact query params from 2025-10-01 API version docs (wss://your-resource.services.ai.azure.com/voice-live/realtime):
        
             wss://name-resource.services.ai.azure.com/voice-live/realtime?api-version=2025-10-01&agent_id=your-agent-id&project_id=your-foundry-project-id&api-key=your-api-key
        
        
        • Key changes: agent_id (not agent_id in your URL—hyphen), project_id (standard param; use your AI Foundry project name/ID from portal > AI Foundry > Projects).
        • If custom domain: Replace with your endpoint (e.g., wss://your-custom-domain.ai.azure.com/...).
    2. Add Agent Access Token (Entra ID Auth):
      • API key alone isn't sufficient for agent integration—generate Entra token for https://ai.azure.com/.default scope.
      • Frontend JS (using MSAL.js):
        
             import { PublicClientApplication } from "@azure/msal-browser";
        
             const msalConfig = {
        
               auth: { clientId: "your-client-id", authority: "https://login.microsoftonline.com/your-tenant-id" }
        
             };
        
             const msalInstance = new PublicClientApplication(msalConfig);
        
             async function getAgentToken() {
        
               const accounts = msalInstance.getAllAccounts();
        
               const request = { scopes: ["https://ai.azure.com/.default"] };
        
               const response = await msalInstance.acquireTokenSilent(request);
        
               return response.accessToken;  // Use this for agent binding
        
             }
        
             // Connect WebSocket
        
             const agentToken = await getAgentToken();
        
             const wsUrl = `wss://name-resource.services.ai.azure.com/voice-live/realtime?api-version=2025-10-01&agent_id=your-agent-id&project_id=your-project-id&api-key=${encodeURIComponent(yourApiKey)}`;
        
             const ws = new WebSocket(wsUrl, [], {
        
               headers: { "Authorization": `Bearer ${agentToken}` }  // Pass token in headers
        
             });
        
             ws.onopen = () => console.log("Connected");
        
             ws.onerror = (err) => console.error("Error:", err);  // Check for auth failures
        
             ws.onclose = (event) => console.log("Disconnected:", event.code, event.reason);  // Logs the missing param error
        
        
        • Replace: your-agent-id (from AI Foundry > Agents > Copy ID), your-project-id (from Projects > Copy name/ID).
    3. Verify AI Foundry Agent Setup:
      • Portal > AI Foundry > Your project > Agent > Ensure agent has "Voice enabled" (Preview as of 2025) and published.
      • Permissions: Assign "Azure AI User" role to your app registration (Entra ID > App registrations > Your app > API permissions > Add Cognitive Services > User Impersonation > Grant admin consent).
      • Endpoint: Use resource's full endpoint (Keys and Endpoint > Endpoint URI)—if custom domain, include it.
    4. Test and Debug:
      • Browser DevTools > Network/WebSocket tab: Monitor connection (should show 101 Switching Protocols; errors show 400/403).
      • If "invalid_request_error": Confirm agent_id/project_id exist and match (case-sensitive).
      • cURL Test (for backend validation):
        
             wscat -c "wss://your-resource.services.ai.azure.com/voice-live/realtime?api-version=2025-10-01&agent_id=your-agent-id&project_id=your-project-id&api-key=your-key" --header "Authorization: Bearer your-entra-token"
        
        
        • Install wscat: npm i -g wscat.
      • Logs: Enable diagnostics (Speech resource > Monitoring > Diagnostic settings > Send to Log Analytics) > Query errors.

    This binds the session to your Foundry agent—test the URL params first. For full integration, use the .NET/Python SDK (azure-ai-voicelive) which handles auth/token automatically. If error persists, share your project/agent IDs (redacted) for validation.

    Best Regards,

    Jerald Felix


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.