wrangler K2 producer bindings write to existing streams
Introduced 2026-09-30 · score 0.92
HOW TO USE IT
When producing events from a Worker to an existing K2 stream, add its ID and a binding name under `k2` in Wrangler config, then call `env.<BINDING>.send(records)` and check `result.success`.
{
"k2": [
{
"binding": "<BINDING>",
"stream": "<32-character-lowercase-hex-stream-id>"
}
]
}const result = await env.<BINDING>.send([
{
content: new TextEncoder().encode("<EVENT_PAYLOAD>"),
headers: { event: "<EVENT_NAME>" }
}
]);
if (!result.success) {
console.error(`Produce failed: ${result.error.message}`);
}npx wrangler typesWHY THIS HELPS
Configure a Worker to produce events to an existing K2 stream during development or deployment.
REQUIREMENTS AND LIMITATIONS
- Version: 4.145.0
- Availability: Beta
- k2[].binding (required): Worker variable name for the binding, such as `env.ORDERS`.
- k2[].stream (required): 32 lowercase hexadecimal stream ID; stream must be in the same account as the Worker.
- send(records)[].content (required): Record payload as `ArrayBuffer` or `Uint8Array`; all records in a batch must use the same type.
- send(records)[].headers: Metadata map with string keys and string values.
- Prerequisite: K2 is available on the Workers Paid plan; it is in public beta.
- Prerequisite: The K2 Workers binding input must be enabled on the stream; it is enabled by default when omitted at stream creation.
- Prerequisite: Run `npx wrangler types` after adding the binding to generate the Env type.
- K2 requires an enabled account.
- Deployment credentials need Worker deployment and K2 configuration-read access.
- Existing OAuth users should run `wrangler login` again to grant the new permissions.
- Development always uses a real K2 stream and may incur usage charges; no local simulator is provided.
- Batches use either all `ArrayBuffer` or all `Uint8Array` content.
- Check the returned `success` value, handle rejected RPC promises, and retry only when the returned error explicitly allows it.
- `remote: false` is rejected.
- Consumption is not part of this Worker binding.
FIRST-PARTY EVIDENCE
- https://github.com/cloudflare/workers-sdk/releases/tag/wrangler%404.145.0
- https://developers.cloudflare.com/k2/features/produce/
- https://developers.cloudflare.com/k2/
- https://developers.cloudflare.com/k2/configuration/
Check the installed version and the source before using it. Entry JSON