Skip to content

WorkerEntrypoint

Source: src/Cloudflare/Workers/WorkerEntrypoint.ts

Bind a specific WorkerEntrypoint class exported by another Worker.

Binding a Worker directly in env (env: { TARGET: worker }) targets its default entrypoint. A Worker that exposes additional WorkerEntrypoint classes — workerd treats every named class export of an entry module as an entrypoint — is bound with WorkerEntrypoint, which selects the class by name and can deliver ctx.props to it.

The target Worker exports a WorkerEntrypoint class alongside its default handler; the consumer selects it by name. InferEnv types the binding as a Fetcher service stub — RPC methods are called on it directly.

target/src/worker.ts
import { WorkerEntrypoint } from "cloudflare:workers";
export class Api extends WorkerEntrypoint {
async greet(name: string): Promise<string> {
return `hello ${name}`;
}
}
export default { async fetch() { return new Response("ok"); } };
alchemy.run.ts
const target = yield* Cloudflare.Worker("Target", { main: "./target/src/worker.ts" });
const caller = yield* Cloudflare.Worker("Caller", {
main: "./caller/src/worker.ts",
env: {
API: Cloudflare.WorkerEntrypoint(target, "Api"),
},
});

The options form attaches properties the target reads from this.ctx.props — workerd’s per-binding configuration channel. Output values resolve at deploy time.

env: {
VENDOR: Cloudflare.WorkerEntrypoint(vendorWorker, {
entrypoint: "Vendor",
props: { baseUrl: site.url },
}),
}