Workers API
Pipelines exposes an API directly to your Workers scripts via the bindings concept. Bindings allow you to securely send data to a Pipeline without having to manage API keys or clients. Sending data via a Worker is enabled by default.
Bind to a pipeline by defining a pipelines
binding within your Wrangler configuration. For example:
#:schema node_modules/wrangler/config-schema.jsonname = "pipeline-starter"main = "src/index.ts"compatibility_date = "2025-04-01"
[[pipelines]]pipeline = "<MY-PIPELINE-NAME>" # The name of your Pipelinebinding = "MY_PIPELINE" # The binding name, accessed using env.MY_PIPELINE
{ "name": "pipeline-starter", "main": "src/index.ts", "compatibility_date": "2025-04-01", "pipelines": [ { "pipeline": "<MY-PIPELINE-NAME>", "binding": "MY_PIPELINE" } ]}
You can bind multiple pipelines to a Worker.
The pipelines binding exposes a send()
method. For example, to log inbound HTTP requests to your Worker:
export default { async fetch(request, env, ctx): Promise<Response> { let log = { url: request.url, method: request.method, headers: Object.fromEntries(request.headers), }; await env.PIPELINE.send([log]); return new Response('Hello World!'); },} satisfies ExportedHandler<Env>;
Pipelines accept arrays of valid JSON objects. You can send multiple objects in a single request, provided the total data volume is within the documented limits. Sending data in a different format will result in an error.
By default, ingestion via a Worker is turned on. You can turn it off by excluding it from the list of sources, by using --sources
when creating or updating a pipeline.
$ npx wrangler pipelines create [PIPELINE-NAME] --r2-bucket [R2-BUCKET-NAME] --sources http
A binding which allows a Worker to send messages to a Pipeline.
interface Pipeline<PipelineRecord> { send(records: PipelineRecord[]): Promise<void>;}
-
send(records)
:Promise<void>
- Sends a record to the Pipeline. The body must be an array of objects which are JSON serializable.
- When the promise resolves, the message is confirmed to be stored by the pipeline.