> For the complete documentation index, see [llms.txt](https://docs.interactive.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.interactive.ai/sdk/media.md).

# Media

## Overview

Upload and resolve media references embedded in trace input/output data.

***

## `resolve_media_references` [(source)](https://github.com/interactive-ai/interactiveai-python-sdk/blob/main/interactiveai/_client/client.py#L2895)

Replace media reference strings in an object with base64 data URIs.

This method recursively traverses an object (up to max\_depth) looking for media reference strings in the format "@@@interactiveaiMedia:...@@@". When found, it (synchronously) fetches the actual media content using the provided InteractiveAI client and replaces the reference string with a base64 data URI.

If fetching media content fails for a reference string, a warning is logged and the reference string is left unchanged.

```python
resolve_media_references(
    *,
    obj: Any,
    resolve_with: Literal['base64_data_uri'],
    max_depth: int = 10,
    content_fetch_timeout_seconds: int = 5,
) -> Any
```

**Parameters**

* `obj` — The object to process. Can be a primitive value, array, or nested object. If the object has a **dict** attribute, a dict will be returned instead of the original object type.
* `resolve_with` — The representation of the media content to replace the media reference string with. Currently only "base64\_data\_uri" is supported.
* `max_depth` — int: The maximum depth to traverse the object. Default is 10.
* `content_fetch_timeout_seconds` — int: The timeout in seconds for fetching media content. Default is 5.

**Returns**

A deep copy of the input object with all media references replaced with base64 data URIs where possible. If the input object has a **dict** attribute, a dict will be returned instead of the original object type.

**Example**

```python
obj = {
    "image": "@@@interactiveaiMedia:type=image/jpeg|id=123|source=bytes@@@",
    "nested": {
        "pdf": "@@@interactiveaiMedia:type=application/pdf|id=456|source=bytes@@@"
    }
}

result = await InteractiveAIMedia.resolve_media_references(obj, interactiveai_client)

# Result:
# {
#     "image": "data:image/jpeg;base64,/9j/4AAQSkZJRg...",
#     "nested": {
#         "pdf": "data:application/pdf;base64,JVBERi0xLjcK..."
#     }
# }
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.interactive.ai/sdk/media.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
