Skip to content

API reference

ai.llm(options) creates a Workers AI model wrapper for calling Cloudflare Workers AI from a Layeron backend.

Terminal window
import { ai } from "@layeron/modules"

Create a Workers AI LLM wrapper.

TypeSpec operation: llm.

Terminal window
ai.llm(options: AiLlmOptions): AiLlmModule

Options accepted by ai.llm(options).

FieldTypeDescription
namestringStable AI instance name inside the Layeron app.
namespacestring | undefinedPlatform namespace for the instance. Defaults to default.
modelstringCloudflare Workers AI model identifier, for example @cf/meta/llama-3.1-8b-instruct.

Input accepted by assistant.run(input).

FieldTypeDescription
promptstringPrompt text sent to the configured Workers AI model.
optionsRecord<unknown> | undefinedAdditional Workers AI options forwarded to AI.run.

Options accepted by assistant.prompt(prompt, options).

FieldTypeDescription
optionsRecord<unknown> | undefinedAdditional Workers AI options forwarded to AI.run.

Normalized AI LLM module configuration.

FieldTypeDescription
kind”ai”Module config kind.
namestringStable AI instance name inside the Layeron app.
namespacestringPlatform namespace for the instance. Defaults to default.
modelstringCloudflare Workers AI model identifier.
binding”AI”Workers AI binding name used by the AI product worker.

Layeron AI module returned by ai.llm(options).

FieldTypeDescription
name”ai”Module name.
configAiLlmModuleConfigNormalized module configuration.

Run the configured Workers AI model with a prompt and optional Workers AI options.

TypeSpec operation: aiLlmRun.

Terminal window
assistant.run(input: AiLlmRunInput): unknown

Run the configured Workers AI model with a prompt string.

TypeSpec operation: aiLlmPrompt.

Terminal window
assistant.prompt(prompt: string, options?: AiLlmPromptOptions): unknown