createOpenAiTextStream (openai/sse.ts)

summarize · src/llm/providers/openai/sse.ts · typescript · MIT
ai

Module exposing: createOpenAiTextStream, createOpenAiSseError, createDeferredUsage

// Source: https://github.com/steipete/summarize | License: MIT | Copyright 2026 Peter Steinberger
// Provided via justclaw.it.com; keep this notice with the code.
import { parseSseStream } from "@steipete/summarize-core/runtime";
import type { LlmTokenUsage } from "../../types.js";
import type { OpenAiTextStreamResult } from "./types.js";

export function createOpenAiTextStream(
  response: Response,
  modelId: string,
  readEvent: (
    event: Record<string, unknown>,
  ) => { text?: string; usage?: LlmTokenUsage | null; terminal?: boolean } | null,
  missingTerminalError: string,
): OpenAiTextStreamResult {
  const body = response.body;
  if (!body) throw new Error("OpenAI stream response was empty.");
  const usage = createDeferredUsage();
  const textStream = {
    async *[Symbol.asyn

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key