Skip to main content

Documentation Index

Fetch the complete documentation index at: https://wb-21fd5541-update-reference-docs-34.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

weave / LLM An LLM call. Emits a chat span with gen_ai.* attributes. Created by weave.startLLM() (or turn.startLLM()) and terminated with end(). Only one LLM may be active in an async context at a time; nest tool/subagent calls under it via startTool / startSubagent. Populate inputMessages / outputMessages / usage / reasoning directly, or via the helper functions (output, think, attachMedia, record). All recorded data is flushed to the span at end(). Example
const llm = weave.startLLM({model: 'gpt-4o-mini', providerName: 'openai'});
try {
  llm.inputMessages = [{role: 'user', content: prompt}];
  const resp = await openai.chat.completions.create({...});
  llm.output(resp.choices[0].message.content ?? '');
  llm.record({usage: {inputTokens: resp.usage?.prompt_tokens}});
} finally {
  llm.end();
}

Table of contents

Properties

Methods

Properties

inputMessages

inputMessages: Message[] = [] Input messages sent to the model. Flushed to gen_ai.input.messages on end().

Defined in

genai/llm.ts:78

model

Readonly model: string

Defined in

genai/llm.ts:98

outputMessages

outputMessages: Message[] = [] Assistant messages returned by the model. Flushed to gen_ai.output.messages on end().

Defined in

genai/llm.ts:83

providerName

Readonly providerName: string

Defined in

genai/llm.ts:99

reasoning

Optional reasoning: Reasoning Chain-of-thought content. Folded into the last assistant message as a ReasoningPart at serialization time.

Defined in

genai/llm.ts:90

usage

usage: Usage = {} Token counts and cache stats. Flushed to gen_ai.usage.* on end().

Defined in

genai/llm.ts:85

Methods

attachMedia

attachMedia(opts): this Attach a media part to the last input message. Pick exactly one of content (inline base64 bytes), uri (URI reference), or fileId (pre-uploaded file id).

Parameters

NameType
optsAttachMediaOpts

Returns

this

Defined in

genai/llm.ts:168

attachMediaUrl

attachMediaUrl(url, opts): this Convenience for attachMedia({uri, modality}).

Parameters

NameType
urlstring
optsObject
opts.modalityModality

Returns

this

Defined in

genai/llm.ts:186

end

end(opts?): void Flush accumulated state to the span and close it. Idempotent. Pass error to mark the span as failed.

Parameters

NameType
opts?Object
opts.error?Error

Returns

void

Defined in

genai/llm.ts:246

output

output(content): this Append an assistant message to the response.

Parameters

NameType
contentstring

Returns

this

Defined in

genai/llm.ts:141

record

record(opts): this Bulk-set any subset of the mutable fields. Replaces (does not merge). Useful for assigning everything at once after a provider call returns.

Parameters

NameType
optsLLMRecordOpts

Returns

this

Defined in

genai/llm.ts:197

startSubagent

startSubagent(opts): SubAgent Start a child SubAgent span nested under this LLM.

Parameters

NameType
optsSubAgentInit

Returns

SubAgent

Defined in

genai/llm.ts:230

startTool

startTool(opts): Tool Start a child Tool span nested under this LLM.

Parameters

NameType
optsToolInit

Returns

Tool

Defined in

genai/llm.ts:221

think

think(content): this Set or extend the model’s reasoning/chain-of-thought content. Accumulates into this.reasoning.content. Folded into the last assistant message as a ReasoningPart at serialization time, matching the Python SDK’s on-the-wire shape.

Parameters

NameType
contentstring

Returns

this

Defined in

genai/llm.ts:153

create

create(opts): LLM

Parameters

NameType
optsLLMInit & ChildSpanContext

Returns

LLM

Defined in

genai/llm.ts:102