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
Table of contents
Properties
Methods
Properties
inputMessages
โข inputMessages:Message[] = []
Input messages sent to the model. Flushed to gen_ai.input.messages on
end().
Defined in
genai/llm.ts:78model
โขReadonly model: string
Defined in
genai/llm.ts:98outputMessages
โข outputMessages:Message[] = []
Assistant messages returned by the model. Flushed to
gen_ai.output.messages on end().
Defined in
genai/llm.ts:83providerName
โขReadonly providerName: string
Defined in
genai/llm.ts:99reasoning
โขOptional reasoning: Reasoning
Chain-of-thought content. Folded into the last assistant message as a
ReasoningPart at serialization time.
Defined in
genai/llm.ts:90usage
โข usage:Usage = {}
Token counts and cache stats. Flushed to gen_ai.usage.* on end().
Defined in
genai/llm.ts:85Methods
attachMedia
โธ 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
genai/llm.ts:168attachMediaUrl
โธ attachMediaUrl(url, opts): this
Convenience for attachMedia({uri, modality}).
Parameters
| Name | Type |
|---|---|
url | string |
opts | Object |
opts.modality | Modality |
Returns
this
Defined in
genai/llm.ts:186end
โธ end(opts?): void
Flush accumulated state to the span and close it. Idempotent. Pass
error to mark the span as failed.
Parameters
| Name | Type |
|---|---|
opts? | Object |
opts.error? | Error |
Returns
void
Defined in
genai/llm.ts:246output
โธ output(content): this
Append an assistant message to the response.
Parameters
| Name | Type |
|---|---|
content | string |
Returns
this
Defined in
genai/llm.ts:141record
โธ 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
genai/llm.ts:197startSubagent
โธ startSubagent(opts): SubAgent
Start a child SubAgent span nested under this LLM.
Parameters
| Name | Type |
|---|---|
opts | SubAgentInit |
Returns
SubAgent
Defined in
genai/llm.ts:230startTool
โธ startTool(opts): Tool
Start a child Tool span nested under this LLM.
Parameters
| Name | Type |
|---|---|
opts | ToolInit |
Returns
Tool
Defined in
genai/llm.ts:221think
โธ 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
genai/llm.ts:153create
โธ create(opts): LLM
Parameters
| Name | Type |
|---|---|
opts | LLMInit & ChildSpanContext |
Returns
LLM