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().
Defined in: src/genai/llm.ts:86
Examples
Extends
SpanBase
Properties
inputMessages
inputMessages:Input messages sent to the model. Flushed toMessage[] =[]
gen_ai.input.messages on
end().
Defined in: src/genai/llm.ts:93
model
Defined in: src/genai/llm.ts:117readonlymodel:string
outputMessages
outputMessages:Assistant messages returned by the model. Flushed toMessage[] =[]
gen_ai.output.messages on end().
Defined in: src/genai/llm.ts:98
providerName
Defined in: src/genai/llm.ts:118readonlyproviderName:string
reasoning
Chain-of-thought content. Folded into the last assistant message as a ReasoningPart at serialization time. Defined in: src/genai/llm.ts:105optionalreasoning:Reasoning
usage
usage:Token counts and cache stats. Flushed toUsage={}
gen_ai.usage.* on end().
Defined in: src/genai/llm.ts:100
Methods
addEvent()
addEvent(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 aftername,attributes?,startTime?):this
end(). Mirrors OTel Span.addEvent.
Defined in: src/genai/spanBase.ts:82
Parameters
name
string
attributes?
Attributes
startTime?
TimeInput
Returns
this
Example
Inherited from
SpanBase.addEvent
attachMedia()
attachMedia(Stage a media attachment for the LLM call. Pick exactly one ofopts):this
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().
Defined in: src/genai/llm.ts:183
Parameters
opts
AttachMediaOpts
Returns
this
attachMediaUrl()
attachMediaUrl(Convenience forurl,opts):this
attachMedia({uri, modality}).
Defined in: src/genai/llm.ts:192
Parameters
url
string
opts
modality
Modality
Returns
this
end()
end(Flush accumulated state and close the span. Idempotent. Passopts?):void
error to mark failed; pass endTime to backdate the close.
Defined in: src/genai/llm.ts:274
Parameters
opts?
SpanEndOptions
Returns
void
output()
output(Append an assistant message to the response. Defined in: src/genai/llm.ts:155content):this
Parameters
content
string
Returns
this
record()
record(Bulk-set any subset of the mutable fields. Replaces (does not merge). Useful for assigning everything at once after a provider call returns. Defined in: src/genai/llm.ts:203opts):this
Parameters
opts
finishReasons?
string[]
inputMessages?
Message[]
mediaAttachments?
AttachMediaOpts[]
outputMessages?
Message[]
outputType?
string
reasoning?
Reasoning
responseId?
string
responseModel?
string
usage?
Usage
Returns
this
setAttributes()
setAttributes(Set multiple attributes on the span at once. Warns and no-ops afterattributes):this
end(). Mirrors OTel Span.setAttributes (and the Python SDK’s
set_attributes).
Defined in: src/genai/spanBase.ts:63
Parameters
attributes
Attributes
Returns
this
Example
Inherited from
SpanBase.setAttributes
startSubagent()
startSubagent(Start a child SubAgent span nested under this LLM. Defined in: src/genai/llm.ts:261opts):SubAgent
Parameters
opts
SubAgentInit
Returns
SubAgent
startTool()
startTool(Start a child Tool span nested under this LLM. Defined in: src/genai/llm.ts:252opts):Tool
Parameters
opts
ToolInit
Returns
Tool
think()
think(Set or extend the model’s reasoning/chain-of-thought content. Accumulates intocontent):this
this.reasoning.content. Folded into the last assistant message as
a ReasoningPart at serialization time, matching the Python SDK’s
on-the-wire shape.
Defined in: src/genai/llm.ts:167
Parameters
content
string
Returns
this