Skip to content

Function: llm()

@providerprotocol/ai


@providerprotocol/ai / @providerprotocol/ai / llm

llm<TParams>(options): LLMInstance<TParams>

Defined in: src/core/llm.ts:1202

Creates an LLM instance configured with the specified options.

This is the primary factory function for creating LLM instances. It validates provider capabilities, binds the model, and returns an instance with generate and stream methods for inference.

TParams = unknown

Provider-specific parameter type for model configuration

LLMOptions<TParams>

Configuration options for the LLM instance

LLMInstance<TParams>

A configured LLM instance ready for inference

When the provider does not support the LLM modality

When structured output is requested but not supported

When tools are provided but not supported

import { llm } from 'upp';
import { anthropic } from 'upp/providers/anthropic';
const assistant = llm({
model: anthropic('claude-sonnet-4-20250514'),
system: 'You are a helpful assistant.',
tools: [myTool],
});
const turn = await assistant.generate('Hello, world!');
console.log(turn.text);