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:Input messages sent to the model. Flushed toMessage[] =[]
gen_ai.input.messages on
end().
model
readonlymodel:string
outputMessages
outputMessages:Assistant messages returned by the model. Flushed toMessage[] =[]
gen_ai.output.messages on end().
providerName
readonlyproviderName:string
reasoning
Chain-of-thought content. Folded into the last assistant message as a ReasoningPart at serialization time.optionalreasoning:Reasoning
usage
usage:Token counts and cache stats. Flushed toUsage={}
gen_ai.usage.* on end().
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.
Parameters
string
required
Attributes
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().
Parameters
{…} | {…} | {…}
required
Returns
this
attachMediaUrl()
attachMediaUrl(Convenience forurl,opts):this
attachMedia({uri, modality}).
Parameters
string
required
object
required
Returns
this
end()
end(Flush accumulated state and close the span. Idempotent. Passopts?):void
error to mark failed; pass endTime to backdate the close.
Parameters
object
Returns
void
output()
output(Append an assistant message to the response.content):this
Parameters
string
required
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.opts):this
Parameters
object
required
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).
Parameters
Attributes
required
Returns
this
Example
Inherited from
SpanBase.setAttributes
startSubagent()
startSubagent(Start a child SubAgent span nested under this LLM.opts):SubAgent
Parameters
SubAgentInit
required
See
SubAgentInit.Returns
SubAgent
startTool()
startTool(Start a child Tool span nested under this LLM.opts):Tool
Parameters
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.
Parameters
string
required
Returns
this