Skip to main content
An LLM call. Emits a 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: Message[] = []
Input messages sent to the model. Flushed to gen_ai.input.messages on end().

model

readonly model: string

outputMessages

outputMessages: Message[] = []
Assistant messages returned by the model. Flushed to gen_ai.output.messages on end().

providerName

readonly providerName: string

reasoning

optional reasoning: Reasoning
Chain-of-thought content. Folded into the last assistant message as a ReasoningPart at serialization time.

usage

usage: Usage = {}
Token counts and cache stats. Flushed to gen_ai.usage.* on end().

Methods

addEvent()

Deprecated. Record this data via setAttributes instead. OpenTelemetry is phasing out the Span Event API (Span.addEvent). This method still works and existing span-event data stays valid. See https://opentelemetry.io/blog/2026/deprecating-span-events/
addEvent(name, attributes?, startTime?): this
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 after end(). Mirrors OTel Span.addEvent.

Parameters

string
required
Attributes
TimeInput

Returns

this

Example

Inherited from

SpanBase.addEvent

attachMedia()

attachMedia(opts): this
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

{…} | {…} | {…}
required
See Modality, Modality, Modality.Full type: { content: string; mimeType: string; modality: Modality; } | { modality: Modality; uri: string; } | { fileId: string; mimeType?: string; modality: Modality; }

Returns

this

attachMediaUrl()

attachMediaUrl(url, opts): this
Convenience for attachMedia({uri, modality}).

Parameters

string
required
object
required

Returns

this

end()

end(opts?): void
Flush accumulated state and close the span. Idempotent. Pass error to mark failed; pass endTime to backdate the close.

Parameters

object

Returns

void

output()

output(content): this
Append an assistant message to the response.

Parameters

string
required

Returns

this

record()

record(opts): this
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()

setAttributes(attributes): this
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

Example

Inherited from

SpanBase.setAttributes

startSubagent()

startSubagent(opts): SubAgent
Start a child SubAgent span nested under this LLM.

Parameters

SubAgentInit
required

Returns

SubAgent

startTool()

startTool(opts): Tool
Start a child Tool span nested under this LLM.

Parameters

ToolInit
required

Returns

Tool

think()

think(content): this
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