Open History to see the last commit
1---
2id: toHttpResponse
3title: toHttpResponse
4---
5
6# Function: toHttpResponse()
7
8```ts
9function toHttpResponse(stream, init?): Response;
10```
11
12Defined in: [packages/typescript/ai/src/stream-to-response.ts:240](https://github.com/TanStack/ai/blob/main/packages/typescript/ai/src/stream-to-response.ts#L240)
13
14Convert a StreamChunk async iterable to a Response in HTTP stream format (newline-delimited JSON)
15
16This creates a Response that emits chunks in HTTP stream format:
17- Each chunk is JSON.stringify'd and followed by "\n"
18- No SSE formatting (no "data: " prefix)
19
20This format is compatible with `fetchHttpStream` connection adapter.
21
22## Parameters
23
24### stream
25
26`AsyncIterable`\<[`AGUIEvent`](../type-aliases/AGUIEvent.md)\>
27
28AsyncIterable of StreamChunks from chat()
29
30### init?
31
32`ResponseInit` & `object`
33
34Optional Response initialization options (including `abortController`)
35
36## Returns
37
38`Response`
39
40Response in HTTP stream format (newline-delimited JSON)
41
42## Example
43
44```typescript
45const stream = chat({ adapter: openaiText(), model: "gpt-4o", messages: [...] });
46return toHttpResponse(stream, { abortController });
47```