Setup
You need:
- Node.js 24.11.1+ or Bun
- An Alchemy app on Cloudflare. See Cloudflare setup.
Pi itself needs no account. The model is yours, through any Effect AI provider, and so is the sandbox platform, when the harness uses one.
Install
Section titled “Install”Install the harness and the shared AI package:
pnpm add https://pkg.alchemy.run/@alchemy.run/pi/pr:3743:56b4873 https://pkg.alchemy.run/@alchemy.run/ai/pr:3743:56b4873bun add https://pkg.alchemy.run/@alchemy.run/pi/pr:3743:56b4873 https://pkg.alchemy.run/@alchemy.run/ai/pr:3743:56b4873npm install https://pkg.alchemy.run/@alchemy.run/pi/pr:3743:56b4873 https://pkg.alchemy.run/@alchemy.run/ai/pr:3743:56b4873yarn add https://pkg.alchemy.run/@alchemy.run/pi/pr:3743:56b4873 https://pkg.alchemy.run/@alchemy.run/ai/pr:3743:56b4873A model
Section titled “A model”A harness needs at least one model. Workers AI needs nothing beyond your Cloudflare account:
import * as AI from "@alchemy.run/ai";import * as AICloudflare from "@alchemy.run/ai/Cloudflare";import * as Cloudflare from "@alchemy.run/cloudflare";
export class Fast extends AI.Model<Fast>()("fast") {}
export const FastLive = AICloudflare.Model(Fast, { model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast",});See Models for other providers.
A harness
Section titled “A harness”Yield the harness in a Durable Object’s outer Effect and provide its Layers once:
import * as Cloudflare from "@alchemy.run/cloudflare";import * as Pi from "@alchemy.run/pi";import * as PiCloudflare from "@alchemy.run/pi/Cloudflare";import * as Effect from "effect/Effect";import * as Layer from "effect/Layer";import { Fast, FastLive } from "./models.ts";
const HarnessLive = Layer.mergeAll(FastLive, PiCloudflare.DurableObjectStorage);
export default class Session extends Cloudflare.DurableObject<Session>()( "Session", Effect.gen(function* () { const harness = yield* Pi.Harness({ models: [Fast] });
return Effect.gen(function* () { return { prompt: Effect.fn(function* (name: string, text: string) { const conversation = yield* harness.createConversation({ name }); const submission = yield* conversation.submit({ type: "input", content: text }); return (yield* submission.wait).status; }), }; }); }).pipe(Effect.provide(HarnessLive)),) {}Bind the Durable Object to a Worker by yielding Session in the Worker’s own outer Effect. See Durable Objects.
A sandbox platform
Section titled “A sandbox platform”A harness that uses the coding tools needs a sandbox platform: E2B, Daytona, Modal, Boat or Archil. Add its provider to the Stack and sign in to it with your profile. See Sandboxes.
Next: the tutorial.