Edit

transport

Environment: client.

BetaTelefunc Stream is in beta: breaking changes may occur in any version update.

Telefunc has two transport settings that control which network protocol is used to deliver messages:

SettingControls
config.stream.transportStreaming (AsyncGenerator, ReadableStream, Promise)
config.channel.transportsnew Channel() (new BroadcastChannel(), callbacks)

These settings only affect streams — plain telefunction calls are always text/plain JSON.

// Environment: client
 
import { config } from 'telefunc/client'
 
config.stream.transport = 'binary-inline' // default
config.channel.transports = ['sse', 'ws'] // default

These are client-side configs — separate from the following server-side settings:

You can define client-side configs (import { config } from 'telefunc/client') anywhere, just make sure to do it at global client-side code that is always executed. For example /pages/+client.js if you use Vike:

// /pages/+client.js
// Environment: client
 
import { config } from 'telefunc/client'
 
// Config values can be set here
config.someClientSideSetting = 'some-value'
// /pages/+client.ts
// Environment: client
 
import { config } from 'telefunc/client'
 
// Config values can be set here
config.someClientSideSetting = 'some-value'

Stream transport

Controls how streaming values are delivered over HTTP.

TransportContent-TypeDescription
'binary-inline' (default)application/octet-streamRaw binary chunked response. Lowest overhead.
'sse-inline'text/event-streamBase64url-encoded SSE. Works through proxies that buffer binary responses.
'channel'text/plain + channelStarts over HTTP, then continues over the configured channel transport.

Comparison

ThroughputProxy/CDNRecoverySetup
'binary-inline'🟡None
'sse-inline'🟡None
'channel' (SSE)🟡None
'channel' (WS)🟡Server setup

✅ good · 🟡 partial / caveats · ❌ none

When to use what

  • Start with 'binary-inline' — it's the fastest and works in most setups.
  • Switch to 'sse-inline' if a proxy or CDN buffers binary HTTP responses but passes SSE events through without buffering.
  • Use 'channel' when you want streamed values to reconnect automatically after a dropped connection (just as Telefunc channels do).

Channel transport

Set the network protocol used by new Channel(), new BroadcastChannel(), and stream primitives that use channels under the hood.

TransportDescription
'sse'HTTP requests + SSE stream.
No extra server setup: works with both new Telefunc() and serve().
'ws'Multiplexed WebSocket.
Extra server setup: works only with new Telefunc() (it supports WebSocket whereas serve() doesn't).

The client default is ['sse', 'ws'] — start on SSE, then upgrade to WebSocket if possible. SSE is supported out-of-the-box, while WebSocket is supported if you set up your server via new Telefunc() (instead of serve()).

The client starts on SSE and upgrades to WebSocket in the background.

All channels share a single multiplexed connection per server URL, so opening many channels doesn't open many connections.

Comparison

ThroughputRecoveryProxy/CDNServer setup
'sse'🟡None
'ws'🟡WebSocket

✅ good · 🟡 partial / caveats

When to use what

  • Start with 'sse' — it works everywhere out-of-the-box.
  • Use 'ws' for high-frequency, real-time traffic that benefits from a full-duplex connection.
GoalConfig
Best defaultconfig.stream.transport = 'binary-inline'
Proxy buffers binaryconfig.stream.transport = 'sse-inline'
Reconnectionconfig.stream.transport = 'channel'
Channels without WSconfig.channel.transports = ['sse']
Full-duplex channelsconfig.channel.transports = ['sse', 'ws']

Per-call overrides

Override transport for a single call (instead of globally) with withContext():

// Environment: client
 
import { onAIChat } from './Chat.telefunc'
import { withContext } from 'telefunc/client'
 
const call = withContext(onAIChat, {
  stream: { transport: 'channel' },  // override config.stream.transport
  channel: { transports: ['ws'] },   // override config.channel.transports
})
 
const gen = call('Tell me a joke')
for await (const message of gen) {
  console.log(message)
}

See also