Writing to streams
Send events to streams using Worker bindings or HTTP endpoints for client-side applications and external systems.
Worker bindings provide a secure way to send data to streams from Workers without managing API tokens or credentials.
Add a pipeline binding to your Wrangler file that points to your stream:
{ "pipelines": [ { "pipeline": "<STREAM_ID>", "binding": "STREAM" } ]}[[pipelines]]pipeline = "<STREAM_ID>"binding = "STREAM"The pipeline binding exposes a method for sending data to your stream:
Sends an array of JSON-serializable records to the stream. Returns a Promise that resolves when records are confirmed as ingested.
export default { async fetch(request, env, ctx) { const events = await request.json();
await env.STREAM.send(events);
return new Response("Events sent"); },};export default { async fetch(request, env, ctx): Promise<Response> { const events = await request.json<Record<string, unknown>[]>();
await env.STREAM.send(events);
return new Response("Events sent"); },} satisfies ExportedHandler<Env>;When a stream has a defined schema, running wrangler types generates schema-specific TypeScript types for your pipeline bindings. Instead of the generic Pipeline<PipelineRecord>, your bindings get a named record type with full autocomplete and compile-time type checking. Refer to the wrangler types documentation to learn more.
After running wrangler types, the generated worker-configuration.d.ts file contains a named record type inside the Cloudflare namespace. The type name is derived from the stream name (not the binding name), converted to PascalCase with a Record suffix.
Below is an example of what generated types look like in worker-configuration.d.ts for a stream named ecommerce_stream:
declare namespace Cloudflare { type EcommerceStreamRecord = { user_id: string; event_type: string; product_id?: string;