Overview
The easiest way to log media in Weave is to use type annotations likeAnnotated[bytes, Content] or Annotated[str, Content] as input or return types in your ops. You can also annotate path arguments with Annotated[str, Content] and Weave will automatically open, detect and display the media for you within your trace.
The examples in this guide use annotations. We recommend using annotations because they are the simplest way to start logging your media. For more advanced configurations, see the Content API section.
Each media section in this guide contains a basic quick-start code snippet and a usable example.
Images
Quickstart
Log images by annotating functions withAnnotated[bytes, Content] types or filepaths with Annotated[str, Content].
The following example draws a basic image and then logs it to Weave using the Content annotation:
- pip
- uv
Images
- pip
- uv
- Python
- TypeScript

Resize large images before logging
It can be helpful to resize images before logging to reduce UI rendering cost and storage impact. You can usepostprocess_output in your @weave.op to resize an image.
Video
Log videos by annotating functions withAnnotated[bytes, Content] types. Weave automatically handles mp4 videos. Here’s a simple example:
Quickstart
- pip
- uv
Example
The following example shows how to log video within a video-understanding project:- pip
- uv

Documents
Log documents by annotating functions withAnnotated[bytes, Content] types, or by specifying the document type with Annotated[str, Content[Literal['text']].
Weave automatically handles pdf, csv, md, text, json, xml file types. You can also log using file paths with Annotated[str, Content].
Quickstart
The following example shows how stores copies of the input PDF and CSV files, and then stores the file contents returned by the function:- pip
- uv
Example
This example demonstrates how to log documents within a Retrieval-Augmented Generation (RAG) system:- pip
- uv

Audio
Log audio to Weave by annotating functions withAnnotated[bytes, Content] types, or by specifying the document type with Annotated[str, Content[Literal['mp3']].
Weave automatically handles mp3, wav, flac, ogg and m4a file types. You can also log using file paths with Annotated[str, Content].
Quickstart
The following code snippet generates a sine wave, records it, and then logs the audio to Weave:- pip
- uv
Example
This example generates and logs AI-created audio using theContent annotation:
- pip
- uv

- Python
- TypeScript

Try in Colab
HTML
Log interactive HTML by annotating functions withAnnotated[str, Content[Literal['html']].
Quickstart
- pip
- uv
Example
This example generates self-contained HTML pages using W&B Inference and logs the pages to Weave:- pip
- uv
file_name.html cell in the table opens it in full screen. You can also download the raw .html file.

Using the Contents API
The Content API handles media objects in Weave. It allows you to import content into Weave as base64 data, file paths, raw bytes, or text.The Content API is only available in Python.
Usage
There are two primary ways to use the Content API: type annotations and direct initialization. Type annotations automatically detect the proper constructor to use, while direct initialization provides more fine-grained control and lets you take advantage of runtime features of the Content API in your code.Type Annotations
The Weave Content API is designed to primarily be used through type annotations, which signal to Weave that traced inputs and outputs should be processed and stored as content blobs.Direct Initialization
If you want to take advantage of features, such as:- Opening a file with a default application (such as a PDF viewer)
- Dumping the model to JSON to upload to your own blob storage (such as S3)
- Passing custom metadata to associate with the
Contentblob (such as the model used to generate it)
Content.from_path- Create from a file pathContent.from_bytes- Create from raw bytesContent.from_text- Create from text stringContent.from_base64- Create from base64-encoded data
Custom Mimetypes
Weave can detect most binary mimetypes, but custom mimetypes and text documents such as markdown may not be automatically detected, requiring you to manually specify the mimetype or extension of your file.Custom Mimetypes with Type Annotations
Custom Mimetypes with Direct Initialization
Content properties
For a comprehensive list of class attributes and methods, view the Content reference docsAttributes
Utility Methods
save(dest: str | Path) -> None: Save content to a fileopen() -> bool: Open file using system default application (requires the content to have been saved or loaded from a path)as_string() -> str: Display the data as a string (bytes are decoded using the encoding attribute)
Initialization Methods
Createcontent object from a file path:
content object from raw bytes:
content object from text:
content object from base64-encoded data: