chat span with gen_ai.* attributes.
Created by tracing.startLLM() (or turn.startLLM(), or
subagent.startLLM()) and terminated with end(). The most recently started
LLM is the current one (getCurrentLLM, tracing.startTool). An LLM started
under a SubAgent while another LLM is active nests LIFO: it is current until
it ends, then the enclosing LLM is current again. Nest tool/subagent calls
under an LLM 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
Properties
Message[]
Type:
Message[]Input messages sent to the model. Flushed to gen_ai.input.messages on
end().string
Read-only.
Message[]
Type:
Message[]Assistant messages returned by the model. Flushed to
gen_ai.output.messages on end().string
Read-only.
Reasoning
Type:
ReasoningChain-of-thought content. Folded into the last assistant message as a
ReasoningPart at serialization time.Methods
attachMedia()
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
AttachMediaOpts
required
Returns
this
attachMediaUrl()
attachMedia({uri, modality}).
Parameters
string
required
object
required
Returns
this
end()
error to mark failed; pass endTime to backdate the close.
Parameters
SpanEndOptions
output()
Parameters
string
required
Returns
this
record()
Parameters
object
required
Returns
this
setAttributes()
end(). Mirrors OTel Span.setAttributes (and the Python SDK’s
set_attributes).
Parameters
Attributes
required
Returns
this
Examples
startSubagent()
Parameters
SubAgentInit
required
Type:
SubAgentInitReturns
SubAgent
startTool()
Parameters
Returns
Tool
think()
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