# Log media & attachments

> Capture multimodal traces in Opik by logging images, videos, and audio files using the Python SDK's Attachment type.

Opik supports multimodal traces allowing you to track not just the text input
and output of your LLM, but also images, videos and audio and any other media.

<Frame>
  <img src="https://files.buildwithfern.com/https://opik.docs.buildwithfern.com/docs/opik/2026-01-30T17:33:07.444Z/img/tracing/attachments.png" />
</Frame>

## Logging Attachments

In the Python SDK, you can use the `Attachment` type to add files to your traces.
Attachements can be images, videos, audio files or any other file that you might
want to log to Opik.

Each attachment is made up of the following fields:

* `data`: The path to the file, raw bytes, or a base64 encoded string of the file
* `file_name`: Optional name for the attachment (required when using raw bytes without a file path)
* `content_type`: The content type of the file formatted as a MIME type

These attachements can then be logged to your traces and spans using The
`opik_context.update_current_span` and `opik_context.update_current_trace`
methods:

### Using file paths

The most common way to log attachments is by providing a file path:

```python wordWrap
from opik import opik_context, track, Attachment

@track
def my_llm_agent(input):
    # LLM chain code
    # ...

    # Update the trace with a file path
    opik_context.update_current_trace(
        attachments=[
            Attachment(
                data="<path to the image>",
                content_type="image/png",
            )
        ]
    )

    return "World!"

print(my_llm_agent("Hello!"))
```

### Using raw bytes (file-like data)

You can also pass raw bytes directly to an attachment. This is useful when you have
file content in memory (e.g., from an API response, generated content, or streaming data)
and don't want to write it to disk first:

```python wordWrap
from opik import opik_context, track, Attachment

@track
def process_image(image_bytes: bytes):
    # Process the image
    # ...

    # Log the raw bytes as an attachment
    opik_context.update_current_trace(
        attachments=[
            Attachment(
                data=image_bytes,  # Raw bytes
                file_name="processed_image.png",  # Required for bytes
                content_type="image/png",
            )
        ]
    )

    return "Image processed!"