Skip to main content
One LLM API call. Maps to a chat OTel span. LLM is a Pydantic model. Set any field below as a keyword argument when you construct it. LLM is a context manager and can be used in a with statement.

Fields

Methods

output

Append an assistant message to output_messages.

think

Set reasoning/chain-of-thought content.

attach_media

Attach media to this LLM call. Exactly one source is required. Bytes are base64-encoded as an inline GenAI blob. String content must already be base64-encoded. URIs and provider file IDs are emitted as GenAI URI and file parts.

attach_media_url

Attach a data URL or ordinary media URI to this LLM call.

record

Set multiple LLM-call fields in one call. Manually-instrumented agents typically build up a chat span by assigning eight or more individual fields at the end of an LLM call (input_messages, output_messages, usage, response_id, and so on). record(...) collapses those into a single keyword call so the recording site stays compact. Only fields explicitly passed (non-None) are applied; existing values are preserved. reasoning accepts either a Reasoning instance or a plain string (wrapped automatically). Returns self for chaining.

end

start

Start this span once; context-manager entry uses the same path.

record_error

Record a failure without ending the span; call end() when ready.

set_attributes

Stamp arbitrary OTel attributes on this span. Pass a dict whether you have one key or many; single-key callers use span.set_attributes({"weave.tag": "value"}). Mirrors OTel’s Span.set_attributes. Must be called after a start_* factory, start(), or with starts the span, and before it ends. Outside that window the call is a no-op and logs a warning. For batch ingest, populate the object’s declared fields directly and pass it to log_turn / log_conversation.
Last modified on September 30, 2026