{"record":{"id":"d3ec177d9f7a6f0a","repo":"mastra-ai/mastra","slug":"mastra-livekit-mastra-agent-stream-request-faile","errorCode":null,"errorMessage":"@mastra/livekit: Mastra agent stream request failed with status ${response.status}","messagePattern":"@mastra/livekit: Mastra agent stream request failed with status (.+?)","errorType":"http","errorClass":"APIStatusError","httpStatus":null,"severity":"error","filePath":"integrations/livekit/src/remote.ts","lineNumber":261,"sourceCode":"                timedOut = true;\n                abortController.abort();\n              }, timeoutMs);\n              (watchdog as { unref?: () => void }).unref?.();\n\n              const resolvedHeaders = await resolveHeaders(headers);\n              if (cancelled) {\n                clearWatchdog();\n                break;\n              }\n              const response = await fetchImpl(url, {\n                method: 'POST',\n                headers: { 'content-type': 'application/json', accept: 'text/event-stream', ...resolvedHeaders },\n                body: JSON.stringify(requestBody),\n                signal: abortController.signal,\n              });\n              if (!response.ok) {\n                const errorBody = await safeReadBody(response);\n                throw new APIStatusError({\n                  message: `@mastra/livekit: Mastra agent stream request failed with status ${response.status}`,\n                  options: { statusCode: response.status, body: errorBody, retryable },\n                });\n              }\n              if (!response.body) {\n                throw new APIConnectionError({\n                  message: '@mastra/livekit: Mastra agent stream returned an empty response body',\n                  options: { retryable },\n                });\n              }\n\n              for await (const chunk of readMastraSSE(\n                response.body as unknown as globalThis.ReadableStream<Uint8Array>,\n                abortController.signal,\n              )) {\n                if (cancelled) break;\n                // First chunk: the server has committed to this generation — forbid any further\n                // retry so the turn can't be replayed mid-stream. The watchdog is NOT cleared here:","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/integrations/livekit/src/remote.ts#L243-L279","documentation":"The remote reply generator streamed from the Mastra server endpoint `/agents/:agentId/stream` and received a non-2xx HTTP status. It wraps the failure in APIStatusError with the status code, the (safely read) response body, and a retryable hint, so callers/retry logic can decide what to do.","triggerScenarios":"The POST to the Mastra agent stream endpoint returns 404 (wrong agentId or baseUrl), 401/403 (bad or missing auth headers), 500 (server-side failure), or any other non-ok response.","commonSituations":"Misconfigured MASTRA_URL/agentId after a deploy; missing auth headers for a protected server; Mastra server down or crashing on that route; server/client API version mismatch.","solutions":["Read the `body` on the APIStatusError — it contains the server's error detail identifying the real cause.","Verify baseUrl and agentId point to a running Mastra server exposing /agents/:agentId/stream.","Check auth headers/credentials passed to the remote options if the status is 401/403.","If retryable is true, retry with backoff; otherwise fix the underlying 4xx configuration error.","Check Mastra server logs for the corresponding request failure."],"exampleFix":"// before\nremote: { baseUrl: 'https://prod.example.com', agentId: 'assistant-v1' } // agent renamed on server\n// after\nremote: { baseUrl: 'https://prod.example.com', agentId: 'assistant' }","handlingStrategy":"retry","validationCode":"async function assertAgentStreamReachable(baseUrl, agentId, headers) {\n  const res = await fetch(`${baseUrl.replace(/\\/$/, '')}/agents/${agentId}/stream`, { method: 'HEAD' }).catch(() => null);\n  if (!res || res.status === 404) throw new Error(`Agent stream endpoint unreachable for agentId=${agentId} at ${baseUrl}`);\n}\n// call before wiring the remote generator","typeGuard":null,"tryCatchPattern":"try {\n  const reply = await generateReply();\n} catch (e) {\n  if (e instanceof APIStatusError) {\n    console.error(`Mastra stream failed: ${e.status}`, e.body);\n    if (e.retryable && attempt < 3) return retryWithBackoff();\n    if (e.status === 401 || e.status === 403) refreshAuthHeaders();\n    if (e.status === 404) verifyAgentIdAndBaseUrl();\n  }\n  throw e;\n}","preventionTips":["Log the APIStatusError body — it contains the server-side cause.","Keep agentId/baseUrl in one config source shared with the Mastra server deploy.","Alert on 5xx rates from the /agents/:id/stream route.","Add an integration test hitting the stream endpoint in CI."],"tags":["network","http","streaming","livekit","mastra-server"],"backgroundTag":"http-request-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}