earendil-works/pi · error · Error

response has no body

Error message

${model.provider} response has no body

What it means

The provider responded to the SSE request with an HTTP body of null, so there is no byte stream to read events from. Fires when the gateway returns a bodyless response (e.g. a proxy or keep-alive artifact) despite an OK status.

Solutions

  1. Retry; verify the provider endpoint returns a response body.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at packages/ai/src/api/pi-messages.ts:401 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of earendil-works/pi@4af9d21d3b (2026-08-24). Data as JSON: /api/errors/d0beb680017705be. Report an issue: GitHub.

Appendix: source

Thrown at packages/ai/src/api/pi-messages.ts:401

				method: "POST",
				headers: {
					authorization: `Bearer ${apiKey}`,
					accept: "text/event-stream",
					"content-type": "application/json",
					...providerHeadersToRecord(options?.headers),
				},
				body: JSON.stringify(payload),
				signal: options?.signal,
			});

			await options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model);

			if (!response.ok) {
				const body = await response.text();
				throw createPiMessagesResponseError(model, url, response, body);
			}
			if (!response.body) {
				throw new Error(`${model.provider} response has no body`);
			}

			for await (const piEvent of readPiMessagesEvents(response.body)) {
				const event = convertEvent(piEvent);
				eventStream.push(event);
				if (event.type === "done" || event.type === "error") {
					return;
				}
			}

			throw new Error(`${model.provider} stream ended without a terminal event`);
		} catch (error) {
			eventStream.push(createErrorEvent(model, error, options?.signal?.aborted ?? false));
		}
	})();

	return eventStream;
};

View on GitHub (pinned to 4af9d21d3b)