{"record":{"id":"70fea231bb638ee8","repo":"vercel/ai","slug":"the-response-body-is-empty-70fea2","errorCode":null,"errorMessage":"The response body is empty.","messagePattern":"The response body is empty\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/svelte/src/structured-object.svelte.ts","lineNumber":178,"sourceCode":"      const response = await actualFetch(this.#options.api, {\n        method: 'POST',\n        headers: {\n          'Content-Type': 'application/json',\n          ...this.#options.headers,\n        },\n        credentials: this.#options.credentials,\n        signal: abortController.signal,\n        body: JSON.stringify(input),\n      });\n\n      if (!response.ok) {\n        throw new Error(\n          (await response.text()) ?? 'Failed to fetch the response.',\n        );\n      }\n\n      if (response.body == null) {\n        throw new Error('The response body is empty.');\n      }\n\n      let accumulatedText = '';\n      let latestObject: DeepPartial<RESULT> | undefined = undefined;\n\n      await response.body.pipeThrough(new TextDecoderStream()).pipeTo(\n        new WritableStream<string>({\n          write: async chunk => {\n            if (abortController?.signal.aborted) {\n              throw new DOMException('Stream aborted', 'AbortError');\n            }\n            accumulatedText += chunk;\n\n            const { value } = await parsePartialJson(accumulatedText);\n            const currentObject = value as DeepPartial<RESULT>;\n\n            if (!isDeepEqualData(latestObject, currentObject)) {\n              latestObject = currentObject;","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/svelte/src/structured-object.svelte.ts#L160-L196","documentation":"The Svelte structured-object client checks response.body after a successful status; if the response has no readable stream body it throws 'The response body is empty.'. The library expects a streamed JSON response to incrementally parse into a partial object.","triggerScenarios":"The fetch resolves with !response.ok false but response.body === null — e.g. HTTP 204 responses, opaque/no-store contexts, or environments without streaming response bodies (some runtimes/polyfills).","commonSituations":"Endpoint returns 204 No Content or an empty-body redirect; running in an environment where Response.body is not implemented; a misconfigured proxy that strips the body.","solutions":["Make the API endpoint return a streamed body (200 with content).","Check for 204/redirect responses from your route and fix the handler.","Run in a runtime that supports streaming Response.body (modern browsers/Node 18+).","Add a server-side check that the structured-generation handler actually streams the result."],"exampleFix":"// before (endpoint)\nreturn new Response(null, { status: 204 });\n// after\nreturn new Response(JSON.stringify(resultStream), { status: 200 });","handlingStrategy":"validation","validationCode":"// server-side guard\nexport function POST() {\n  const body = buildStructuredStream();\n  if (!body) return new Response('no body', { status: 500 });\n  return new Response(body, { status: 200 });\n}","typeGuard":"null","tryCatchPattern":"try {\n  startGeneration();\n} catch (e) {\n  if (e?.message === 'The response body is empty.') {\n    console.error('Endpoint returned no stream body — check the API handler.');\n  } else throw e;\n}","preventionTips":["Ensure the endpoint returns 200 with a body.","Avoid 204/empty responses from generation routes.","Test the route with curl to confirm a streamed body.","Use a runtime supporting streaming Response.body."],"tags":["http","fetch","streaming","svelte"],"backgroundTag":"empty-response-body","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}