Skip to content

AI

Layeron AI binds Cloudflare Workers AI as AI on the product worker.

Use ai.llm to set a default model, then call it with run or the shorter prompt helper.

Terminal window
import { ai } from "@layeron/modules"
const assistant = ai.llm({
name: "assistant",
model: "@cf/meta/llama-3.1-8b-instruct",
})
const reply = await assistant.prompt("Write a short haiku about Cloudflare.")

Pass extra Workers AI options through run when you need them:

Terminal window
const result = await assistant.run({
prompt: "Summarize this paragraph.",
options: {
temperature: 0.2,
max_tokens: 128,
},
})