# 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..."
#     }
# }
```
