Models
A harness runs each conversation on a model. AI.Model gives a model a name, and an Effect AI LanguageModel Layer says which LLM answers under that name. Conversations store the name, so the LLM behind it can change without touching them.
Declare a model
Section titled “Declare a model”A model is a class with a name:
import * as AI from "@alchemy.run/ai";
export class Fast extends AI.Model<Fast>()("fast") {}export class Smart extends AI.Model<Smart>()("smart") {}The class says nothing of the LLM. Its window, its key and its provider are all said where it is backed.
Back it with an LLM
Section titled “Back it with an LLM”Fast.layer takes an Effect AI LanguageModel Layer, from any provider. For the models Cloudflare hosts (the @cf/... ids), AICloudflare.Model does it in one call, with no provider key:
import * as AI from "@alchemy.run/ai";import * as AICloudflare from "@alchemy.run/ai/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", parameters: { temperature: 0, maxTokens: 1024 },});The model’s key never leaves your runtime. Pi and OpenCode both run in your Durable Object, and each model request they make is answered by this Layer.
Route through AI Gateway
Section titled “Route through AI Gateway”An AI Gateway logs, caches and rate-limits requests on their way to a model. Pass one as gateway:
import * as AI from "@alchemy.run/ai";import * as AICloudflare from "@alchemy.run/ai/Cloudflare";import * as Cloudflare from "@alchemy.run/cloudflare";
export const Gateway = Cloudflare.AI.Gateway("Gateway", { collectLogs: true });
export class Fast extends AI.Model<Fast>()("fast") {}
export const FastLive = AICloudflare.Model(Fast, { gateway: Gateway, model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast",});See AI Gateway.
Use Anthropic
Section titled “Use Anthropic”AIAnthropic.Model backs a model with one of Anthropic’s, through Effect AI’s @effect/ai-anthropic:
pnpm add @effect/ai-anthropicbun add @effect/ai-anthropicnpm install @effect/ai-anthropicyarn add @effect/ai-anthropicimport * as AI from "@alchemy.run/ai";import * as AIAnthropic from "@alchemy.run/ai/Anthropic";
export class Smart extends AI.Model<Smart>()("smart") {}
export const SmartLive = AIAnthropic.Model(Smart, { model: "claude-opus-5-5" });It reads its key from ANTHROPIC_API_KEY while the runtime is constructed, so the deploy binds it as a secret. Pass apiKey to name it yourself, and parameters for what every request is made with:
import * as AI from "@alchemy.run/ai";import * as AIAnthropic from "@alchemy.run/ai/Anthropic";import * as Config from "effect/Config";
export class Smart extends AI.Model<Smart>()("smart") {}
export const SmartLive = AIAnthropic.Model(Smart, { model: "claude-opus-5-5", apiKey: Config.Redacted("TEAM_ANTHROPIC_API_KEY"), parameters: { temperature: 0 },});Use OpenAI
Section titled “Use OpenAI”AIOpenAI.Model backs a model with one of OpenAI’s, through Effect AI’s @effect/ai-openai:
pnpm add @effect/ai-openaibun add @effect/ai-openainpm install @effect/ai-openaiyarn add @effect/ai-openaiimport * as AI from "@alchemy.run/ai";import * as AIOpenAI from "@alchemy.run/ai/OpenAI";
export class Fast extends AI.Model<Fast>()("fast") {}
export const FastLive = AIOpenAI.Model(Fast, { model: "gpt-5.4-mini" });It reads its key from OPENAI_API_KEY while the runtime is constructed, so the deploy binds it as a secret. Pass apiKey to name it yourself, and parameters for what every request is made with:
import * as AI from "@alchemy.run/ai";import * as AIOpenAI from "@alchemy.run/ai/OpenAI";import * as Config from "effect/Config";
export class Fast extends AI.Model<Fast>()("fast") {}
export const FastLive = AIOpenAI.Model(Fast, { model: "gpt-5.4-mini", apiKey: Config.Redacted("TEAM_OPENAI_API_KEY"), parameters: { temperature: 0 },});Say what the LLM can take
Section titled “Say what the LLM can take”A harness plans a conversation around the LLM’s limits: how much context it accepts, how long one answer may be, and whether it reads images. Say them on the Layer, beside the LLM they describe:
import * as AI from "@alchemy.run/ai";import * as AIAnthropic from "@alchemy.run/ai/Anthropic";
export class Smart extends AI.Model<Smart>()("smart") {}
export const SmartLive = AIAnthropic.Model(Smart, { model: "claude-opus-5-5", contextWindow: 200_000, images: true,});contextWindow is 128,000 tokens unless you say otherwise, maxTokens for one answer is 8,192, and images is off. AIOpenAI.Model, AICloudflare.Model and Fast.layer, as its second argument, take the same three.
Use another provider
Section titled “Use another provider”Fast.layer takes any LanguageModel Layer, so a provider without a ready-made Layer is a few lines. This is AICloudflare.Model written out:
import * as AI from "@alchemy.run/ai";import * as Cloudflare from "@alchemy.run/cloudflare";import * as Effect from "effect/Effect";import * as Layer from "effect/Layer";
export class Fast extends AI.Model<Fast>()("fast") {}
export const FastLive = Layer.unwrap( Effect.gen(function* () { const ai = yield* Cloudflare.Workers.AI(); return Fast.layer(ai.model({ model: "@cf/meta/llama-3.3-70b-instruct-fp8-fast" })); }),).pipe(Layer.provide(Cloudflare.Workers.AIBinding));The Effect runs where the harness is yielded, so the binding it declares is part of the deploy. See Effect AI on Cloudflare, Bedrock and Vertex AI.
Set the default model
Section titled “Set the default model”Every process runs on AI.DefaultModel unless told otherwise. Give it one of your models, where the process’s Layers are provided:
import * as AI from "@alchemy.run/ai";import * as Layer from "effect/Layer";import { FastLive, Smart, SmartLive } from "./models.ts";
export const ModelsLive = AI.DefaultModel(Smart).pipe( Layer.provideMerge(Layer.mergeAll(SmartLive, FastLive)),);Mention a model in a process
Section titled “Mention a model in a process”A process that mentions a model may be run on it, and may start other sessions on it:
import * as AI from "@alchemy.run/ai";import { Fast } from "./models.ts";import { Research } from "./Research.process.ts";
export class Engineer extends AI.Process<Engineer>()("Engineer", { description: "Make one change to the project.",})` Start a ${Research} on ${Fast} for each thing you need to know, then make the change.` {}Each mentioned model’s Layer is a requirement of the process. See Mention a model.
List models on a harness
Section titled “List models on a harness”A harness used without processes lists every model its conversations may run on. The first is the default:
const harness = yield* Pi.Harness({ models: [Fast, Smart] });