Function: llm()
@providerprotocol/ai / @providerprotocol/ai / llm
Function: llm()
Section titled “Function: 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.
Type Parameters
Section titled “Type Parameters”TParams
Section titled “TParams”TParams = unknown
Provider-specific parameter type for model configuration
Parameters
Section titled “Parameters”options
Section titled “options”LLMOptions<TParams>
Configuration options for the LLM instance
Returns
Section titled “Returns”LLMInstance<TParams>
A configured LLM instance ready for inference
Throws
Section titled “Throws”When the provider does not support the LLM modality
Throws
Section titled “Throws”When structured output is requested but not supported
Throws
Section titled “Throws”When tools are provided but not supported
Example
Section titled “Example”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);