Skip to main content
An LLM call. Emits a 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.
Usage
Type: UsageToken counts and cache stats. Flushed to gen_ai.usage.* on end().

Methods

attachMedia()

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

AttachMediaOpts
required

Returns

this

attachMediaUrl()

Convenience for attachMedia({uri, modality}).

Parameters

string
required
object
required

Returns

this

end()

Flush accumulated state and close the span. Idempotent. Pass error to mark failed; pass endTime to backdate the close.

Parameters

SpanEndOptions

output()

Append an assistant message to the response.

Parameters

string
required

Returns

this

record()

Bulk-set any subset of the mutable fields. Replaces (does not merge). Useful for assigning everything at once after a provider call returns.

Parameters

object
required

Returns

this

setAttributes()

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
required

Returns

this

Examples

startSubagent()

Start a child SubAgent span nested under this LLM.

Parameters

SubAgentInit
required

Returns

SubAgent

startTool()

Start a child Tool span nested under this LLM.

Parameters

ToolInit
required
Type: ToolInit

Returns

Tool

think()

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

string
required

Returns

this
Last modified on September 30, 2026