llm
import { llm } from '@routecraft/ai'
Call a language model and get text or structured output. Requires llmPlugin() in your context plugins.
import { llm } from '@routecraft/ai'
// Text output
craft()
.id('summarise')
.from(source)
.enrich(llm('anthropic:claude-haiku-4-5-20251001', {
system: 'Summarise the following in one sentence.',
user: (ex) => ex.body.content,
}))
.to(log())
// Result replaces the body: { text: '...', usage: { inputTokens, outputTokens } }
// (use only() to merge instead, e.g. .enrich(llm(...), only((r) => r.text, 'summary')))
// Structured output with Zod schema
import { z } from 'zod'
const sentimentSchema = z.object({
sentiment: z.enum(['positive', 'neutral', 'negative']),
confidence: z.number(),
})
craft()
.id('classify')
.from(source)
.enrich(llm('openai:gpt-4o', {
system: 'Classify the sentiment of the text.',
user: (ex) => ex.body.text,
output: sentimentSchema,
}))
.to(log())
// result.output is typed as { sentiment: 'positive' | 'neutral' | 'negative', confidence: number }
Model ID format: "provider:model-name" (e.g., "ollama:llama3.2", "anthropic:claude-sonnet-4-6").
Supported providers: openai, anthropic, ollama, openrouter, gemini, lmstudio, custom
Options:
Result shape (replaces the body in bare .enrich() / .to(); pass an aggregator such as only() to merge):
Provider credentials are configured once in llmPlugin() and shared across all llm() calls. See Plugins reference.