{"record":{"id":"170656cda08754c1","repo":"vercel/ai","slug":"failed-to-fetch-chat-response-status-await-r","errorCode":null,"errorMessage":"Failed to fetch chat: ${response.status} ${await response.text()}","messagePattern":"Failed to fetch chat: (.+?) (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/workflow/src/workflow-chat-transport.ts","lineNumber":318,"sourceCode":"          api: this.api,\n          trigger,\n          messageId,\n        })\n      : undefined;\n\n    const url = requestConfig?.api ?? this.api;\n    const response = await this.fetch(url, {\n      method: 'POST',\n      body: JSON.stringify(\n        requestConfig?.body ?? { messages, ...options.body },\n      ),\n      headers: requestConfig?.headers,\n      credentials: requestConfig?.credentials,\n      signal: abortSignal,\n    });\n\n    if (!response.ok || !response.body) {\n      throw new Error(\n        `Failed to fetch chat: ${response.status} ${await response.text()}`,\n      );\n    }\n\n    const workflowRunId = response.headers.get('x-workflow-run-id');\n    if (!workflowRunId) {\n      throw new Error(\n        'Workflow run ID not found in \"x-workflow-run-id\" response header',\n      );\n    }\n\n    // Notify the caller that the chat POST request was sent.\n    // This is useful for tracking the chat history on the client\n    // side and allows for inspecting response headers.\n    await this.onChatSendMessage?.(response, options);\n\n    // Flush the initial stream until the end or an error occurs\n    try {","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/workflow/src/workflow-chat-transport.ts#L300-L336","documentation":"WorkflowChatTransport.sendMessagesIterator performs a POST to the chat endpoint and throws if the HTTP response is not ok or has no body, embedding the status code and response text. It signals that the server rejected the message-send request.","triggerScenarios":"POST to the chat API returns a non-2xx status (401 unauthorized, 404 wrong route, 500 server error) or an empty body; network proxy returns an error page; server route not implemented.","commonSituations":"Missing/misconfigured auth so the server returns 401/403; chat API route path mismatch; server crashed mid-request; CORS or gateway returning 5xx.","solutions":["Check the status code and response text in the error message to identify the server-side cause.","Verify authentication headers/credentials (requestConfig.headers) are sent.","Confirm the chat API endpoint URL and route handler exist and return an SSE/stream body.","Inspect server logs for the corresponding request error."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// no pre-call check possible for server response; ensure endpoint exists:\n// fetch(chatUrl, { method: 'HEAD' }) to verify route availability and auth before POST","typeGuard":null,"tryCatchPattern":"try {\n  await transport.sendMessages({ chatId, messages });\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Failed to fetch chat:')) {\n    const status = parseInt(e.message.match(/\\d{3}/)?.[0] ?? '0', 10);\n    if (status === 401 || status === 403) fixAuth();\n    else if (status >= 500) scheduleRetry();\n  } else throw e;\n}","preventionTips":["Verify auth headers/credentials are configured on the transport.","Confirm the chat API route exists and returns a stream body.","Check CORS/proxy configuration that could strip the response body.","Monitor server logs for 5xx on the chat endpoint."],"tags":["network","http","transport"],"backgroundTag":"http-request-failed","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}