Skip to main content
Defined in: src/genai/llm.ts:86 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().

Examples

Extends

  • SpanBase

Properties

inputMessages

inputMessages: Message[] = []
Defined in: src/genai/llm.ts:93 Input messages sent to the model. Flushed to gen_ai.input.messages on end().

model

readonly model: string
Defined in: src/genai/llm.ts:117

outputMessages

outputMessages: Message[] = []
Defined in: src/genai/llm.ts:98 Assistant messages returned by the model. Flushed to gen_ai.output.messages on end().

providerName

readonly providerName: string
Defined in: src/genai/llm.ts:118

reasoning?

optional reasoning?: Reasoning
Defined in: src/genai/llm.ts:105 Chain-of-thought content. Folded into the last assistant message as a ReasoningPart at serialization time.

usage

usage: Usage = {}
Defined in: src/genai/llm.ts:100 Token counts and cache stats. Flushed to gen_ai.usage.* on end().

Methods

addEvent()

Deprecated. Record this data via setAttributes instead. OpenTelemetry is phasing out the Span Event API (Span.addEvent). This method still works and existing span-event data stays valid. See https://opentelemetry.io/blog/2026/deprecating-span-events/
addEvent(name, attributes?, startTime?): this
Defined in: src/genai/spanBase.ts:82 Add a named event to the span. Useful for marking non-span moments such as context compaction, tool-loop detection, or guardrail trips. Warns and no-ops after end(). Mirrors OTel Span.addEvent.

Parameters

name
string
attributes?
Attributes
startTime?
TimeInput

Returns

this

Example

Inherited from

SpanBase.addEvent

attachMedia()

attachMedia(opts): this
Defined in: src/genai/llm.ts:183 Stage a media attachment for the LLM call. Pick exactly one of content (inline base64 bytes), uri (URI reference), or fileId (pre-uploaded file id). The attachment is glued onto the last user message in inputMessages on end().

Parameters

opts
AttachMediaOpts

Returns

this

attachMediaUrl()

attachMediaUrl(url, opts): this
Defined in: src/genai/llm.ts:192 Convenience for attachMedia({uri, modality}).

Parameters

url
string
opts
modality
Modality

Returns

this

end()

end(opts?): void
Defined in: src/genai/llm.ts:274 Flush accumulated state and close the span. Idempotent. Pass error to mark failed; pass endTime to backdate the close.

Parameters

opts?
SpanEndOptions

Returns

void

output()

output(content): this
Defined in: src/genai/llm.ts:155 Append an assistant message to the response.

Parameters

content
string

Returns

this

record()

record(opts): this
Defined in: src/genai/llm.ts:203 Bulk-set any subset of the mutable fields. Replaces (does not merge). Useful for assigning everything at once after a provider call returns.

Parameters

opts
finishReasons?
string[]
inputMessages?
Message[]
mediaAttachments?
AttachMediaOpts[]
outputMessages?
Message[]
outputType?
string
reasoning?
Reasoning
responseId?
string
responseModel?
string
usage?
Usage

Returns

this

setAttributes()

setAttributes(attributes): this
Defined in: src/genai/spanBase.ts:63 Set multiple attributes on the span at once. Warns and no-ops after end(). Mirrors OTel Span.setAttributes (and the Python SDK’s set_attributes).

Parameters

attributes
Attributes

Returns

this

Example

Inherited from

SpanBase.setAttributes

startSubagent()

startSubagent(opts): SubAgent
Defined in: src/genai/llm.ts:261 Start a child SubAgent span nested under this LLM.

Parameters

opts
SubAgentInit

Returns

SubAgent

startTool()

startTool(opts): Tool
Defined in: src/genai/llm.ts:252 Start a child Tool span nested under this LLM.

Parameters

opts
ToolInit

Returns

Tool

think()

think(content): this
Defined in: src/genai/llm.ts:167 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

content
string

Returns

this