Interface: LLMInstance
@providerprotocol/ai / @providerprotocol/ai / LLMInstance
Interface: LLMInstance<TParams>
Section titled “Interface: LLMInstance<TParams>”Defined in: src/types/llm.ts:197
LLM instance returned by the llm() function.
Provides methods for generating responses and streaming output, with access to the bound model and capabilities.
Example
Section titled “Example”import { llm, openai, StreamEventType } from 'provider-protocol';
const instance = llm({ model: openai('gpt-4') });
// Simple generationconst turn = await instance.generate('Hello!');console.log(turn.response.text);
// Streamingconst stream = instance.stream('Tell me a story');for await (const event of stream) { if (event.type === StreamEventType.TextDelta) { process.stdout.write(event.delta.text ?? ''); }}const finalTurn = await stream.turn;Type Parameters
Section titled “Type Parameters”TParams
Section titled “TParams”TParams = unknown
Provider-specific parameter type
Properties
Section titled “Properties”capabilities
Section titled “capabilities”
readonlycapabilities:LLMCapabilities
Defined in: src/types/llm.ts:247
Provider API capabilities
readonlymodel:BoundLLMModel<TParams>
Defined in: src/types/llm.ts:238
The bound model instance
params
Section titled “params”
readonlyparams:TParams|undefined
Defined in: src/types/llm.ts:244
Current model parameters
system
Section titled “system”
readonlysystem:string|unknown[] |undefined
Defined in: src/types/llm.ts:241
Current system prompt (string or provider-specific array format)
Methods
Section titled “Methods”generate()
Section titled “generate()”generate(
historyOrInput?, …input?):Promise<Turn<unknown>>
Defined in: src/types/llm.ts:212
Executes inference and returns the complete Turn.
Supports multiple calling patterns:
- No input (system-only):
generate() - Single input:
generate('Hello') - Multiple inputs:
generate('Context...', 'Question?') - With history:
generate(messages, 'Follow-up?') - With thread:
generate(thread, 'Next message')
Parameters
Section titled “Parameters”historyOrInput?
Section titled “historyOrInput?”Optional history (Message[] or Thread) or first input
Message[] | Thread | InferenceInput
input?
Section titled “input?”Additional inputs to include in the request
Returns
Section titled “Returns”Promise<Turn<unknown>>
Promise resolving to the complete Turn
stream()
Section titled “stream()”stream(
historyOrInput?, …input?):StreamResult
Defined in: src/types/llm.ts:232
Executes streaming inference.
Returns an async iterable of stream events that can also be awaited for the final Turn.
Supports multiple calling patterns:
- No input (system-only):
stream() - Single input:
stream('Hello') - With history:
stream(messages, 'Follow-up?')
Parameters
Section titled “Parameters”historyOrInput?
Section titled “historyOrInput?”Optional history (Message[] or Thread) or first input
Message[] | Thread | InferenceInput
input?
Section titled “input?”Additional inputs to include in the request
Returns
Section titled “Returns”StreamResult that yields events and resolves to Turn