OpenrouterSdk.Streaming (OpenRouter SDK v0.1.0)

Copy Markdown View Source

shared sink semantics for *_stream apis.

consumers can opt into three sinks via :into:

  • default (no :into) — {:ok, stream}, lazy Stream.
  • :into is a pid — events are forwarded as {:openrouter_event, ref, event}; returns {:ok, ref}.
  • :into is a fun/2 — runs Enum.reduce/3 for the consumer with acc: opts[:acc] || []; returns {:ok, acc}.

the streaming function is passed as a thunk so we can decide whether to invoke it inline or inside a separate task — this matters because the underlying stream reads from the mailbox of whichever process opened it.

Summary

Types

start_fn()

@type start_fn() :: (-> {:ok, Enumerable.t()} | {:error, term()})

Functions

wrap(start_fn, opts)

@spec wrap(
  start_fn(),
  keyword()
) :: {:ok, Enumerable.t() | reference() | term()} | {:error, term()}