Skip to content

Interface: LLMInstance

@providerprotocol/ai


@providerprotocol/ai / @providerprotocol/ai / LLMInstance

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.

import { llm, openai, StreamEventType } from 'provider-protocol';
const instance = llm({ model: openai('gpt-4') });
// Simple generation
const turn = await instance.generate('Hello!');
console.log(turn.response.text);
// Streaming
const 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;

TParams = unknown

Provider-specific parameter type

readonly capabilities: LLMCapabilities

Defined in: src/types/llm.ts:247

Provider API capabilities


readonly model: BoundLLMModel<TParams>

Defined in: src/types/llm.ts:238

The bound model instance


readonly params: TParams | undefined

Defined in: src/types/llm.ts:244

Current model parameters


readonly system: string | unknown[] | undefined

Defined in: src/types/llm.ts:241

Current system prompt (string or provider-specific array format)

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')

Optional history (Message[] or Thread) or first input

Message[] | Thread | InferenceInput

…InferenceInput[]

Additional inputs to include in the request

Promise<Turn<unknown>>

Promise resolving to the complete Turn


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?')

Optional history (Message[] or Thread) or first input

Message[] | Thread | InferenceInput

…InferenceInput[]

Additional inputs to include in the request

StreamResult

StreamResult that yields events and resolves to Turn