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().
Example
Hierarchy
-
SpanBase↳LLM
Table of contents
Properties
Methods
- addEvent
- attachMedia
- attachMediaUrl
- end
- output
- record
- setAttributes
- startSubagent
- startTool
- think
- create
Properties
inputMessages
• inputMessages:Message[] = []
Input messages sent to the model. Flushed to gen_ai.input.messages on
end().
Defined in
src/genai/llm.ts:79model
•Readonly model: string
Defined in
src/genai/llm.ts:97outputMessages
• outputMessages:Message[] = []
Assistant messages returned by the model. Flushed to
gen_ai.output.messages on end().
Defined in
src/genai/llm.ts:84providerName
•Readonly providerName: string
Defined in
src/genai/llm.ts:98reasoning
•Optional reasoning: Reasoning
Chain-of-thought content. Folded into the last assistant message as a
ReasoningPart at serialization time.
Defined in
src/genai/llm.ts:91usage
• usage:Usage = {}
Token counts and cache stats. Flushed to gen_ai.usage.* on end().
Defined in
src/genai/llm.ts:86Methods
addEvent
▸ 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
| Name | Type |
|---|---|
name | string |
attributes? | Attributes |
startTime? | TimeInput |
Returns
this
Example
Inherited from
SpanBase.addEventDefined in
src/genai/spanBase.ts:77attachMedia
▸ attachMedia(opts): this
Attach a media part to the last input message. Pick exactly one of
content (inline base64 bytes), uri (URI reference), or fileId
(pre-uploaded file id).
Parameters
| Name | Type |
|---|---|
opts | AttachMediaOpts |
Returns
this
Defined in
src/genai/llm.ts:170attachMediaUrl
▸ attachMediaUrl(url, opts): this
Convenience for attachMedia({uri, modality}).
Parameters
| Name | Type |
|---|---|
url | string |
opts | Object |
opts.modality | Modality |
Returns
this
Defined in
src/genai/llm.ts:188end
▸ end(opts?): void
Flush accumulated state and close the span. Idempotent. Pass error to mark failed; pass endTime to backdate the close.
Parameters
| Name | Type |
|---|---|
opts? | SpanEndOptions |
Returns
void
Defined in
src/genai/llm.ts:245output
▸ output(content): this
Append an assistant message to the response.
Parameters
| Name | Type |
|---|---|
content | string |
Returns
this
Defined in
src/genai/llm.ts:143record
▸ 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
| Name | Type |
|---|---|
opts | LLMRecordOpts |
Returns
this
Defined in
src/genai/llm.ts:199setAttributes
▸ 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
| Name | Type |
|---|---|
attributes | Attributes |
Returns
this
Example
Inherited from
SpanBase.setAttributesDefined in
src/genai/spanBase.ts:63startSubagent
▸ startSubagent(opts): SubAgent
Start a child SubAgent span nested under this LLM.
Parameters
| Name | Type |
|---|---|
opts | SubAgentInit |
Returns
SubAgent
Defined in
src/genai/llm.ts:232startTool
▸ startTool(opts): Tool
Start a child Tool span nested under this LLM.
Parameters
| Name | Type |
|---|---|
opts | ToolInit |
Returns
Tool
Defined in
src/genai/llm.ts:223think
▸ 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
| Name | Type |
|---|---|
content | string |
Returns
this
Defined in
src/genai/llm.ts:155create
▸ create(opts): LLM
Parameters
| Name | Type |
|---|---|
opts | LLMInit & ChildSpanContext |
Returns
LLM