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:Defined in: src/genai/llm.ts:93 Input messages sent to the model. Flushed toMessage[] =[]
gen_ai.input.messages on
end().
model
Defined in: src/genai/llm.ts:117readonlymodel:string
outputMessages
outputMessages:Defined in: src/genai/llm.ts:98 Assistant messages returned by the model. Flushed toMessage[] =[]
gen_ai.output.messages on end().
providerName
Defined in: src/genai/llm.ts:118readonlyproviderName:string
reasoning?
Defined in: src/genai/llm.ts:105 Chain-of-thought content. Folded into the last assistant message as a ReasoningPart at serialization time.optionalreasoning?:Reasoning
usage
usage:Defined in: src/genai/llm.ts:100 Token counts and cache stats. Flushed toUsage={}
gen_ai.usage.* on end().
Methods
addEvent()
addEvent(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 aftername,attributes?,startTime?):this
end(). Mirrors OTel Span.addEvent.
Parameters
name
string
attributes?
Attributes
startTime?
TimeInput
Returns
this
Example
Inherited from
SpanBase.addEvent
attachMedia()
attachMedia(Defined in: src/genai/llm.ts:183 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
opts
AttachMediaOpts
Returns
this
attachMediaUrl()
attachMediaUrl(Defined in: src/genai/llm.ts:192 Convenience forurl,opts):this
attachMedia({uri, modality}).
Parameters
url
string
opts
modality
Modality
Returns
this
end()
end(Defined in: src/genai/llm.ts:274 Flush accumulated state and close the span. Idempotent. Passopts?):void
error to mark failed; pass endTime to backdate the close.
Parameters
opts?
SpanEndOptions
Returns
void
output()
output(Defined in: src/genai/llm.ts:155 Append an assistant message to the response.content):this
Parameters
content
string
Returns
this
record()
record(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.opts):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(Defined in: src/genai/spanBase.ts:63 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
Attributes
Returns
this
Example
Inherited from
SpanBase.setAttributes
startSubagent()
startSubagent(Defined in: src/genai/llm.ts:261 Start a child SubAgent span nested under this LLM.opts):SubAgent
Parameters
opts
SubAgentInit
Returns
SubAgent
startTool()
startTool(Defined in: src/genai/llm.ts:252 Start a child Tool span nested under this LLM.opts):Tool
Parameters
opts
ToolInit
Returns
Tool
think()
think(Defined in: src/genai/llm.ts:167 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
content
string
Returns
this