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
- 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/...).
- Key changes:
- Use the exact query params from 2025-10-01 API version docs (wss://your-resource.services.ai.azure.com/voice-live/realtime):
- Add Agent Access Token (Entra ID Auth):
- API key alone isn't sufficient for agent integration—generate Entra token for
https://ai.azure.com/.defaultscope. - 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).
- Replace:
- API key alone isn't sufficient for agent integration—generate Entra token for
- 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.
- 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.
- Install 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