Alchemy v1 uses async/await with top-level await for
orchestration. Alchemy v2 replaces this with Effect generators for
type-safe error handling, composable retries, and declarative
resource wiring.
Your existing async fetch handlers do not need to change — you
can keep them as-is and still get all the benefits of the new engine.
Your existing Worker runtime code does not need to change. The async
pattern declares bindings on the Worker’s env prop and uses
Cloudflare.InferEnv to type the env object:
alchemy.run.ts
exporttype
type WorkerEnv = Cloudflare.InferEnv<any>
WorkerEnv=
Cloudflare.
type Cloudflare.InferEnv = /*unresolved*/ any
InferEnv<typeof
const Worker: any
Worker>;
exportconst
const Worker: any
Worker=
any
Cloudflare.
any
Worker("Worker", {
main: string
main:"./src/worker.ts",
env: {
Bucket: any;
}
env: {
type Bucket: any
Bucket },
});
Your handler stays the same — just update the type import:
Cloudflare.InferEnv derives a fully typed env object from the
env declared on the Worker. You get type safety on the binding
names and their APIs without using Effect in your runtime code.
Your v1 state is not compatible with v2. On your first deploy, Alchemy
creates new resources. You should destroy your v1 stack first, then
deploy with v2.
Server-side representation of an incoming HTTP request.
Details
It extends HttpIncomingMessage with request metadata, parsed cookies,
multipart accessors, WebSocket upgrade support, and a modify method for
creating adjusted request views.
Service tag for the active server-side HTTP request.
When to use
Use to access the request currently being handled by HTTP server routes and
middleware.
Provides a way to write effectful code using generator functions, simplifying
control flow and error handling.
When to use
Use when you want to write effectful code that looks and behaves like
synchronous code, while still handling asynchronous tasks, errors, and complex
control flow such as loops and conditions.
Generator functions work similarly to async/await but keep errors,
requirements, and interruption in the Effect type. You can yield* values
from effects and return the final result at the end.
Attach one or more custom domains to serve bucket objects from a hostname
you control. The domain's zone must already exist in your Cloudflare
account; the zone is inferred from the hostname when omitted, or you can
pass a Cloudflare.Zone resource, a zone ID, or any hostname inside the
zone via the zone field.
Configure lifecycle rules to automatically delete objects, abort
incomplete multipart uploads, or transition objects to InfrequentAccess
storage. Pass an empty array (or omit) to clear all rules. See the
Cloudflare R2 docs
for details and limits (max 1000 rules per bucket).
Provides a way to write effectful code using generator functions, simplifying
control flow and error handling.
When to use
Use when you want to write effectful code that looks and behaves like
synchronous code, while still handling asynchronous tasks, errors, and complex
control flow such as loops and conditions.
Generator functions work similarly to async/await but keep errors,
requirements, and interruption in the Effect type. You can yield* values
from effects and return the final result at the end.
Server-side representation of an incoming HTTP request.
Details
It extends HttpIncomingMessage with request metadata, parsed cookies,
multipart accessors, WebSocket upgrade support, and a modify method for
creating adjusted request views.
Service tag for the active server-side HTTP request.
When to use
Use to access the request currently being handled by HTTP server routes and
middleware.
Split a string into substrings using the specified separator and return them as an array.
@param ― separator A string that identifies character or characters to use in separating the string. If omitted, a single-element array containing the entire string is returned.
@param ― limit A value used to limit the number of elements returned in the array.
split("/").
Array<string>.pop(): string |undefined
Removes the last element from an array and returns it.
If the array is empty, undefined is returned and the array is not modified.
The Worker resource declaration moves from alchemy.run.ts into the
Worker file itself (using import.meta.filename as the main), and the
Stack just yield*-s the imported Worker:
alchemy.run.ts
import*as
import Alchemy
Alchemyfrom"alchemy";
import*as
import Cloudflare
Cloudflarefrom"alchemy/Cloudflare";
import*as
import Effect
Effectfrom"effect/Effect";
import
import Worker
var Worker: Effect.Effect<Cloudflare.Worker<{
readonly Bucket: any;
}>, never, Cloudflare.Providers>
Workerfrom"./src/worker.ts";
import {
import Bucket
Bucket } from"./src/bucket.ts";
exporttype
type WorkerEnv = {
readonly Bucket: any;
}
WorkerEnv=
import Cloudflare
Cloudflare.
type InferEnv<W> = W extends Effect.Effect<infer A, infer _E, infer _R> ? Cloudflare.InferEnv<A> : W extends Cloudflare.Worker<any> ? Cloudflare.InferEnv<Exclude<W["Props"]["env"], undefined>> : { [k in keyof W]: Cloudflare.GetBindingType<W[k]>; }
Path to the Worker's entry module. Bundled with rolldown before
upload. Mutually exclusive with
script
— provide exactly one.
main:"./src/worker.ts",
env?:Alchemy.Input<{
readonlyBucket: any;
} | undefined>
Environment variables and native Cloudflare Bindings to bind to
the Worker. Accepts:
Resource references (R2 bucket, KV namespace, D1 database,
another Worker, Durable Object, etc.) — emitted as the
corresponding native binding.
effect/Config values (Config.redacted, Config.string,
Config.number, …) — resolved at deploy time and bound as
secret_text on Cloudflare regardless of the Config
constructor used. See
In Effect-native Workers you can alternatively yield* a
Config in the Init phase to register the binding implicitly;
env is the only option for async (non-Effect) Workers.
Cloudflare providers, bindings, and credentials for Worker-based stacks.
providers() },
import Effect
Effect.
constgen: <any, {
url: Alchemy.Output<string | undefined, never>;
}>(f: () => Generator<any, {
url: Alchemy.Output<string | undefined, never>;
}, never>) => Effect.Effect<{
url: Alchemy.Output<string | undefined, never>;
}, unknown, unknown> (+1 overload)
Provides a way to write effectful code using generator functions, simplifying
control flow and error handling.
When to use
Use when you want to write effectful code that looks and behaves like
synchronous code, while still handling asynchronous tasks, errors, and complex
control flow such as loops and conditions.
Generator functions work similarly to async/await but keep errors,
requirements, and interruption in the Effect type. You can yield* values
from effects and return the final result at the end.