Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions py/src/braintrust/integrations/adk/tracing.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,8 @@
from typing import Any, cast

from braintrust.bt_json import bt_safe_deep_copy
from braintrust.logger import Attachment, start_span
from braintrust.integrations.utils import _attachment_from_bytes, _image_url_payload
from braintrust.logger import start_span
from braintrust.span_types import SpanTypeAttribute


Expand DownExpand Up@@ -59,12 +60,10 @@ def _serialize_part(part: Any) -> Any:

# Convert bytes to Attachment
if isinstance(data, bytes):
extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
filename = f"file.{extension}"
attachment = Attachment(data=data, filename=filename, content_type=mime_type)
attachment = _attachment_from_bytes(data, mime_type)

# Return in image_url format - SDK will replace with AttachmentReference
return {"image_url": {"url": attachment}}
return _image_url_payload(attachment)

# Handle Part objects with file_data (file references)
if hasattr(part, "file_data") and part.file_data:
Expand Down
25 changes: 11 additions & 14 deletions py/src/braintrust/integrations/anthropic/tracing.py
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
import base64
import logging
import time
import warnings

from braintrust.bt_json import bt_safe_deep_copy
from braintrust.integrations.anthropic._utils import Wrapper, extract_anthropic_usage
from braintrust.logger import Attachment, log_exc_info_to_span, start_span
from braintrust.integrations.utils import (
_attachment_filename_for_mime_type,
_attachment_from_base64_data,
_image_url_payload,
)
from braintrust.logger import log_exc_info_to_span, start_span


log = logging.getLogger(__name__)
Expand DownExpand Up@@ -410,10 +414,8 @@ def _start_batch_results_span(args, kwargs):


def _attachment_filename_for_media_type(media_type: str, block_type: str) -> str:
extension = media_type.split("/", 1)[1] if "/" in media_type else "bin"
extension = extension.split("+", 1)[0]
prefix = "image" if block_type == "image" else "document"
return f"{prefix}.{extension}"
return _attachment_filename_for_mime_type(media_type, prefix=prefix)


def _convert_base64_source_to_attachment(block_type, source):
Expand All@@ -427,15 +429,10 @@ def _convert_base64_source_to_attachment(block_type, source):
if not isinstance(media_type, str) or not isinstance(data, str):
return None

try:
binary_data = base64.b64decode(data, validate=True)
except Exception:
return None

return Attachment(
data=binary_data,
return _attachment_from_base64_data(
data,
media_type,
filename=_attachment_filename_for_media_type(media_type, block_type),
content_type=media_type,
)


Expand All@@ -452,7 +449,7 @@ def _process_input_attachments(value):
if attachment is not None:
processed = {k: _process_input_attachments(v) for k, v in value.items() if k != "source"}
processed["source"] = {k: _process_input_attachments(v) for k, v in source.items() if k != "data"}
processed["image_url"] = {"url": attachment}
processed.update(_image_url_payload(attachment))
return processed

return {k: _process_input_attachments(v) for k, v in value.items()}
Expand Down
42 changes: 14 additions & 28 deletions py/src/braintrust/integrations/google_genai/tracing.py
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
"""Google GenAI-specific span creation, metadata extraction, stream handling, and output normalization."""

import base64
import binascii
import contextvars
import dataclasses
import logging
Expand All@@ -12,6 +10,12 @@
from typing import TYPE_CHECKING, Any

from braintrust.bt_json import bt_safe_deep_copy
from braintrust.integrations.utils import (
_attachment_filename_for_mime_type,
_attachment_from_base64_data,
_attachment_from_bytes,
_image_url_payload,
)
from braintrust.logger import Attachment, start_span
from braintrust.span_types import SpanTypeAttribute
from braintrust.util import clean_nones
Expand DownExpand Up@@ -114,16 +118,11 @@ def _serialize_content_item(item: Any) -> Any:

# Ensure data is bytes
if isinstance(data, bytes):
# Determine file extension from mime type
extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
filename = f"file.{extension}"

# Create an Attachment object
attachment = Attachment(data=data, filename=filename, content_type=mime_type)
attachment = _attachment_from_bytes(data, mime_type)

# Return the attachment object in image_url format
# The SDK's _extract_attachments will replace it with its reference when logging
return {"image_url": {"url": attachment}}
return _image_url_payload(attachment)

# Try to use built-in serialization if available
if hasattr(item, "model_dump"):
Expand DownExpand Up@@ -156,21 +155,6 @@ def _serialize_tools(api_client: Any, input: Any | None) -> Any | None:
return None


def _attachment_from_base64_data(data: str, mime_type: str, *, label: str) -> Attachment | None:
raw_data = data
if raw_data.startswith("data:"):
_, _, encoded = raw_data.partition(",")
raw_data = encoded

try:
decoded = base64.b64decode(raw_data, validate=True)
except (ValueError, binascii.Error):
return None

extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
return Attachment(data=decoded, filename=f"{label}.{extension}", content_type=mime_type)


def _serialize_interaction_content_dict(value: dict[str, Any]) -> dict[str, Any]:
serialized = {key: _serialize_interaction_value(val) for key, val in value.items() if val is not None}

Expand DownExpand Up@@ -402,10 +386,12 @@ def _extract_generate_images_output(response: Any) -> dict[str, Any]:
# Convert image bytes to an Attachment so the SDK uploads them to
# object storage and the Braintrust UI can render the image.
if isinstance(image_bytes, bytes) and mime_type:
extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
filename = f"generated_image_{i}.{extension}"
attachment = Attachment(data=image_bytes, filename=filename, content_type=mime_type)
image_entry["image_url"] = {"url": attachment}
attachment = _attachment_from_bytes(
image_bytes,
mime_type,
filename=_attachment_filename_for_mime_type(mime_type, prefix=f"generated_image_{i}"),
)
image_entry.update(_image_url_payload(attachment))

serialized_images.append(image_entry)

Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
interactions:
- request:
body: !!binary |
LS0xYWVjMzE5NmZmOTMxMWI1NzJjNjI3YmZlNmFiOTg0ZA0KQ29udGVudC1EaXNwb3NpdGlvbjog
Zm9ybS1kYXRhOyBuYW1lPSJwcm9tcHQiDQoNCkFkZCBhIGJsdWUgYm9yZGVyDQotLTFhZWMzMTk2
ZmY5MzExYjU3MmM2MjdiZmU2YWI5ODRkDQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9Im1vZGVsIg0KDQpkYWxsLWUtMg0KLS0xYWVjMzE5NmZmOTMxMWI1NzJjNjI3YmZlNmFi
OTg0ZA0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJyZXNwb25zZV9mb3Jt
YXQiDQoNCnVybA0KLS0xYWVjMzE5NmZmOTMxMWI1NzJjNjI3YmZlNmFiOTg0ZA0KQ29udGVudC1E
aXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJzaXplIg0KDQoyNTZ4MjU2DQotLTFhZWMzMTk2
ZmY5MzExYjU3MmM2MjdiZmU2YWI5ODRkDQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9ImltYWdlIjsgZmlsZW5hbWU9ImJyYWludHJ1c3QtdGVzdC1pbWFnZS5wbmciDQpDb250
ZW50LVR5cGU6IGltYWdlL3BuZw0KDQqJUE5HDQoaCgAAAA1JSERSAAAAQAAAAEAIBgAAAKppcd4A
AACUSURBVHic7dAxEQAwEMOw8Cf9haGhHrT7vNvuZ9MBWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1
QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYA
HaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoD0OI4dJt2PESAAAAAElFTkSuQmCC
DQotLTFhZWMzMTk2ZmY5MzExYjU3MmM2MjdiZmU2YWI5ODRkLS0NCg==
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate, zstd
Connection:
- keep-alive
Content-Length:
- '781'
Content-Type:
- multipart/form-data; boundary=1aec3196ff9311b572c627bfe6ab984d
Host:
- api.openai.com
User-Agent:
- OpenAI/Python 2.24.0
X-Stainless-Arch:
- arm64
X-Stainless-Async:
- 'false'
X-Stainless-Lang:
- python
X-Stainless-OS:
- MacOS
X-Stainless-Package-Version:
- 2.24.0
X-Stainless-Runtime:
- CPython
X-Stainless-Runtime-Version:
- 3.13.3
x-stainless-read-timeout:
- '600'
x-stainless-retry-count:
- '0'
method: POST
uri: https://api.openai.com/v1/images/edits
response:
body:
string: "{\n \"created\": 1775759071,\n \"data\": [\n {\n \"url\":
\"https://oaidalleapiprodscus.blob.core.windows.net/private/org-gY2CWXtioLkEfpHBJTrcdNID/user-jIouncdtCNqBNU7Q41fsSvZ2/img-sWsBgQsG5L08pmtO95p4nUGz.png?st=2026-04-09T17%3A24%3A31Z&se=2026-04-09T19%3A24%3A31Z&sp=r&sv=2026-02-06&sr=b&rscd=inline&rsct=image/png&skoid=8b33a531-2df9-46a3-bc02-d4b1430a422c&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2026-04-09T18%3A21%3A40Z&ske=2026-04-10T18%3A21%3A40Z&sks=b&skv=2026-02-06&sig=IWn2M3VRWKx8z8T9b95nfRa5EjAhZCemDwua6t23EbQ%3D\"\n
\ }\n ]\n}"
headers:
CF-RAY:
- 9e9b8c57af1fa06e-YYZ
Connection:
- keep-alive
Content-Type:
- application/json
Date:
- Thu, 09 Apr 2026 18:24:31 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=31536000; includeSubDomains; preload
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
content-length:
- '544'
openai-organization:
- braintrust-data
openai-processing-ms:
- '9957'
openai-project:
- proj_vsCSXafhhByzWOThMrJcZiw9
openai-version:
- '2020-10-01'
set-cookie:
- __cf_bm=awSasqBRHVxTDWJEEP6Qw.Xnqko8SJvLBvYIJ5jhC_A-1775759061.7060604-1.0.1.1-NR9TiN9VkB6eP1aqSC3oqHyb_wYQQnIHT18qD4FrGpG6IOP0xE56iRyQ.EI8ZSpFKitT8V1qfALR7m2lodLMoXKxbNtwd..QCsUA1.7NbCTBFr61c7xZAZkBq7cQZGkp;
HttpOnly; Secure; Path=/; Domain=api.openai.com; Expires=Thu, 09 Apr 2026
18:54:31 GMT
x-request-id:
- req_23c05ec9d803459aa51a6bb3f029020a
status:
code: 200
message: OK
- request:
body: !!binary |
LS05Y2M1YWFiZWJlMmFkMTE4MzdlNGVmNjQ1MWEyMTcyOA0KQ29udGVudC1EaXNwb3NpdGlvbjog
Zm9ybS1kYXRhOyBuYW1lPSJwcm9tcHQiDQoNCkFkZCBhIGJsdWUgYm9yZGVyDQotLTljYzVhYWJl
YmUyYWQxMTgzN2U0ZWY2NDUxYTIxNzI4DQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9Im1vZGVsIg0KDQpkYWxsLWUtMg0KLS05Y2M1YWFiZWJlMmFkMTE4MzdlNGVmNjQ1MWEy
MTcyOA0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJyZXNwb25zZV9mb3Jt
YXQiDQoNCnVybA0KLS05Y2M1YWFiZWJlMmFkMTE4MzdlNGVmNjQ1MWEyMTcyOA0KQ29udGVudC1E
aXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJzaXplIg0KDQoyNTZ4MjU2DQotLTljYzVhYWJl
YmUyYWQxMTgzN2U0ZWY2NDUxYTIxNzI4DQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9ImltYWdlIjsgZmlsZW5hbWU9ImJyYWludHJ1c3QtdGVzdC1pbWFnZS5wbmciDQpDb250
ZW50LVR5cGU6IGltYWdlL3BuZw0KDQqJUE5HDQoaCgAAAA1JSERSAAAAQAAAAEAIBgAAAKppcd4A
AACUSURBVHic7dAxEQAwEMOw8Cf9haGhHrT7vNvuZ9MBWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1
QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYA
HaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoD0OI4dJt2PESAAAAAElFTkSuQmCC
DQotLTljYzVhYWJlYmUyYWQxMTgzN2U0ZWY2NDUxYTIxNzI4LS0NCg==
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate, zstd
Connection:
- keep-alive
Content-Length:
- '781'
Content-Type:
- multipart/form-data; boundary=9cc5aabebe2ad11837e4ef6451a21728
Host:
- api.openai.com
User-Agent:
- OpenAI/Python 2.24.0
X-Stainless-Arch:
- arm64
X-Stainless-Async:
- 'false'
X-Stainless-Lang:
- python
X-Stainless-OS:
- MacOS
X-Stainless-Package-Version:
- 2.24.0
X-Stainless-Runtime:
- CPython
X-Stainless-Runtime-Version:
- 3.13.3
x-stainless-read-timeout:
- '600'
x-stainless-retry-count:
- '0'
method: POST
uri: https://api.openai.com/v1/images/edits
response:
body:
string: "{\n \"created\": 1775759080,\n \"data\": [\n {\n \"url\":
\"https://oaidalleapiprodscus.blob.core.windows.net/private/org-gY2CWXtioLkEfpHBJTrcdNID/user-jIouncdtCNqBNU7Q41fsSvZ2/img-dg5LcnpEkqDsbL996mUGtuR7.png?st=2026-04-09T17%3A24%3A40Z&se=2026-04-09T19%3A24%3A40Z&sp=r&sv=2026-02-06&sr=b&rscd=inline&rsct=image/png&skoid=7daae675-7b42-4e2e-ab4c-8d8419a28d99&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2026-04-09T11%3A45%3A25Z&ske=2026-04-10T11%3A45%3A25Z&sks=b&skv=2026-02-06&sig=5xpj5xgDoSam7/osQpyjYWdD0WhqIvwfK6olzqGnNSw%3D\"\n
\ }\n ]\n}"
headers:
CF-RAY:
- 9e9b8c96db4c8e83-YYZ
Connection:
- keep-alive
Content-Type:
- application/json
Date:
- Thu, 09 Apr 2026 18:24:40 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=31536000; includeSubDomains; preload
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
content-length:
- '544'
openai-organization:
- braintrust-data
openai-processing-ms:
- '8841'
openai-project:
- proj_vsCSXafhhByzWOThMrJcZiw9
openai-version:
- '2020-10-01'
set-cookie:
- __cf_bm=71VJ5AXIV3KbEjxMwRTgzN6wXFuq_FJpfnaclJQEftA-1775759071.815464-1.0.1.1-KlPEAAV9pa1hiqAJSUM_1Hphmoc2bA67hnze_M9BLdP4BVlQNYOk7VfapD42MqF4SAAUD2srxAuNDxLnBCFHf1KO76acIfz5vC2uIwFn8Zsbn04ItH_OHQSg_bkamfxn;
HttpOnly; Secure; Path=/; Domain=api.openai.com; Expires=Thu, 09 Apr 2026
18:54:40 GMT
x-request-id:
- req_4a84ca0d8b6641c0b92a54393a75f44b
status:
code: 200
message: OK
version: 1
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions py/src/braintrust/integrations/adk/tracing.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,8 @@
from typing import Any, cast

from braintrust.bt_json import bt_safe_deep_copy
from braintrust.logger import Attachment, start_span
from braintrust.integrations.utils import _attachment_from_bytes, _image_url_payload
from braintrust.logger import start_span
from braintrust.span_types import SpanTypeAttribute


Expand DownExpand Up@@ -59,12 +60,10 @@ def _serialize_part(part: Any) -> Any:

# Convert bytes to Attachment
if isinstance(data, bytes):
extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
filename = f"file.{extension}"
attachment = Attachment(data=data, filename=filename, content_type=mime_type)
attachment = _attachment_from_bytes(data, mime_type)

# Return in image_url format - SDK will replace with AttachmentReference
return {"image_url": {"url": attachment}}
return _image_url_payload(attachment)

# Handle Part objects with file_data (file references)
if hasattr(part, "file_data") and part.file_data:
Expand Down
25 changes: 11 additions & 14 deletions py/src/braintrust/integrations/anthropic/tracing.py
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
import base64
import logging
import time
import warnings

from braintrust.bt_json import bt_safe_deep_copy
from braintrust.integrations.anthropic._utils import Wrapper, extract_anthropic_usage
from braintrust.logger import Attachment, log_exc_info_to_span, start_span
from braintrust.integrations.utils import (
_attachment_filename_for_mime_type,
_attachment_from_base64_data,
_image_url_payload,
)
from braintrust.logger import log_exc_info_to_span, start_span


log = logging.getLogger(__name__)
Expand DownExpand Up@@ -410,10 +414,8 @@ def _start_batch_results_span(args, kwargs):


def _attachment_filename_for_media_type(media_type: str, block_type: str) -> str:
extension = media_type.split("/", 1)[1] if "/" in media_type else "bin"
extension = extension.split("+", 1)[0]
prefix = "image" if block_type == "image" else "document"
return f"{prefix}.{extension}"
return _attachment_filename_for_mime_type(media_type, prefix=prefix)


def _convert_base64_source_to_attachment(block_type, source):
Expand All@@ -427,15 +429,10 @@ def _convert_base64_source_to_attachment(block_type, source):
if not isinstance(media_type, str) or not isinstance(data, str):
return None

try:
binary_data = base64.b64decode(data, validate=True)
except Exception:
return None

return Attachment(
data=binary_data,
return _attachment_from_base64_data(
data,
media_type,
filename=_attachment_filename_for_media_type(media_type, block_type),
content_type=media_type,
)


Expand All@@ -452,7 +449,7 @@ def _process_input_attachments(value):
if attachment is not None:
processed = {k: _process_input_attachments(v) for k, v in value.items() if k != "source"}
processed["source"] = {k: _process_input_attachments(v) for k, v in source.items() if k != "data"}
processed["image_url"] = {"url": attachment}
processed.update(_image_url_payload(attachment))
return processed

return {k: _process_input_attachments(v) for k, v in value.items()}
Expand Down
42 changes: 14 additions & 28 deletions py/src/braintrust/integrations/google_genai/tracing.py
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
"""Google GenAI-specific span creation, metadata extraction, stream handling, and output normalization."""

import base64
import binascii
import contextvars
import dataclasses
import logging
Expand All@@ -12,6 +10,12 @@
from typing import TYPE_CHECKING, Any

from braintrust.bt_json import bt_safe_deep_copy
from braintrust.integrations.utils import (
_attachment_filename_for_mime_type,
_attachment_from_base64_data,
_attachment_from_bytes,
_image_url_payload,
)
from braintrust.logger import Attachment, start_span
from braintrust.span_types import SpanTypeAttribute
from braintrust.util import clean_nones
Expand DownExpand Up@@ -114,16 +118,11 @@ def _serialize_content_item(item: Any) -> Any:

# Ensure data is bytes
if isinstance(data, bytes):
# Determine file extension from mime type
extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
filename = f"file.{extension}"

# Create an Attachment object
attachment = Attachment(data=data, filename=filename, content_type=mime_type)
attachment = _attachment_from_bytes(data, mime_type)

# Return the attachment object in image_url format
# The SDK's _extract_attachments will replace it with its reference when logging
return {"image_url": {"url": attachment}}
return _image_url_payload(attachment)

# Try to use built-in serialization if available
if hasattr(item, "model_dump"):
Expand DownExpand Up@@ -156,21 +155,6 @@ def _serialize_tools(api_client: Any, input: Any | None) -> Any | None:
return None


def _attachment_from_base64_data(data: str, mime_type: str, *, label: str) -> Attachment | None:
raw_data = data
if raw_data.startswith("data:"):
_, _, encoded = raw_data.partition(",")
raw_data = encoded

try:
decoded = base64.b64decode(raw_data, validate=True)
except (ValueError, binascii.Error):
return None

extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
return Attachment(data=decoded, filename=f"{label}.{extension}", content_type=mime_type)


def _serialize_interaction_content_dict(value: dict[str, Any]) -> dict[str, Any]:
serialized = {key: _serialize_interaction_value(val) for key, val in value.items() if val is not None}

Expand DownExpand Up@@ -402,10 +386,12 @@ def _extract_generate_images_output(response: Any) -> dict[str, Any]:
# Convert image bytes to an Attachment so the SDK uploads them to
# object storage and the Braintrust UI can render the image.
if isinstance(image_bytes, bytes) and mime_type:
extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
filename = f"generated_image_{i}.{extension}"
attachment = Attachment(data=image_bytes, filename=filename, content_type=mime_type)
image_entry["image_url"] = {"url": attachment}
attachment = _attachment_from_bytes(
image_bytes,
mime_type,
filename=_attachment_filename_for_mime_type(mime_type, prefix=f"generated_image_{i}"),
)
image_entry.update(_image_url_payload(attachment))

serialized_images.append(image_entry)

Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
interactions:
- request:
body: !!binary |
LS0xYWVjMzE5NmZmOTMxMWI1NzJjNjI3YmZlNmFiOTg0ZA0KQ29udGVudC1EaXNwb3NpdGlvbjog
Zm9ybS1kYXRhOyBuYW1lPSJwcm9tcHQiDQoNCkFkZCBhIGJsdWUgYm9yZGVyDQotLTFhZWMzMTk2
ZmY5MzExYjU3MmM2MjdiZmU2YWI5ODRkDQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9Im1vZGVsIg0KDQpkYWxsLWUtMg0KLS0xYWVjMzE5NmZmOTMxMWI1NzJjNjI3YmZlNmFi
OTg0ZA0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJyZXNwb25zZV9mb3Jt
YXQiDQoNCnVybA0KLS0xYWVjMzE5NmZmOTMxMWI1NzJjNjI3YmZlNmFiOTg0ZA0KQ29udGVudC1E
aXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJzaXplIg0KDQoyNTZ4MjU2DQotLTFhZWMzMTk2
ZmY5MzExYjU3MmM2MjdiZmU2YWI5ODRkDQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9ImltYWdlIjsgZmlsZW5hbWU9ImJyYWludHJ1c3QtdGVzdC1pbWFnZS5wbmciDQpDb250
ZW50LVR5cGU6IGltYWdlL3BuZw0KDQqJUE5HDQoaCgAAAA1JSERSAAAAQAAAAEAIBgAAAKppcd4A
AACUSURBVHic7dAxEQAwEMOw8Cf9haGhHrT7vNvuZ9MBWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1
QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYA
HaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoD0OI4dJt2PESAAAAAElFTkSuQmCC
DQotLTFhZWMzMTk2ZmY5MzExYjU3MmM2MjdiZmU2YWI5ODRkLS0NCg==
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate, zstd
Connection:
- keep-alive
Content-Length:
- '781'
Content-Type:
- multipart/form-data; boundary=1aec3196ff9311b572c627bfe6ab984d
Host:
- api.openai.com
User-Agent:
- OpenAI/Python 2.24.0
X-Stainless-Arch:
- arm64
X-Stainless-Async:
- 'false'
X-Stainless-Lang:
- python
X-Stainless-OS:
- MacOS
X-Stainless-Package-Version:
- 2.24.0
X-Stainless-Runtime:
- CPython
X-Stainless-Runtime-Version:
- 3.13.3
x-stainless-read-timeout:
- '600'
x-stainless-retry-count:
- '0'
method: POST
uri: https://api.openai.com/v1/images/edits
response:
body:
string: "{\n \"created\": 1775759071,\n \"data\": [\n {\n \"url\":
\"https://oaidalleapiprodscus.blob.core.windows.net/private/org-gY2CWXtioLkEfpHBJTrcdNID/user-jIouncdtCNqBNU7Q41fsSvZ2/img-sWsBgQsG5L08pmtO95p4nUGz.png?st=2026-04-09T17%3A24%3A31Z&se=2026-04-09T19%3A24%3A31Z&sp=r&sv=2026-02-06&sr=b&rscd=inline&rsct=image/png&skoid=8b33a531-2df9-46a3-bc02-d4b1430a422c&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2026-04-09T18%3A21%3A40Z&ske=2026-04-10T18%3A21%3A40Z&sks=b&skv=2026-02-06&sig=IWn2M3VRWKx8z8T9b95nfRa5EjAhZCemDwua6t23EbQ%3D\"\n
\ }\n ]\n}"
headers:
CF-RAY:
- 9e9b8c57af1fa06e-YYZ
Connection:
- keep-alive
Content-Type:
- application/json
Date:
- Thu, 09 Apr 2026 18:24:31 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=31536000; includeSubDomains; preload
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
content-length:
- '544'
openai-organization:
- braintrust-data
openai-processing-ms:
- '9957'
openai-project:
- proj_vsCSXafhhByzWOThMrJcZiw9
openai-version:
- '2020-10-01'
set-cookie:
- __cf_bm=awSasqBRHVxTDWJEEP6Qw.Xnqko8SJvLBvYIJ5jhC_A-1775759061.7060604-1.0.1.1-NR9TiN9VkB6eP1aqSC3oqHyb_wYQQnIHT18qD4FrGpG6IOP0xE56iRyQ.EI8ZSpFKitT8V1qfALR7m2lodLMoXKxbNtwd..QCsUA1.7NbCTBFr61c7xZAZkBq7cQZGkp;
HttpOnly; Secure; Path=/; Domain=api.openai.com; Expires=Thu, 09 Apr 2026
18:54:31 GMT
x-request-id:
- req_23c05ec9d803459aa51a6bb3f029020a
status:
code: 200
message: OK
- request:
body: !!binary |
LS05Y2M1YWFiZWJlMmFkMTE4MzdlNGVmNjQ1MWEyMTcyOA0KQ29udGVudC1EaXNwb3NpdGlvbjog
Zm9ybS1kYXRhOyBuYW1lPSJwcm9tcHQiDQoNCkFkZCBhIGJsdWUgYm9yZGVyDQotLTljYzVhYWJl
YmUyYWQxMTgzN2U0ZWY2NDUxYTIxNzI4DQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9Im1vZGVsIg0KDQpkYWxsLWUtMg0KLS05Y2M1YWFiZWJlMmFkMTE4MzdlNGVmNjQ1MWEy
MTcyOA0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJyZXNwb25zZV9mb3Jt
YXQiDQoNCnVybA0KLS05Y2M1YWFiZWJlMmFkMTE4MzdlNGVmNjQ1MWEyMTcyOA0KQ29udGVudC1E
aXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJzaXplIg0KDQoyNTZ4MjU2DQotLTljYzVhYWJl
YmUyYWQxMTgzN2U0ZWY2NDUxYTIxNzI4DQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9ImltYWdlIjsgZmlsZW5hbWU9ImJyYWludHJ1c3QtdGVzdC1pbWFnZS5wbmciDQpDb250
ZW50LVR5cGU6IGltYWdlL3BuZw0KDQqJUE5HDQoaCgAAAA1JSERSAAAAQAAAAEAIBgAAAKppcd4A
AACUSURBVHic7dAxEQAwEMOw8Cf9haGhHrT7vNvuZ9MBWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1
QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYA
HaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoD0OI4dJt2PESAAAAAElFTkSuQmCC
DQotLTljYzVhYWJlYmUyYWQxMTgzN2U0ZWY2NDUxYTIxNzI4LS0NCg==
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate, zstd
Connection:
- keep-alive
Content-Length:
- '781'
Content-Type:
- multipart/form-data; boundary=9cc5aabebe2ad11837e4ef6451a21728
Host:
- api.openai.com
User-Agent:
- OpenAI/Python 2.24.0
X-Stainless-Arch:
- arm64
X-Stainless-Async:
- 'false'
X-Stainless-Lang:
- python
X-Stainless-OS:
- MacOS
X-Stainless-Package-Version:
- 2.24.0
X-Stainless-Runtime:
- CPython
X-Stainless-Runtime-Version:
- 3.13.3
x-stainless-read-timeout:
- '600'
x-stainless-retry-count:
- '0'
method: POST
uri: https://api.openai.com/v1/images/edits
response:
body:
string: "{\n \"created\": 1775759080,\n \"data\": [\n {\n \"url\":
\"https://oaidalleapiprodscus.blob.core.windows.net/private/org-gY2CWXtioLkEfpHBJTrcdNID/user-jIouncdtCNqBNU7Q41fsSvZ2/img-dg5LcnpEkqDsbL996mUGtuR7.png?st=2026-04-09T17%3A24%3A40Z&se=2026-04-09T19%3A24%3A40Z&sp=r&sv=2026-02-06&sr=b&rscd=inline&rsct=image/png&skoid=7daae675-7b42-4e2e-ab4c-8d8419a28d99&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2026-04-09T11%3A45%3A25Z&ske=2026-04-10T11%3A45%3A25Z&sks=b&skv=2026-02-06&sig=5xpj5xgDoSam7/osQpyjYWdD0WhqIvwfK6olzqGnNSw%3D\"\n
\ }\n ]\n}"
headers:
CF-RAY:
- 9e9b8c96db4c8e83-YYZ
Connection:
- keep-alive
Content-Type:
- application/json
Date:
- Thu, 09 Apr 2026 18:24:40 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=31536000; includeSubDomains; preload
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
content-length:
- '544'
openai-organization:
- braintrust-data
openai-processing-ms:
- '8841'
openai-project:
- proj_vsCSXafhhByzWOThMrJcZiw9
openai-version:
- '2020-10-01'
set-cookie:
- __cf_bm=71VJ5AXIV3KbEjxMwRTgzN6wXFuq_FJpfnaclJQEftA-1775759071.815464-1.0.1.1-KlPEAAV9pa1hiqAJSUM_1Hphmoc2bA67hnze_M9BLdP4BVlQNYOk7VfapD42MqF4SAAUD2srxAuNDxLnBCFHf1KO76acIfz5vC2uIwFn8Zsbn04ItH_OHQSg_bkamfxn;
HttpOnly; Secure; Path=/; Domain=api.openai.com; Expires=Thu, 09 Apr 2026
18:54:40 GMT
x-request-id:
- req_4a84ca0d8b6641c0b92a54393a75f44b
status:
code: 200
message: OK
version: 1
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions py/src/braintrust/integrations/adk/tracing.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,8 @@
from typing import Any, cast

from braintrust.bt_json import bt_safe_deep_copy
from braintrust.logger import Attachment, start_span
from braintrust.integrations.utils import _attachment_from_bytes, _image_url_payload
from braintrust.logger import start_span
from braintrust.span_types import SpanTypeAttribute


Expand DownExpand Up@@ -59,12 +60,10 @@ def _serialize_part(part: Any) -> Any:

# Convert bytes to Attachment
if isinstance(data, bytes):
extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
filename = f"file.{extension}"
attachment = Attachment(data=data, filename=filename, content_type=mime_type)
attachment = _attachment_from_bytes(data, mime_type)

# Return in image_url format - SDK will replace with AttachmentReference
return {"image_url": {"url": attachment}}
return _image_url_payload(attachment)

# Handle Part objects with file_data (file references)
if hasattr(part, "file_data") and part.file_data:
Expand Down
25 changes: 11 additions & 14 deletions py/src/braintrust/integrations/anthropic/tracing.py
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
import base64
import logging
import time
import warnings

from braintrust.bt_json import bt_safe_deep_copy
from braintrust.integrations.anthropic._utils import Wrapper, extract_anthropic_usage
from braintrust.logger import Attachment, log_exc_info_to_span, start_span
from braintrust.integrations.utils import (
_attachment_filename_for_mime_type,
_attachment_from_base64_data,
_image_url_payload,
)
from braintrust.logger import log_exc_info_to_span, start_span


log = logging.getLogger(__name__)
Expand DownExpand Up@@ -410,10 +414,8 @@ def _start_batch_results_span(args, kwargs):


def _attachment_filename_for_media_type(media_type: str, block_type: str) -> str:
extension = media_type.split("/", 1)[1] if "/" in media_type else "bin"
extension = extension.split("+", 1)[0]
prefix = "image" if block_type == "image" else "document"
return f"{prefix}.{extension}"
return _attachment_filename_for_mime_type(media_type, prefix=prefix)


def _convert_base64_source_to_attachment(block_type, source):
Expand All@@ -427,15 +429,10 @@ def _convert_base64_source_to_attachment(block_type, source):
if not isinstance(media_type, str) or not isinstance(data, str):
return None

try:
binary_data = base64.b64decode(data, validate=True)
except Exception:
return None

return Attachment(
data=binary_data,
return _attachment_from_base64_data(
data,
media_type,
filename=_attachment_filename_for_media_type(media_type, block_type),
content_type=media_type,
)


Expand All@@ -452,7 +449,7 @@ def _process_input_attachments(value):
if attachment is not None:
processed = {k: _process_input_attachments(v) for k, v in value.items() if k != "source"}
processed["source"] = {k: _process_input_attachments(v) for k, v in source.items() if k != "data"}
processed["image_url"] = {"url": attachment}
processed.update(_image_url_payload(attachment))
return processed

return {k: _process_input_attachments(v) for k, v in value.items()}
Expand Down
42 changes: 14 additions & 28 deletions py/src/braintrust/integrations/google_genai/tracing.py
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
"""Google GenAI-specific span creation, metadata extraction, stream handling, and output normalization."""

import base64
import binascii
import contextvars
import dataclasses
import logging
Expand All@@ -12,6 +10,12 @@
from typing import TYPE_CHECKING, Any

from braintrust.bt_json import bt_safe_deep_copy
from braintrust.integrations.utils import (
_attachment_filename_for_mime_type,
_attachment_from_base64_data,
_attachment_from_bytes,
_image_url_payload,
)
from braintrust.logger import Attachment, start_span
from braintrust.span_types import SpanTypeAttribute
from braintrust.util import clean_nones
Expand DownExpand Up@@ -114,16 +118,11 @@ def _serialize_content_item(item: Any) -> Any:

# Ensure data is bytes
if isinstance(data, bytes):
# Determine file extension from mime type
extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
filename = f"file.{extension}"

# Create an Attachment object
attachment = Attachment(data=data, filename=filename, content_type=mime_type)
attachment = _attachment_from_bytes(data, mime_type)

# Return the attachment object in image_url format
# The SDK's _extract_attachments will replace it with its reference when logging
return {"image_url": {"url": attachment}}
return _image_url_payload(attachment)

# Try to use built-in serialization if available
if hasattr(item, "model_dump"):
Expand DownExpand Up@@ -156,21 +155,6 @@ def _serialize_tools(api_client: Any, input: Any | None) -> Any | None:
return None


def _attachment_from_base64_data(data: str, mime_type: str, *, label: str) -> Attachment | None:
raw_data = data
if raw_data.startswith("data:"):
_, _, encoded = raw_data.partition(",")
raw_data = encoded

try:
decoded = base64.b64decode(raw_data, validate=True)
except (ValueError, binascii.Error):
return None

extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
return Attachment(data=decoded, filename=f"{label}.{extension}", content_type=mime_type)


def _serialize_interaction_content_dict(value: dict[str, Any]) -> dict[str, Any]:
serialized = {key: _serialize_interaction_value(val) for key, val in value.items() if val is not None}

Expand DownExpand Up@@ -402,10 +386,12 @@ def _extract_generate_images_output(response: Any) -> dict[str, Any]:
# Convert image bytes to an Attachment so the SDK uploads them to
# object storage and the Braintrust UI can render the image.
if isinstance(image_bytes, bytes) and mime_type:
extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
filename = f"generated_image_{i}.{extension}"
attachment = Attachment(data=image_bytes, filename=filename, content_type=mime_type)
image_entry["image_url"] = {"url": attachment}
attachment = _attachment_from_bytes(
image_bytes,
mime_type,
filename=_attachment_filename_for_mime_type(mime_type, prefix=f"generated_image_{i}"),
)
image_entry.update(_image_url_payload(attachment))

serialized_images.append(image_entry)

Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
interactions:
- request:
body: !!binary |
LS0xYWVjMzE5NmZmOTMxMWI1NzJjNjI3YmZlNmFiOTg0ZA0KQ29udGVudC1EaXNwb3NpdGlvbjog
Zm9ybS1kYXRhOyBuYW1lPSJwcm9tcHQiDQoNCkFkZCBhIGJsdWUgYm9yZGVyDQotLTFhZWMzMTk2
ZmY5MzExYjU3MmM2MjdiZmU2YWI5ODRkDQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9Im1vZGVsIg0KDQpkYWxsLWUtMg0KLS0xYWVjMzE5NmZmOTMxMWI1NzJjNjI3YmZlNmFi
OTg0ZA0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJyZXNwb25zZV9mb3Jt
YXQiDQoNCnVybA0KLS0xYWVjMzE5NmZmOTMxMWI1NzJjNjI3YmZlNmFiOTg0ZA0KQ29udGVudC1E
aXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJzaXplIg0KDQoyNTZ4MjU2DQotLTFhZWMzMTk2
ZmY5MzExYjU3MmM2MjdiZmU2YWI5ODRkDQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9ImltYWdlIjsgZmlsZW5hbWU9ImJyYWludHJ1c3QtdGVzdC1pbWFnZS5wbmciDQpDb250
ZW50LVR5cGU6IGltYWdlL3BuZw0KDQqJUE5HDQoaCgAAAA1JSERSAAAAQAAAAEAIBgAAAKppcd4A
AACUSURBVHic7dAxEQAwEMOw8Cf9haGhHrT7vNvuZ9MBWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1
QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYA
HaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoD0OI4dJt2PESAAAAAElFTkSuQmCC
DQotLTFhZWMzMTk2ZmY5MzExYjU3MmM2MjdiZmU2YWI5ODRkLS0NCg==
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate, zstd
Connection:
- keep-alive
Content-Length:
- '781'
Content-Type:
- multipart/form-data; boundary=1aec3196ff9311b572c627bfe6ab984d
Host:
- api.openai.com
User-Agent:
- OpenAI/Python 2.24.0
X-Stainless-Arch:
- arm64
X-Stainless-Async:
- 'false'
X-Stainless-Lang:
- python
X-Stainless-OS:
- MacOS
X-Stainless-Package-Version:
- 2.24.0
X-Stainless-Runtime:
- CPython
X-Stainless-Runtime-Version:
- 3.13.3
x-stainless-read-timeout:
- '600'
x-stainless-retry-count:
- '0'
method: POST
uri: https://api.openai.com/v1/images/edits
response:
body:
string: "{\n \"created\": 1775759071,\n \"data\": [\n {\n \"url\":
\"https://oaidalleapiprodscus.blob.core.windows.net/private/org-gY2CWXtioLkEfpHBJTrcdNID/user-jIouncdtCNqBNU7Q41fsSvZ2/img-sWsBgQsG5L08pmtO95p4nUGz.png?st=2026-04-09T17%3A24%3A31Z&se=2026-04-09T19%3A24%3A31Z&sp=r&sv=2026-02-06&sr=b&rscd=inline&rsct=image/png&skoid=8b33a531-2df9-46a3-bc02-d4b1430a422c&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2026-04-09T18%3A21%3A40Z&ske=2026-04-10T18%3A21%3A40Z&sks=b&skv=2026-02-06&sig=IWn2M3VRWKx8z8T9b95nfRa5EjAhZCemDwua6t23EbQ%3D\"\n
\ }\n ]\n}"
headers:
CF-RAY:
- 9e9b8c57af1fa06e-YYZ
Connection:
- keep-alive
Content-Type:
- application/json
Date:
- Thu, 09 Apr 2026 18:24:31 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=31536000; includeSubDomains; preload
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
content-length:
- '544'
openai-organization:
- braintrust-data
openai-processing-ms:
- '9957'
openai-project:
- proj_vsCSXafhhByzWOThMrJcZiw9
openai-version:
- '2020-10-01'
set-cookie:
- __cf_bm=awSasqBRHVxTDWJEEP6Qw.Xnqko8SJvLBvYIJ5jhC_A-1775759061.7060604-1.0.1.1-NR9TiN9VkB6eP1aqSC3oqHyb_wYQQnIHT18qD4FrGpG6IOP0xE56iRyQ.EI8ZSpFKitT8V1qfALR7m2lodLMoXKxbNtwd..QCsUA1.7NbCTBFr61c7xZAZkBq7cQZGkp;
HttpOnly; Secure; Path=/; Domain=api.openai.com; Expires=Thu, 09 Apr 2026
18:54:31 GMT
x-request-id:
- req_23c05ec9d803459aa51a6bb3f029020a
status:
code: 200
message: OK
- request:
body: !!binary |
LS05Y2M1YWFiZWJlMmFkMTE4MzdlNGVmNjQ1MWEyMTcyOA0KQ29udGVudC1EaXNwb3NpdGlvbjog
Zm9ybS1kYXRhOyBuYW1lPSJwcm9tcHQiDQoNCkFkZCBhIGJsdWUgYm9yZGVyDQotLTljYzVhYWJl
YmUyYWQxMTgzN2U0ZWY2NDUxYTIxNzI4DQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9Im1vZGVsIg0KDQpkYWxsLWUtMg0KLS05Y2M1YWFiZWJlMmFkMTE4MzdlNGVmNjQ1MWEy
MTcyOA0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJyZXNwb25zZV9mb3Jt
YXQiDQoNCnVybA0KLS05Y2M1YWFiZWJlMmFkMTE4MzdlNGVmNjQ1MWEyMTcyOA0KQ29udGVudC1E
aXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJzaXplIg0KDQoyNTZ4MjU2DQotLTljYzVhYWJl
YmUyYWQxMTgzN2U0ZWY2NDUxYTIxNzI4DQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9ImltYWdlIjsgZmlsZW5hbWU9ImJyYWludHJ1c3QtdGVzdC1pbWFnZS5wbmciDQpDb250
ZW50LVR5cGU6IGltYWdlL3BuZw0KDQqJUE5HDQoaCgAAAA1JSERSAAAAQAAAAEAIBgAAAKppcd4A
AACUSURBVHic7dAxEQAwEMOw8Cf9haGhHrT7vNvuZ9MBWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1
QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYA
HaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoD0OI4dJt2PESAAAAAElFTkSuQmCC
DQotLTljYzVhYWJlYmUyYWQxMTgzN2U0ZWY2NDUxYTIxNzI4LS0NCg==
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate, zstd
Connection:
- keep-alive
Content-Length:
- '781'
Content-Type:
- multipart/form-data; boundary=9cc5aabebe2ad11837e4ef6451a21728
Host:
- api.openai.com
User-Agent:
- OpenAI/Python 2.24.0
X-Stainless-Arch:
- arm64
X-Stainless-Async:
- 'false'
X-Stainless-Lang:
- python
X-Stainless-OS:
- MacOS
X-Stainless-Package-Version:
- 2.24.0
X-Stainless-Runtime:
- CPython
X-Stainless-Runtime-Version:
- 3.13.3
x-stainless-read-timeout:
- '600'
x-stainless-retry-count:
- '0'
method: POST
uri: https://api.openai.com/v1/images/edits
response:
body:
string: "{\n \"created\": 1775759080,\n \"data\": [\n {\n \"url\":
\"https://oaidalleapiprodscus.blob.core.windows.net/private/org-gY2CWXtioLkEfpHBJTrcdNID/user-jIouncdtCNqBNU7Q41fsSvZ2/img-dg5LcnpEkqDsbL996mUGtuR7.png?st=2026-04-09T17%3A24%3A40Z&se=2026-04-09T19%3A24%3A40Z&sp=r&sv=2026-02-06&sr=b&rscd=inline&rsct=image/png&skoid=7daae675-7b42-4e2e-ab4c-8d8419a28d99&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2026-04-09T11%3A45%3A25Z&ske=2026-04-10T11%3A45%3A25Z&sks=b&skv=2026-02-06&sig=5xpj5xgDoSam7/osQpyjYWdD0WhqIvwfK6olzqGnNSw%3D\"\n
\ }\n ]\n}"
headers:
CF-RAY:
- 9e9b8c96db4c8e83-YYZ
Connection:
- keep-alive
Content-Type:
- application/json
Date:
- Thu, 09 Apr 2026 18:24:40 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=31536000; includeSubDomains; preload
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
content-length:
- '544'
openai-organization:
- braintrust-data
openai-processing-ms:
- '8841'
openai-project:
- proj_vsCSXafhhByzWOThMrJcZiw9
openai-version:
- '2020-10-01'
set-cookie:
- __cf_bm=71VJ5AXIV3KbEjxMwRTgzN6wXFuq_FJpfnaclJQEftA-1775759071.815464-1.0.1.1-KlPEAAV9pa1hiqAJSUM_1Hphmoc2bA67hnze_M9BLdP4BVlQNYOk7VfapD42MqF4SAAUD2srxAuNDxLnBCFHf1KO76acIfz5vC2uIwFn8Zsbn04ItH_OHQSg_bkamfxn;
HttpOnly; Secure; Path=/; Domain=api.openai.com; Expires=Thu, 09 Apr 2026
18:54:40 GMT
x-request-id:
- req_4a84ca0d8b6641c0b92a54393a75f44b
status:
code: 200
message: OK
version: 1
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions py/src/braintrust/integrations/adk/tracing.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,8 @@
from typing import Any, cast

from braintrust.bt_json import bt_safe_deep_copy
from braintrust.logger import Attachment, start_span
from braintrust.integrations.utils import _attachment_from_bytes, _image_url_payload
from braintrust.logger import start_span
from braintrust.span_types import SpanTypeAttribute


Expand DownExpand Up@@ -59,12 +60,10 @@ def _serialize_part(part: Any) -> Any:

# Convert bytes to Attachment
if isinstance(data, bytes):
extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
filename = f"file.{extension}"
attachment = Attachment(data=data, filename=filename, content_type=mime_type)
attachment = _attachment_from_bytes(data, mime_type)

# Return in image_url format - SDK will replace with AttachmentReference
return {"image_url": {"url": attachment}}
return _image_url_payload(attachment)

# Handle Part objects with file_data (file references)
if hasattr(part, "file_data") and part.file_data:
Expand Down
25 changes: 11 additions & 14 deletions py/src/braintrust/integrations/anthropic/tracing.py
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
import base64
import logging
import time
import warnings

from braintrust.bt_json import bt_safe_deep_copy
from braintrust.integrations.anthropic._utils import Wrapper, extract_anthropic_usage
from braintrust.logger import Attachment, log_exc_info_to_span, start_span
from braintrust.integrations.utils import (
_attachment_filename_for_mime_type,
_attachment_from_base64_data,
_image_url_payload,
)
from braintrust.logger import log_exc_info_to_span, start_span


log = logging.getLogger(__name__)
Expand DownExpand Up@@ -410,10 +414,8 @@ def _start_batch_results_span(args, kwargs):


def _attachment_filename_for_media_type(media_type: str, block_type: str) -> str:
extension = media_type.split("/", 1)[1] if "/" in media_type else "bin"
extension = extension.split("+", 1)[0]
prefix = "image" if block_type == "image" else "document"
return f"{prefix}.{extension}"
return _attachment_filename_for_mime_type(media_type, prefix=prefix)


def _convert_base64_source_to_attachment(block_type, source):
Expand All@@ -427,15 +429,10 @@ def _convert_base64_source_to_attachment(block_type, source):
if not isinstance(media_type, str) or not isinstance(data, str):
return None

try:
binary_data = base64.b64decode(data, validate=True)
except Exception:
return None

return Attachment(
data=binary_data,
return _attachment_from_base64_data(
data,
media_type,
filename=_attachment_filename_for_media_type(media_type, block_type),
content_type=media_type,
)


Expand All@@ -452,7 +449,7 @@ def _process_input_attachments(value):
if attachment is not None:
processed = {k: _process_input_attachments(v) for k, v in value.items() if k != "source"}
processed["source"] = {k: _process_input_attachments(v) for k, v in source.items() if k != "data"}
processed["image_url"] = {"url": attachment}
processed.update(_image_url_payload(attachment))
return processed

return {k: _process_input_attachments(v) for k, v in value.items()}
Expand Down
42 changes: 14 additions & 28 deletions py/src/braintrust/integrations/google_genai/tracing.py
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
"""Google GenAI-specific span creation, metadata extraction, stream handling, and output normalization."""

import base64
import binascii
import contextvars
import dataclasses
import logging
Expand All@@ -12,6 +10,12 @@
from typing import TYPE_CHECKING, Any

from braintrust.bt_json import bt_safe_deep_copy
from braintrust.integrations.utils import (
_attachment_filename_for_mime_type,
_attachment_from_base64_data,
_attachment_from_bytes,
_image_url_payload,
)
from braintrust.logger import Attachment, start_span
from braintrust.span_types import SpanTypeAttribute
from braintrust.util import clean_nones
Expand DownExpand Up@@ -114,16 +118,11 @@ def _serialize_content_item(item: Any) -> Any:

# Ensure data is bytes
if isinstance(data, bytes):
# Determine file extension from mime type
extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
filename = f"file.{extension}"

# Create an Attachment object
attachment = Attachment(data=data, filename=filename, content_type=mime_type)
attachment = _attachment_from_bytes(data, mime_type)

# Return the attachment object in image_url format
# The SDK's _extract_attachments will replace it with its reference when logging
return {"image_url": {"url": attachment}}
return _image_url_payload(attachment)

# Try to use built-in serialization if available
if hasattr(item, "model_dump"):
Expand DownExpand Up@@ -156,21 +155,6 @@ def _serialize_tools(api_client: Any, input: Any | None) -> Any | None:
return None


def _attachment_from_base64_data(data: str, mime_type: str, *, label: str) -> Attachment | None:
raw_data = data
if raw_data.startswith("data:"):
_, _, encoded = raw_data.partition(",")
raw_data = encoded

try:
decoded = base64.b64decode(raw_data, validate=True)
except (ValueError, binascii.Error):
return None

extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
return Attachment(data=decoded, filename=f"{label}.{extension}", content_type=mime_type)


def _serialize_interaction_content_dict(value: dict[str, Any]) -> dict[str, Any]:
serialized = {key: _serialize_interaction_value(val) for key, val in value.items() if val is not None}

Expand DownExpand Up@@ -402,10 +386,12 @@ def _extract_generate_images_output(response: Any) -> dict[str, Any]:
# Convert image bytes to an Attachment so the SDK uploads them to
# object storage and the Braintrust UI can render the image.
if isinstance(image_bytes, bytes) and mime_type:
extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
filename = f"generated_image_{i}.{extension}"
attachment = Attachment(data=image_bytes, filename=filename, content_type=mime_type)
image_entry["image_url"] = {"url": attachment}
attachment = _attachment_from_bytes(
image_bytes,
mime_type,
filename=_attachment_filename_for_mime_type(mime_type, prefix=f"generated_image_{i}"),
)
image_entry.update(_image_url_payload(attachment))

serialized_images.append(image_entry)

Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
interactions:
- request:
body: !!binary |
LS0xYWVjMzE5NmZmOTMxMWI1NzJjNjI3YmZlNmFiOTg0ZA0KQ29udGVudC1EaXNwb3NpdGlvbjog
Zm9ybS1kYXRhOyBuYW1lPSJwcm9tcHQiDQoNCkFkZCBhIGJsdWUgYm9yZGVyDQotLTFhZWMzMTk2
ZmY5MzExYjU3MmM2MjdiZmU2YWI5ODRkDQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9Im1vZGVsIg0KDQpkYWxsLWUtMg0KLS0xYWVjMzE5NmZmOTMxMWI1NzJjNjI3YmZlNmFi
OTg0ZA0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJyZXNwb25zZV9mb3Jt
YXQiDQoNCnVybA0KLS0xYWVjMzE5NmZmOTMxMWI1NzJjNjI3YmZlNmFiOTg0ZA0KQ29udGVudC1E
aXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJzaXplIg0KDQoyNTZ4MjU2DQotLTFhZWMzMTk2
ZmY5MzExYjU3MmM2MjdiZmU2YWI5ODRkDQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9ImltYWdlIjsgZmlsZW5hbWU9ImJyYWludHJ1c3QtdGVzdC1pbWFnZS5wbmciDQpDb250
ZW50LVR5cGU6IGltYWdlL3BuZw0KDQqJUE5HDQoaCgAAAA1JSERSAAAAQAAAAEAIBgAAAKppcd4A
AACUSURBVHic7dAxEQAwEMOw8Cf9haGhHrT7vNvuZ9MBWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1
QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYA
HaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoD0OI4dJt2PESAAAAAElFTkSuQmCC
DQotLTFhZWMzMTk2ZmY5MzExYjU3MmM2MjdiZmU2YWI5ODRkLS0NCg==
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate, zstd
Connection:
- keep-alive
Content-Length:
- '781'
Content-Type:
- multipart/form-data; boundary=1aec3196ff9311b572c627bfe6ab984d
Host:
- api.openai.com
User-Agent:
- OpenAI/Python 2.24.0
X-Stainless-Arch:
- arm64
X-Stainless-Async:
- 'false'
X-Stainless-Lang:
- python
X-Stainless-OS:
- MacOS
X-Stainless-Package-Version:
- 2.24.0
X-Stainless-Runtime:
- CPython
X-Stainless-Runtime-Version:
- 3.13.3
x-stainless-read-timeout:
- '600'
x-stainless-retry-count:
- '0'
method: POST
uri: https://api.openai.com/v1/images/edits
response:
body:
string: "{\n \"created\": 1775759071,\n \"data\": [\n {\n \"url\":
\"https://oaidalleapiprodscus.blob.core.windows.net/private/org-gY2CWXtioLkEfpHBJTrcdNID/user-jIouncdtCNqBNU7Q41fsSvZ2/img-sWsBgQsG5L08pmtO95p4nUGz.png?st=2026-04-09T17%3A24%3A31Z&se=2026-04-09T19%3A24%3A31Z&sp=r&sv=2026-02-06&sr=b&rscd=inline&rsct=image/png&skoid=8b33a531-2df9-46a3-bc02-d4b1430a422c&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2026-04-09T18%3A21%3A40Z&ske=2026-04-10T18%3A21%3A40Z&sks=b&skv=2026-02-06&sig=IWn2M3VRWKx8z8T9b95nfRa5EjAhZCemDwua6t23EbQ%3D\"\n
\ }\n ]\n}"
headers:
CF-RAY:
- 9e9b8c57af1fa06e-YYZ
Connection:
- keep-alive
Content-Type:
- application/json
Date:
- Thu, 09 Apr 2026 18:24:31 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=31536000; includeSubDomains; preload
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
content-length:
- '544'
openai-organization:
- braintrust-data
openai-processing-ms:
- '9957'
openai-project:
- proj_vsCSXafhhByzWOThMrJcZiw9
openai-version:
- '2020-10-01'
set-cookie:
- __cf_bm=awSasqBRHVxTDWJEEP6Qw.Xnqko8SJvLBvYIJ5jhC_A-1775759061.7060604-1.0.1.1-NR9TiN9VkB6eP1aqSC3oqHyb_wYQQnIHT18qD4FrGpG6IOP0xE56iRyQ.EI8ZSpFKitT8V1qfALR7m2lodLMoXKxbNtwd..QCsUA1.7NbCTBFr61c7xZAZkBq7cQZGkp;
HttpOnly; Secure; Path=/; Domain=api.openai.com; Expires=Thu, 09 Apr 2026
18:54:31 GMT
x-request-id:
- req_23c05ec9d803459aa51a6bb3f029020a
status:
code: 200
message: OK
- request:
body: !!binary |
LS05Y2M1YWFiZWJlMmFkMTE4MzdlNGVmNjQ1MWEyMTcyOA0KQ29udGVudC1EaXNwb3NpdGlvbjog
Zm9ybS1kYXRhOyBuYW1lPSJwcm9tcHQiDQoNCkFkZCBhIGJsdWUgYm9yZGVyDQotLTljYzVhYWJl
YmUyYWQxMTgzN2U0ZWY2NDUxYTIxNzI4DQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9Im1vZGVsIg0KDQpkYWxsLWUtMg0KLS05Y2M1YWFiZWJlMmFkMTE4MzdlNGVmNjQ1MWEy
MTcyOA0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJyZXNwb25zZV9mb3Jt
YXQiDQoNCnVybA0KLS05Y2M1YWFiZWJlMmFkMTE4MzdlNGVmNjQ1MWEyMTcyOA0KQ29udGVudC1E
aXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJzaXplIg0KDQoyNTZ4MjU2DQotLTljYzVhYWJl
YmUyYWQxMTgzN2U0ZWY2NDUxYTIxNzI4DQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9ImltYWdlIjsgZmlsZW5hbWU9ImJyYWludHJ1c3QtdGVzdC1pbWFnZS5wbmciDQpDb250
ZW50LVR5cGU6IGltYWdlL3BuZw0KDQqJUE5HDQoaCgAAAA1JSERSAAAAQAAAAEAIBgAAAKppcd4A
AACUSURBVHic7dAxEQAwEMOw8Cf9haGhHrT7vNvuZ9MBWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1
QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYA
HaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoD0OI4dJt2PESAAAAAElFTkSuQmCC
DQotLTljYzVhYWJlYmUyYWQxMTgzN2U0ZWY2NDUxYTIxNzI4LS0NCg==
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate, zstd
Connection:
- keep-alive
Content-Length:
- '781'
Content-Type:
- multipart/form-data; boundary=9cc5aabebe2ad11837e4ef6451a21728
Host:
- api.openai.com
User-Agent:
- OpenAI/Python 2.24.0
X-Stainless-Arch:
- arm64
X-Stainless-Async:
- 'false'
X-Stainless-Lang:
- python
X-Stainless-OS:
- MacOS
X-Stainless-Package-Version:
- 2.24.0
X-Stainless-Runtime:
- CPython
X-Stainless-Runtime-Version:
- 3.13.3
x-stainless-read-timeout:
- '600'
x-stainless-retry-count:
- '0'
method: POST
uri: https://api.openai.com/v1/images/edits
response:
body:
string: "{\n \"created\": 1775759080,\n \"data\": [\n {\n \"url\":
\"https://oaidalleapiprodscus.blob.core.windows.net/private/org-gY2CWXtioLkEfpHBJTrcdNID/user-jIouncdtCNqBNU7Q41fsSvZ2/img-dg5LcnpEkqDsbL996mUGtuR7.png?st=2026-04-09T17%3A24%3A40Z&se=2026-04-09T19%3A24%3A40Z&sp=r&sv=2026-02-06&sr=b&rscd=inline&rsct=image/png&skoid=7daae675-7b42-4e2e-ab4c-8d8419a28d99&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2026-04-09T11%3A45%3A25Z&ske=2026-04-10T11%3A45%3A25Z&sks=b&skv=2026-02-06&sig=5xpj5xgDoSam7/osQpyjYWdD0WhqIvwfK6olzqGnNSw%3D\"\n
\ }\n ]\n}"
headers:
CF-RAY:
- 9e9b8c96db4c8e83-YYZ
Connection:
- keep-alive
Content-Type:
- application/json
Date:
- Thu, 09 Apr 2026 18:24:40 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=31536000; includeSubDomains; preload
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
content-length:
- '544'
openai-organization:
- braintrust-data
openai-processing-ms:
- '8841'
openai-project:
- proj_vsCSXafhhByzWOThMrJcZiw9
openai-version:
- '2020-10-01'
set-cookie:
- __cf_bm=71VJ5AXIV3KbEjxMwRTgzN6wXFuq_FJpfnaclJQEftA-1775759071.815464-1.0.1.1-KlPEAAV9pa1hiqAJSUM_1Hphmoc2bA67hnze_M9BLdP4BVlQNYOk7VfapD42MqF4SAAUD2srxAuNDxLnBCFHf1KO76acIfz5vC2uIwFn8Zsbn04ItH_OHQSg_bkamfxn;
HttpOnly; Secure; Path=/; Domain=api.openai.com; Expires=Thu, 09 Apr 2026
18:54:40 GMT
x-request-id:
- req_4a84ca0d8b6641c0b92a54393a75f44b
status:
code: 200
message: OK
version: 1
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions py/src/braintrust/integrations/adk/tracing.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,8 @@
from typing import Any, cast

from braintrust.bt_json import bt_safe_deep_copy
from braintrust.logger import Attachment, start_span
from braintrust.integrations.utils import _attachment_from_bytes, _image_url_payload
from braintrust.logger import start_span
from braintrust.span_types import SpanTypeAttribute


Expand DownExpand Up@@ -59,12 +60,10 @@ def _serialize_part(part: Any) -> Any:

# Convert bytes to Attachment
if isinstance(data, bytes):
extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
filename = f"file.{extension}"
attachment = Attachment(data=data, filename=filename, content_type=mime_type)
attachment = _attachment_from_bytes(data, mime_type)

# Return in image_url format - SDK will replace with AttachmentReference
return {"image_url": {"url": attachment}}
return _image_url_payload(attachment)

# Handle Part objects with file_data (file references)
if hasattr(part, "file_data") and part.file_data:
Expand Down
25 changes: 11 additions & 14 deletions py/src/braintrust/integrations/anthropic/tracing.py
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
import base64
import logging
import time
import warnings

from braintrust.bt_json import bt_safe_deep_copy
from braintrust.integrations.anthropic._utils import Wrapper, extract_anthropic_usage
from braintrust.logger import Attachment, log_exc_info_to_span, start_span
from braintrust.integrations.utils import (
_attachment_filename_for_mime_type,
_attachment_from_base64_data,
_image_url_payload,
)
from braintrust.logger import log_exc_info_to_span, start_span


log = logging.getLogger(__name__)
Expand DownExpand Up@@ -410,10 +414,8 @@ def _start_batch_results_span(args, kwargs):


def _attachment_filename_for_media_type(media_type: str, block_type: str) -> str:
extension = media_type.split("/", 1)[1] if "/" in media_type else "bin"
extension = extension.split("+", 1)[0]
prefix = "image" if block_type == "image" else "document"
return f"{prefix}.{extension}"
return _attachment_filename_for_mime_type(media_type, prefix=prefix)


def _convert_base64_source_to_attachment(block_type, source):
Expand All@@ -427,15 +429,10 @@ def _convert_base64_source_to_attachment(block_type, source):
if not isinstance(media_type, str) or not isinstance(data, str):
return None

try:
binary_data = base64.b64decode(data, validate=True)
except Exception:
return None

return Attachment(
data=binary_data,
return _attachment_from_base64_data(
data,
media_type,
filename=_attachment_filename_for_media_type(media_type, block_type),
content_type=media_type,
)


Expand All@@ -452,7 +449,7 @@ def _process_input_attachments(value):
if attachment is not None:
processed = {k: _process_input_attachments(v) for k, v in value.items() if k != "source"}
processed["source"] = {k: _process_input_attachments(v) for k, v in source.items() if k != "data"}
processed["image_url"] = {"url": attachment}
processed.update(_image_url_payload(attachment))
return processed

return {k: _process_input_attachments(v) for k, v in value.items()}
Expand Down
42 changes: 14 additions & 28 deletions py/src/braintrust/integrations/google_genai/tracing.py
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
"""Google GenAI-specific span creation, metadata extraction, stream handling, and output normalization."""

import base64
import binascii
import contextvars
import dataclasses
import logging
Expand All@@ -12,6 +10,12 @@
from typing import TYPE_CHECKING, Any

from braintrust.bt_json import bt_safe_deep_copy
from braintrust.integrations.utils import (
_attachment_filename_for_mime_type,
_attachment_from_base64_data,
_attachment_from_bytes,
_image_url_payload,
)
from braintrust.logger import Attachment, start_span
from braintrust.span_types import SpanTypeAttribute
from braintrust.util import clean_nones
Expand DownExpand Up@@ -114,16 +118,11 @@ def _serialize_content_item(item: Any) -> Any:

# Ensure data is bytes
if isinstance(data, bytes):
# Determine file extension from mime type
extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
filename = f"file.{extension}"

# Create an Attachment object
attachment = Attachment(data=data, filename=filename, content_type=mime_type)
attachment = _attachment_from_bytes(data, mime_type)

# Return the attachment object in image_url format
# The SDK's _extract_attachments will replace it with its reference when logging
return {"image_url": {"url": attachment}}
return _image_url_payload(attachment)

# Try to use built-in serialization if available
if hasattr(item, "model_dump"):
Expand DownExpand Up@@ -156,21 +155,6 @@ def _serialize_tools(api_client: Any, input: Any | None) -> Any | None:
return None


def _attachment_from_base64_data(data: str, mime_type: str, *, label: str) -> Attachment | None:
raw_data = data
if raw_data.startswith("data:"):
_, _, encoded = raw_data.partition(",")
raw_data = encoded

try:
decoded = base64.b64decode(raw_data, validate=True)
except (ValueError, binascii.Error):
return None

extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
return Attachment(data=decoded, filename=f"{label}.{extension}", content_type=mime_type)


def _serialize_interaction_content_dict(value: dict[str, Any]) -> dict[str, Any]:
serialized = {key: _serialize_interaction_value(val) for key, val in value.items() if val is not None}

Expand DownExpand Up@@ -402,10 +386,12 @@ def _extract_generate_images_output(response: Any) -> dict[str, Any]:
# Convert image bytes to an Attachment so the SDK uploads them to
# object storage and the Braintrust UI can render the image.
if isinstance(image_bytes, bytes) and mime_type:
extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
filename = f"generated_image_{i}.{extension}"
attachment = Attachment(data=image_bytes, filename=filename, content_type=mime_type)
image_entry["image_url"] = {"url": attachment}
attachment = _attachment_from_bytes(
image_bytes,
mime_type,
filename=_attachment_filename_for_mime_type(mime_type, prefix=f"generated_image_{i}"),
)
image_entry.update(_image_url_payload(attachment))

serialized_images.append(image_entry)

Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
interactions:
- request:
body: !!binary |
LS0xYWVjMzE5NmZmOTMxMWI1NzJjNjI3YmZlNmFiOTg0ZA0KQ29udGVudC1EaXNwb3NpdGlvbjog
Zm9ybS1kYXRhOyBuYW1lPSJwcm9tcHQiDQoNCkFkZCBhIGJsdWUgYm9yZGVyDQotLTFhZWMzMTk2
ZmY5MzExYjU3MmM2MjdiZmU2YWI5ODRkDQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9Im1vZGVsIg0KDQpkYWxsLWUtMg0KLS0xYWVjMzE5NmZmOTMxMWI1NzJjNjI3YmZlNmFi
OTg0ZA0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJyZXNwb25zZV9mb3Jt
YXQiDQoNCnVybA0KLS0xYWVjMzE5NmZmOTMxMWI1NzJjNjI3YmZlNmFiOTg0ZA0KQ29udGVudC1E
aXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJzaXplIg0KDQoyNTZ4MjU2DQotLTFhZWMzMTk2
ZmY5MzExYjU3MmM2MjdiZmU2YWI5ODRkDQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9ImltYWdlIjsgZmlsZW5hbWU9ImJyYWludHJ1c3QtdGVzdC1pbWFnZS5wbmciDQpDb250
ZW50LVR5cGU6IGltYWdlL3BuZw0KDQqJUE5HDQoaCgAAAA1JSERSAAAAQAAAAEAIBgAAAKppcd4A
AACUSURBVHic7dAxEQAwEMOw8Cf9haGhHrT7vNvuZ9MBWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1
QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYA
HaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoD0OI4dJt2PESAAAAAElFTkSuQmCC
DQotLTFhZWMzMTk2ZmY5MzExYjU3MmM2MjdiZmU2YWI5ODRkLS0NCg==
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate, zstd
Connection:
- keep-alive
Content-Length:
- '781'
Content-Type:
- multipart/form-data; boundary=1aec3196ff9311b572c627bfe6ab984d
Host:
- api.openai.com
User-Agent:
- OpenAI/Python 2.24.0
X-Stainless-Arch:
- arm64
X-Stainless-Async:
- 'false'
X-Stainless-Lang:
- python
X-Stainless-OS:
- MacOS
X-Stainless-Package-Version:
- 2.24.0
X-Stainless-Runtime:
- CPython
X-Stainless-Runtime-Version:
- 3.13.3
x-stainless-read-timeout:
- '600'
x-stainless-retry-count:
- '0'
method: POST
uri: https://api.openai.com/v1/images/edits
response:
body:
string: "{\n \"created\": 1775759071,\n \"data\": [\n {\n \"url\":
\"https://oaidalleapiprodscus.blob.core.windows.net/private/org-gY2CWXtioLkEfpHBJTrcdNID/user-jIouncdtCNqBNU7Q41fsSvZ2/img-sWsBgQsG5L08pmtO95p4nUGz.png?st=2026-04-09T17%3A24%3A31Z&se=2026-04-09T19%3A24%3A31Z&sp=r&sv=2026-02-06&sr=b&rscd=inline&rsct=image/png&skoid=8b33a531-2df9-46a3-bc02-d4b1430a422c&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2026-04-09T18%3A21%3A40Z&ske=2026-04-10T18%3A21%3A40Z&sks=b&skv=2026-02-06&sig=IWn2M3VRWKx8z8T9b95nfRa5EjAhZCemDwua6t23EbQ%3D\"\n
\ }\n ]\n}"
headers:
CF-RAY:
- 9e9b8c57af1fa06e-YYZ
Connection:
- keep-alive
Content-Type:
- application/json
Date:
- Thu, 09 Apr 2026 18:24:31 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=31536000; includeSubDomains; preload
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
content-length:
- '544'
openai-organization:
- braintrust-data
openai-processing-ms:
- '9957'
openai-project:
- proj_vsCSXafhhByzWOThMrJcZiw9
openai-version:
- '2020-10-01'
set-cookie:
- __cf_bm=awSasqBRHVxTDWJEEP6Qw.Xnqko8SJvLBvYIJ5jhC_A-1775759061.7060604-1.0.1.1-NR9TiN9VkB6eP1aqSC3oqHyb_wYQQnIHT18qD4FrGpG6IOP0xE56iRyQ.EI8ZSpFKitT8V1qfALR7m2lodLMoXKxbNtwd..QCsUA1.7NbCTBFr61c7xZAZkBq7cQZGkp;
HttpOnly; Secure; Path=/; Domain=api.openai.com; Expires=Thu, 09 Apr 2026
18:54:31 GMT
x-request-id:
- req_23c05ec9d803459aa51a6bb3f029020a
status:
code: 200
message: OK
- request:
body: !!binary |
LS05Y2M1YWFiZWJlMmFkMTE4MzdlNGVmNjQ1MWEyMTcyOA0KQ29udGVudC1EaXNwb3NpdGlvbjog
Zm9ybS1kYXRhOyBuYW1lPSJwcm9tcHQiDQoNCkFkZCBhIGJsdWUgYm9yZGVyDQotLTljYzVhYWJl
YmUyYWQxMTgzN2U0ZWY2NDUxYTIxNzI4DQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9Im1vZGVsIg0KDQpkYWxsLWUtMg0KLS05Y2M1YWFiZWJlMmFkMTE4MzdlNGVmNjQ1MWEy
MTcyOA0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJyZXNwb25zZV9mb3Jt
YXQiDQoNCnVybA0KLS05Y2M1YWFiZWJlMmFkMTE4MzdlNGVmNjQ1MWEyMTcyOA0KQ29udGVudC1E
aXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJzaXplIg0KDQoyNTZ4MjU2DQotLTljYzVhYWJl
YmUyYWQxMTgzN2U0ZWY2NDUxYTIxNzI4DQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9ImltYWdlIjsgZmlsZW5hbWU9ImJyYWludHJ1c3QtdGVzdC1pbWFnZS5wbmciDQpDb250
ZW50LVR5cGU6IGltYWdlL3BuZw0KDQqJUE5HDQoaCgAAAA1JSERSAAAAQAAAAEAIBgAAAKppcd4A
AACUSURBVHic7dAxEQAwEMOw8Cf9haGhHrT7vNvuZ9MBWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1
QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYA
HaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoD0OI4dJt2PESAAAAAElFTkSuQmCC
DQotLTljYzVhYWJlYmUyYWQxMTgzN2U0ZWY2NDUxYTIxNzI4LS0NCg==
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate, zstd
Connection:
- keep-alive
Content-Length:
- '781'
Content-Type:
- multipart/form-data; boundary=9cc5aabebe2ad11837e4ef6451a21728
Host:
- api.openai.com
User-Agent:
- OpenAI/Python 2.24.0
X-Stainless-Arch:
- arm64
X-Stainless-Async:
- 'false'
X-Stainless-Lang:
- python
X-Stainless-OS:
- MacOS
X-Stainless-Package-Version:
- 2.24.0
X-Stainless-Runtime:
- CPython
X-Stainless-Runtime-Version:
- 3.13.3
x-stainless-read-timeout:
- '600'
x-stainless-retry-count:
- '0'
method: POST
uri: https://api.openai.com/v1/images/edits
response:
body:
string: "{\n \"created\": 1775759080,\n \"data\": [\n {\n \"url\":
\"https://oaidalleapiprodscus.blob.core.windows.net/private/org-gY2CWXtioLkEfpHBJTrcdNID/user-jIouncdtCNqBNU7Q41fsSvZ2/img-dg5LcnpEkqDsbL996mUGtuR7.png?st=2026-04-09T17%3A24%3A40Z&se=2026-04-09T19%3A24%3A40Z&sp=r&sv=2026-02-06&sr=b&rscd=inline&rsct=image/png&skoid=7daae675-7b42-4e2e-ab4c-8d8419a28d99&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2026-04-09T11%3A45%3A25Z&ske=2026-04-10T11%3A45%3A25Z&sks=b&skv=2026-02-06&sig=5xpj5xgDoSam7/osQpyjYWdD0WhqIvwfK6olzqGnNSw%3D\"\n
\ }\n ]\n}"
headers:
CF-RAY:
- 9e9b8c96db4c8e83-YYZ
Connection:
- keep-alive
Content-Type:
- application/json
Date:
- Thu, 09 Apr 2026 18:24:40 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=31536000; includeSubDomains; preload
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
content-length:
- '544'
openai-organization:
- braintrust-data
openai-processing-ms:
- '8841'
openai-project:
- proj_vsCSXafhhByzWOThMrJcZiw9
openai-version:
- '2020-10-01'
set-cookie:
- __cf_bm=71VJ5AXIV3KbEjxMwRTgzN6wXFuq_FJpfnaclJQEftA-1775759071.815464-1.0.1.1-KlPEAAV9pa1hiqAJSUM_1Hphmoc2bA67hnze_M9BLdP4BVlQNYOk7VfapD42MqF4SAAUD2srxAuNDxLnBCFHf1KO76acIfz5vC2uIwFn8Zsbn04ItH_OHQSg_bkamfxn;
HttpOnly; Secure; Path=/; Domain=api.openai.com; Expires=Thu, 09 Apr 2026
18:54:40 GMT
x-request-id:
- req_4a84ca0d8b6641c0b92a54393a75f44b
status:
code: 200
message: OK
version: 1
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions py/src/braintrust/integrations/adk/tracing.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,8 @@
from typing import Any, cast

from braintrust.bt_json import bt_safe_deep_copy
from braintrust.logger import Attachment, start_span
from braintrust.integrations.utils import _attachment_from_bytes, _image_url_payload
from braintrust.logger import start_span
from braintrust.span_types import SpanTypeAttribute


Expand DownExpand Up@@ -59,12 +60,10 @@ def _serialize_part(part: Any) -> Any:

# Convert bytes to Attachment
if isinstance(data, bytes):
extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
filename = f"file.{extension}"
attachment = Attachment(data=data, filename=filename, content_type=mime_type)
attachment = _attachment_from_bytes(data, mime_type)

# Return in image_url format - SDK will replace with AttachmentReference
return {"image_url": {"url": attachment}}
return _image_url_payload(attachment)

# Handle Part objects with file_data (file references)
if hasattr(part, "file_data") and part.file_data:
Expand Down
25 changes: 11 additions & 14 deletions py/src/braintrust/integrations/anthropic/tracing.py
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
import base64
import logging
import time
import warnings

from braintrust.bt_json import bt_safe_deep_copy
from braintrust.integrations.anthropic._utils import Wrapper, extract_anthropic_usage
from braintrust.logger import Attachment, log_exc_info_to_span, start_span
from braintrust.integrations.utils import (
_attachment_filename_for_mime_type,
_attachment_from_base64_data,
_image_url_payload,
)
from braintrust.logger import log_exc_info_to_span, start_span


log = logging.getLogger(__name__)
Expand DownExpand Up@@ -410,10 +414,8 @@ def _start_batch_results_span(args, kwargs):


def _attachment_filename_for_media_type(media_type: str, block_type: str) -> str:
extension = media_type.split("/", 1)[1] if "/" in media_type else "bin"
extension = extension.split("+", 1)[0]
prefix = "image" if block_type == "image" else "document"
return f"{prefix}.{extension}"
return _attachment_filename_for_mime_type(media_type, prefix=prefix)


def _convert_base64_source_to_attachment(block_type, source):
Expand All@@ -427,15 +429,10 @@ def _convert_base64_source_to_attachment(block_type, source):
if not isinstance(media_type, str) or not isinstance(data, str):
return None

try:
binary_data = base64.b64decode(data, validate=True)
except Exception:
return None

return Attachment(
data=binary_data,
return _attachment_from_base64_data(
data,
media_type,
filename=_attachment_filename_for_media_type(media_type, block_type),
content_type=media_type,
)


Expand All@@ -452,7 +449,7 @@ def _process_input_attachments(value):
if attachment is not None:
processed = {k: _process_input_attachments(v) for k, v in value.items() if k != "source"}
processed["source"] = {k: _process_input_attachments(v) for k, v in source.items() if k != "data"}
processed["image_url"] = {"url": attachment}
processed.update(_image_url_payload(attachment))
return processed

return {k: _process_input_attachments(v) for k, v in value.items()}
Expand Down
42 changes: 14 additions & 28 deletions py/src/braintrust/integrations/google_genai/tracing.py
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
"""Google GenAI-specific span creation, metadata extraction, stream handling, and output normalization."""

import base64
import binascii
import contextvars
import dataclasses
import logging
Expand All@@ -12,6 +10,12 @@
from typing import TYPE_CHECKING, Any

from braintrust.bt_json import bt_safe_deep_copy
from braintrust.integrations.utils import (
_attachment_filename_for_mime_type,
_attachment_from_base64_data,
_attachment_from_bytes,
_image_url_payload,
)
from braintrust.logger import Attachment, start_span
from braintrust.span_types import SpanTypeAttribute
from braintrust.util import clean_nones
Expand DownExpand Up@@ -114,16 +118,11 @@ def _serialize_content_item(item: Any) -> Any:

# Ensure data is bytes
if isinstance(data, bytes):
# Determine file extension from mime type
extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
filename = f"file.{extension}"

# Create an Attachment object
attachment = Attachment(data=data, filename=filename, content_type=mime_type)
attachment = _attachment_from_bytes(data, mime_type)

# Return the attachment object in image_url format
# The SDK's _extract_attachments will replace it with its reference when logging
return {"image_url": {"url": attachment}}
return _image_url_payload(attachment)

# Try to use built-in serialization if available
if hasattr(item, "model_dump"):
Expand DownExpand Up@@ -156,21 +155,6 @@ def _serialize_tools(api_client: Any, input: Any | None) -> Any | None:
return None


def _attachment_from_base64_data(data: str, mime_type: str, *, label: str) -> Attachment | None:
raw_data = data
if raw_data.startswith("data:"):
_, _, encoded = raw_data.partition(",")
raw_data = encoded

try:
decoded = base64.b64decode(raw_data, validate=True)
except (ValueError, binascii.Error):
return None

extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
return Attachment(data=decoded, filename=f"{label}.{extension}", content_type=mime_type)


def _serialize_interaction_content_dict(value: dict[str, Any]) -> dict[str, Any]:
serialized = {key: _serialize_interaction_value(val) for key, val in value.items() if val is not None}

Expand DownExpand Up@@ -402,10 +386,12 @@ def _extract_generate_images_output(response: Any) -> dict[str, Any]:
# Convert image bytes to an Attachment so the SDK uploads them to
# object storage and the Braintrust UI can render the image.
if isinstance(image_bytes, bytes) and mime_type:
extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
filename = f"generated_image_{i}.{extension}"
attachment = Attachment(data=image_bytes, filename=filename, content_type=mime_type)
image_entry["image_url"] = {"url": attachment}
attachment = _attachment_from_bytes(
image_bytes,
mime_type,
filename=_attachment_filename_for_mime_type(mime_type, prefix=f"generated_image_{i}"),
)
image_entry.update(_image_url_payload(attachment))

serialized_images.append(image_entry)

Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
interactions:
- request:
body: !!binary |
LS0xYWVjMzE5NmZmOTMxMWI1NzJjNjI3YmZlNmFiOTg0ZA0KQ29udGVudC1EaXNwb3NpdGlvbjog
Zm9ybS1kYXRhOyBuYW1lPSJwcm9tcHQiDQoNCkFkZCBhIGJsdWUgYm9yZGVyDQotLTFhZWMzMTk2
ZmY5MzExYjU3MmM2MjdiZmU2YWI5ODRkDQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9Im1vZGVsIg0KDQpkYWxsLWUtMg0KLS0xYWVjMzE5NmZmOTMxMWI1NzJjNjI3YmZlNmFi
OTg0ZA0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJyZXNwb25zZV9mb3Jt
YXQiDQoNCnVybA0KLS0xYWVjMzE5NmZmOTMxMWI1NzJjNjI3YmZlNmFiOTg0ZA0KQ29udGVudC1E
aXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJzaXplIg0KDQoyNTZ4MjU2DQotLTFhZWMzMTk2
ZmY5MzExYjU3MmM2MjdiZmU2YWI5ODRkDQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9ImltYWdlIjsgZmlsZW5hbWU9ImJyYWludHJ1c3QtdGVzdC1pbWFnZS5wbmciDQpDb250
ZW50LVR5cGU6IGltYWdlL3BuZw0KDQqJUE5HDQoaCgAAAA1JSERSAAAAQAAAAEAIBgAAAKppcd4A
AACUSURBVHic7dAxEQAwEMOw8Cf9haGhHrT7vNvuZ9MBWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1
QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYA
HaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoD0OI4dJt2PESAAAAAElFTkSuQmCC
DQotLTFhZWMzMTk2ZmY5MzExYjU3MmM2MjdiZmU2YWI5ODRkLS0NCg==
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate, zstd
Connection:
- keep-alive
Content-Length:
- '781'
Content-Type:
- multipart/form-data; boundary=1aec3196ff9311b572c627bfe6ab984d
Host:
- api.openai.com
User-Agent:
- OpenAI/Python 2.24.0
X-Stainless-Arch:
- arm64
X-Stainless-Async:
- 'false'
X-Stainless-Lang:
- python
X-Stainless-OS:
- MacOS
X-Stainless-Package-Version:
- 2.24.0
X-Stainless-Runtime:
- CPython
X-Stainless-Runtime-Version:
- 3.13.3
x-stainless-read-timeout:
- '600'
x-stainless-retry-count:
- '0'
method: POST
uri: https://api.openai.com/v1/images/edits
response:
body:
string: "{\n \"created\": 1775759071,\n \"data\": [\n {\n \"url\":
\"https://oaidalleapiprodscus.blob.core.windows.net/private/org-gY2CWXtioLkEfpHBJTrcdNID/user-jIouncdtCNqBNU7Q41fsSvZ2/img-sWsBgQsG5L08pmtO95p4nUGz.png?st=2026-04-09T17%3A24%3A31Z&se=2026-04-09T19%3A24%3A31Z&sp=r&sv=2026-02-06&sr=b&rscd=inline&rsct=image/png&skoid=8b33a531-2df9-46a3-bc02-d4b1430a422c&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2026-04-09T18%3A21%3A40Z&ske=2026-04-10T18%3A21%3A40Z&sks=b&skv=2026-02-06&sig=IWn2M3VRWKx8z8T9b95nfRa5EjAhZCemDwua6t23EbQ%3D\"\n
\ }\n ]\n}"
headers:
CF-RAY:
- 9e9b8c57af1fa06e-YYZ
Connection:
- keep-alive
Content-Type:
- application/json
Date:
- Thu, 09 Apr 2026 18:24:31 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=31536000; includeSubDomains; preload
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
content-length:
- '544'
openai-organization:
- braintrust-data
openai-processing-ms:
- '9957'
openai-project:
- proj_vsCSXafhhByzWOThMrJcZiw9
openai-version:
- '2020-10-01'
set-cookie:
- __cf_bm=awSasqBRHVxTDWJEEP6Qw.Xnqko8SJvLBvYIJ5jhC_A-1775759061.7060604-1.0.1.1-NR9TiN9VkB6eP1aqSC3oqHyb_wYQQnIHT18qD4FrGpG6IOP0xE56iRyQ.EI8ZSpFKitT8V1qfALR7m2lodLMoXKxbNtwd..QCsUA1.7NbCTBFr61c7xZAZkBq7cQZGkp;
HttpOnly; Secure; Path=/; Domain=api.openai.com; Expires=Thu, 09 Apr 2026
18:54:31 GMT
x-request-id:
- req_23c05ec9d803459aa51a6bb3f029020a
status:
code: 200
message: OK
- request:
body: !!binary |
LS05Y2M1YWFiZWJlMmFkMTE4MzdlNGVmNjQ1MWEyMTcyOA0KQ29udGVudC1EaXNwb3NpdGlvbjog
Zm9ybS1kYXRhOyBuYW1lPSJwcm9tcHQiDQoNCkFkZCBhIGJsdWUgYm9yZGVyDQotLTljYzVhYWJl
YmUyYWQxMTgzN2U0ZWY2NDUxYTIxNzI4DQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9Im1vZGVsIg0KDQpkYWxsLWUtMg0KLS05Y2M1YWFiZWJlMmFkMTE4MzdlNGVmNjQ1MWEy
MTcyOA0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJyZXNwb25zZV9mb3Jt
YXQiDQoNCnVybA0KLS05Y2M1YWFiZWJlMmFkMTE4MzdlNGVmNjQ1MWEyMTcyOA0KQ29udGVudC1E
aXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJzaXplIg0KDQoyNTZ4MjU2DQotLTljYzVhYWJl
YmUyYWQxMTgzN2U0ZWY2NDUxYTIxNzI4DQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9ImltYWdlIjsgZmlsZW5hbWU9ImJyYWludHJ1c3QtdGVzdC1pbWFnZS5wbmciDQpDb250
ZW50LVR5cGU6IGltYWdlL3BuZw0KDQqJUE5HDQoaCgAAAA1JSERSAAAAQAAAAEAIBgAAAKppcd4A
AACUSURBVHic7dAxEQAwEMOw8Cf9haGhHrT7vNvuZ9MBWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1
QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYA
HaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoD0OI4dJt2PESAAAAAElFTkSuQmCC
DQotLTljYzVhYWJlYmUyYWQxMTgzN2U0ZWY2NDUxYTIxNzI4LS0NCg==
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate, zstd
Connection:
- keep-alive
Content-Length:
- '781'
Content-Type:
- multipart/form-data; boundary=9cc5aabebe2ad11837e4ef6451a21728
Host:
- api.openai.com
User-Agent:
- OpenAI/Python 2.24.0
X-Stainless-Arch:
- arm64
X-Stainless-Async:
- 'false'
X-Stainless-Lang:
- python
X-Stainless-OS:
- MacOS
X-Stainless-Package-Version:
- 2.24.0
X-Stainless-Runtime:
- CPython
X-Stainless-Runtime-Version:
- 3.13.3
x-stainless-read-timeout:
- '600'
x-stainless-retry-count:
- '0'
method: POST
uri: https://api.openai.com/v1/images/edits
response:
body:
string: "{\n \"created\": 1775759080,\n \"data\": [\n {\n \"url\":
\"https://oaidalleapiprodscus.blob.core.windows.net/private/org-gY2CWXtioLkEfpHBJTrcdNID/user-jIouncdtCNqBNU7Q41fsSvZ2/img-dg5LcnpEkqDsbL996mUGtuR7.png?st=2026-04-09T17%3A24%3A40Z&se=2026-04-09T19%3A24%3A40Z&sp=r&sv=2026-02-06&sr=b&rscd=inline&rsct=image/png&skoid=7daae675-7b42-4e2e-ab4c-8d8419a28d99&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2026-04-09T11%3A45%3A25Z&ske=2026-04-10T11%3A45%3A25Z&sks=b&skv=2026-02-06&sig=5xpj5xgDoSam7/osQpyjYWdD0WhqIvwfK6olzqGnNSw%3D\"\n
\ }\n ]\n}"
headers:
CF-RAY:
- 9e9b8c96db4c8e83-YYZ
Connection:
- keep-alive
Content-Type:
- application/json
Date:
- Thu, 09 Apr 2026 18:24:40 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=31536000; includeSubDomains; preload
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
content-length:
- '544'
openai-organization:
- braintrust-data
openai-processing-ms:
- '8841'
openai-project:
- proj_vsCSXafhhByzWOThMrJcZiw9
openai-version:
- '2020-10-01'
set-cookie:
- __cf_bm=71VJ5AXIV3KbEjxMwRTgzN6wXFuq_FJpfnaclJQEftA-1775759071.815464-1.0.1.1-KlPEAAV9pa1hiqAJSUM_1Hphmoc2bA67hnze_M9BLdP4BVlQNYOk7VfapD42MqF4SAAUD2srxAuNDxLnBCFHf1KO76acIfz5vC2uIwFn8Zsbn04ItH_OHQSg_bkamfxn;
HttpOnly; Secure; Path=/; Domain=api.openai.com; Expires=Thu, 09 Apr 2026
18:54:40 GMT
x-request-id:
- req_4a84ca0d8b6641c0b92a54393a75f44b
status:
code: 200
message: OK
version: 1
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions py/src/braintrust/integrations/adk/tracing.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,8 @@
from typing import Any, cast

from braintrust.bt_json import bt_safe_deep_copy
from braintrust.logger import Attachment, start_span
from braintrust.integrations.utils import _attachment_from_bytes, _image_url_payload
from braintrust.logger import start_span
from braintrust.span_types import SpanTypeAttribute


Expand DownExpand Up@@ -59,12 +60,10 @@ def _serialize_part(part: Any) -> Any:

# Convert bytes to Attachment
if isinstance(data, bytes):
extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
filename = f"file.{extension}"
attachment = Attachment(data=data, filename=filename, content_type=mime_type)
attachment = _attachment_from_bytes(data, mime_type)

# Return in image_url format - SDK will replace with AttachmentReference
return {"image_url": {"url": attachment}}
return _image_url_payload(attachment)

# Handle Part objects with file_data (file references)
if hasattr(part, "file_data") and part.file_data:
Expand Down
25 changes: 11 additions & 14 deletions py/src/braintrust/integrations/anthropic/tracing.py
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
import base64
import logging
import time
import warnings

from braintrust.bt_json import bt_safe_deep_copy
from braintrust.integrations.anthropic._utils import Wrapper, extract_anthropic_usage
from braintrust.logger import Attachment, log_exc_info_to_span, start_span
from braintrust.integrations.utils import (
_attachment_filename_for_mime_type,
_attachment_from_base64_data,
_image_url_payload,
)
from braintrust.logger import log_exc_info_to_span, start_span


log = logging.getLogger(__name__)
Expand DownExpand Up@@ -410,10 +414,8 @@ def _start_batch_results_span(args, kwargs):


def _attachment_filename_for_media_type(media_type: str, block_type: str) -> str:
extension = media_type.split("/", 1)[1] if "/" in media_type else "bin"
extension = extension.split("+", 1)[0]
prefix = "image" if block_type == "image" else "document"
return f"{prefix}.{extension}"
return _attachment_filename_for_mime_type(media_type, prefix=prefix)


def _convert_base64_source_to_attachment(block_type, source):
Expand All@@ -427,15 +429,10 @@ def _convert_base64_source_to_attachment(block_type, source):
if not isinstance(media_type, str) or not isinstance(data, str):
return None

try:
binary_data = base64.b64decode(data, validate=True)
except Exception:
return None

return Attachment(
data=binary_data,
return _attachment_from_base64_data(
data,
media_type,
filename=_attachment_filename_for_media_type(media_type, block_type),
content_type=media_type,
)


Expand All@@ -452,7 +449,7 @@ def _process_input_attachments(value):
if attachment is not None:
processed = {k: _process_input_attachments(v) for k, v in value.items() if k != "source"}
processed["source"] = {k: _process_input_attachments(v) for k, v in source.items() if k != "data"}
processed["image_url"] = {"url": attachment}
processed.update(_image_url_payload(attachment))
return processed

return {k: _process_input_attachments(v) for k, v in value.items()}
Expand Down
42 changes: 14 additions & 28 deletions py/src/braintrust/integrations/google_genai/tracing.py
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
"""Google GenAI-specific span creation, metadata extraction, stream handling, and output normalization."""

import base64
import binascii
import contextvars
import dataclasses
import logging
Expand All@@ -12,6 +10,12 @@
from typing import TYPE_CHECKING, Any

from braintrust.bt_json import bt_safe_deep_copy
from braintrust.integrations.utils import (
_attachment_filename_for_mime_type,
_attachment_from_base64_data,
_attachment_from_bytes,
_image_url_payload,
)
from braintrust.logger import Attachment, start_span
from braintrust.span_types import SpanTypeAttribute
from braintrust.util import clean_nones
Expand DownExpand Up@@ -114,16 +118,11 @@ def _serialize_content_item(item: Any) -> Any:

# Ensure data is bytes
if isinstance(data, bytes):
# Determine file extension from mime type
extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
filename = f"file.{extension}"

# Create an Attachment object
attachment = Attachment(data=data, filename=filename, content_type=mime_type)
attachment = _attachment_from_bytes(data, mime_type)

# Return the attachment object in image_url format
# The SDK's _extract_attachments will replace it with its reference when logging
return {"image_url": {"url": attachment}}
return _image_url_payload(attachment)

# Try to use built-in serialization if available
if hasattr(item, "model_dump"):
Expand DownExpand Up@@ -156,21 +155,6 @@ def _serialize_tools(api_client: Any, input: Any | None) -> Any | None:
return None


def _attachment_from_base64_data(data: str, mime_type: str, *, label: str) -> Attachment | None:
raw_data = data
if raw_data.startswith("data:"):
_, _, encoded = raw_data.partition(",")
raw_data = encoded

try:
decoded = base64.b64decode(raw_data, validate=True)
except (ValueError, binascii.Error):
return None

extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
return Attachment(data=decoded, filename=f"{label}.{extension}", content_type=mime_type)


def _serialize_interaction_content_dict(value: dict[str, Any]) -> dict[str, Any]:
serialized = {key: _serialize_interaction_value(val) for key, val in value.items() if val is not None}

Expand DownExpand Up@@ -402,10 +386,12 @@ def _extract_generate_images_output(response: Any) -> dict[str, Any]:
# Convert image bytes to an Attachment so the SDK uploads them to
# object storage and the Braintrust UI can render the image.
if isinstance(image_bytes, bytes) and mime_type:
extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
filename = f"generated_image_{i}.{extension}"
attachment = Attachment(data=image_bytes, filename=filename, content_type=mime_type)
image_entry["image_url"] = {"url": attachment}
attachment = _attachment_from_bytes(
image_bytes,
mime_type,
filename=_attachment_filename_for_mime_type(mime_type, prefix=f"generated_image_{i}"),
)
image_entry.update(_image_url_payload(attachment))

serialized_images.append(image_entry)

Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
interactions:
- request:
body: !!binary |
LS0xYWVjMzE5NmZmOTMxMWI1NzJjNjI3YmZlNmFiOTg0ZA0KQ29udGVudC1EaXNwb3NpdGlvbjog
Zm9ybS1kYXRhOyBuYW1lPSJwcm9tcHQiDQoNCkFkZCBhIGJsdWUgYm9yZGVyDQotLTFhZWMzMTk2
ZmY5MzExYjU3MmM2MjdiZmU2YWI5ODRkDQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9Im1vZGVsIg0KDQpkYWxsLWUtMg0KLS0xYWVjMzE5NmZmOTMxMWI1NzJjNjI3YmZlNmFi
OTg0ZA0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJyZXNwb25zZV9mb3Jt
YXQiDQoNCnVybA0KLS0xYWVjMzE5NmZmOTMxMWI1NzJjNjI3YmZlNmFiOTg0ZA0KQ29udGVudC1E
aXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJzaXplIg0KDQoyNTZ4MjU2DQotLTFhZWMzMTk2
ZmY5MzExYjU3MmM2MjdiZmU2YWI5ODRkDQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9ImltYWdlIjsgZmlsZW5hbWU9ImJyYWludHJ1c3QtdGVzdC1pbWFnZS5wbmciDQpDb250
ZW50LVR5cGU6IGltYWdlL3BuZw0KDQqJUE5HDQoaCgAAAA1JSERSAAAAQAAAAEAIBgAAAKppcd4A
AACUSURBVHic7dAxEQAwEMOw8Cf9haGhHrT7vNvuZ9MBWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1
QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYA
HaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoD0OI4dJt2PESAAAAAElFTkSuQmCC
DQotLTFhZWMzMTk2ZmY5MzExYjU3MmM2MjdiZmU2YWI5ODRkLS0NCg==
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate, zstd
Connection:
- keep-alive
Content-Length:
- '781'
Content-Type:
- multipart/form-data; boundary=1aec3196ff9311b572c627bfe6ab984d
Host:
- api.openai.com
User-Agent:
- OpenAI/Python 2.24.0
X-Stainless-Arch:
- arm64
X-Stainless-Async:
- 'false'
X-Stainless-Lang:
- python
X-Stainless-OS:
- MacOS
X-Stainless-Package-Version:
- 2.24.0
X-Stainless-Runtime:
- CPython
X-Stainless-Runtime-Version:
- 3.13.3
x-stainless-read-timeout:
- '600'
x-stainless-retry-count:
- '0'
method: POST
uri: https://api.openai.com/v1/images/edits
response:
body:
string: "{\n \"created\": 1775759071,\n \"data\": [\n {\n \"url\":
\"https://oaidalleapiprodscus.blob.core.windows.net/private/org-gY2CWXtioLkEfpHBJTrcdNID/user-jIouncdtCNqBNU7Q41fsSvZ2/img-sWsBgQsG5L08pmtO95p4nUGz.png?st=2026-04-09T17%3A24%3A31Z&se=2026-04-09T19%3A24%3A31Z&sp=r&sv=2026-02-06&sr=b&rscd=inline&rsct=image/png&skoid=8b33a531-2df9-46a3-bc02-d4b1430a422c&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2026-04-09T18%3A21%3A40Z&ske=2026-04-10T18%3A21%3A40Z&sks=b&skv=2026-02-06&sig=IWn2M3VRWKx8z8T9b95nfRa5EjAhZCemDwua6t23EbQ%3D\"\n
\ }\n ]\n}"
headers:
CF-RAY:
- 9e9b8c57af1fa06e-YYZ
Connection:
- keep-alive
Content-Type:
- application/json
Date:
- Thu, 09 Apr 2026 18:24:31 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=31536000; includeSubDomains; preload
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
content-length:
- '544'
openai-organization:
- braintrust-data
openai-processing-ms:
- '9957'
openai-project:
- proj_vsCSXafhhByzWOThMrJcZiw9
openai-version:
- '2020-10-01'
set-cookie:
- __cf_bm=awSasqBRHVxTDWJEEP6Qw.Xnqko8SJvLBvYIJ5jhC_A-1775759061.7060604-1.0.1.1-NR9TiN9VkB6eP1aqSC3oqHyb_wYQQnIHT18qD4FrGpG6IOP0xE56iRyQ.EI8ZSpFKitT8V1qfALR7m2lodLMoXKxbNtwd..QCsUA1.7NbCTBFr61c7xZAZkBq7cQZGkp;
HttpOnly; Secure; Path=/; Domain=api.openai.com; Expires=Thu, 09 Apr 2026
18:54:31 GMT
x-request-id:
- req_23c05ec9d803459aa51a6bb3f029020a
status:
code: 200
message: OK
- request:
body: !!binary |
LS05Y2M1YWFiZWJlMmFkMTE4MzdlNGVmNjQ1MWEyMTcyOA0KQ29udGVudC1EaXNwb3NpdGlvbjog
Zm9ybS1kYXRhOyBuYW1lPSJwcm9tcHQiDQoNCkFkZCBhIGJsdWUgYm9yZGVyDQotLTljYzVhYWJl
YmUyYWQxMTgzN2U0ZWY2NDUxYTIxNzI4DQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9Im1vZGVsIg0KDQpkYWxsLWUtMg0KLS05Y2M1YWFiZWJlMmFkMTE4MzdlNGVmNjQ1MWEy
MTcyOA0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJyZXNwb25zZV9mb3Jt
YXQiDQoNCnVybA0KLS05Y2M1YWFiZWJlMmFkMTE4MzdlNGVmNjQ1MWEyMTcyOA0KQ29udGVudC1E
aXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJzaXplIg0KDQoyNTZ4MjU2DQotLTljYzVhYWJl
YmUyYWQxMTgzN2U0ZWY2NDUxYTIxNzI4DQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9ImltYWdlIjsgZmlsZW5hbWU9ImJyYWludHJ1c3QtdGVzdC1pbWFnZS5wbmciDQpDb250
ZW50LVR5cGU6IGltYWdlL3BuZw0KDQqJUE5HDQoaCgAAAA1JSERSAAAAQAAAAEAIBgAAAKppcd4A
AACUSURBVHic7dAxEQAwEMOw8Cf9haGhHrT7vNvuZ9MBWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1
QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYA
HaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoD0OI4dJt2PESAAAAAElFTkSuQmCC
DQotLTljYzVhYWJlYmUyYWQxMTgzN2U0ZWY2NDUxYTIxNzI4LS0NCg==
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate, zstd
Connection:
- keep-alive
Content-Length:
- '781'
Content-Type:
- multipart/form-data; boundary=9cc5aabebe2ad11837e4ef6451a21728
Host:
- api.openai.com
User-Agent:
- OpenAI/Python 2.24.0
X-Stainless-Arch:
- arm64
X-Stainless-Async:
- 'false'
X-Stainless-Lang:
- python
X-Stainless-OS:
- MacOS
X-Stainless-Package-Version:
- 2.24.0
X-Stainless-Runtime:
- CPython
X-Stainless-Runtime-Version:
- 3.13.3
x-stainless-read-timeout:
- '600'
x-stainless-retry-count:
- '0'
method: POST
uri: https://api.openai.com/v1/images/edits
response:
body:
string: "{\n \"created\": 1775759080,\n \"data\": [\n {\n \"url\":
\"https://oaidalleapiprodscus.blob.core.windows.net/private/org-gY2CWXtioLkEfpHBJTrcdNID/user-jIouncdtCNqBNU7Q41fsSvZ2/img-dg5LcnpEkqDsbL996mUGtuR7.png?st=2026-04-09T17%3A24%3A40Z&se=2026-04-09T19%3A24%3A40Z&sp=r&sv=2026-02-06&sr=b&rscd=inline&rsct=image/png&skoid=7daae675-7b42-4e2e-ab4c-8d8419a28d99&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2026-04-09T11%3A45%3A25Z&ske=2026-04-10T11%3A45%3A25Z&sks=b&skv=2026-02-06&sig=5xpj5xgDoSam7/osQpyjYWdD0WhqIvwfK6olzqGnNSw%3D\"\n
\ }\n ]\n}"
headers:
CF-RAY:
- 9e9b8c96db4c8e83-YYZ
Connection:
- keep-alive
Content-Type:
- application/json
Date:
- Thu, 09 Apr 2026 18:24:40 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=31536000; includeSubDomains; preload
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
content-length:
- '544'
openai-organization:
- braintrust-data
openai-processing-ms:
- '8841'
openai-project:
- proj_vsCSXafhhByzWOThMrJcZiw9
openai-version:
- '2020-10-01'
set-cookie:
- __cf_bm=71VJ5AXIV3KbEjxMwRTgzN6wXFuq_FJpfnaclJQEftA-1775759071.815464-1.0.1.1-KlPEAAV9pa1hiqAJSUM_1Hphmoc2bA67hnze_M9BLdP4BVlQNYOk7VfapD42MqF4SAAUD2srxAuNDxLnBCFHf1KO76acIfz5vC2uIwFn8Zsbn04ItH_OHQSg_bkamfxn;
HttpOnly; Secure; Path=/; Domain=api.openai.com; Expires=Thu, 09 Apr 2026
18:54:40 GMT
x-request-id:
- req_4a84ca0d8b6641c0b92a54393a75f44b
status:
code: 200
message: OK
version: 1
Loading
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions py/src/braintrust/integrations/adk/tracing.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,8 @@
from typing import Any, cast

from braintrust.bt_json import bt_safe_deep_copy
from braintrust.logger import Attachment, start_span
from braintrust.integrations.utils import _attachment_from_bytes, _image_url_payload
from braintrust.logger import start_span
from braintrust.span_types import SpanTypeAttribute


Expand DownExpand Up@@ -59,12 +60,10 @@ def _serialize_part(part: Any) -> Any:

# Convert bytes to Attachment
if isinstance(data, bytes):
extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
filename = f"file.{extension}"
attachment = Attachment(data=data, filename=filename, content_type=mime_type)
attachment = _attachment_from_bytes(data, mime_type)

# Return in image_url format - SDK will replace with AttachmentReference
return {"image_url": {"url": attachment}}
return _image_url_payload(attachment)

# Handle Part objects with file_data (file references)
if hasattr(part, "file_data") and part.file_data:
Expand Down
25 changes: 11 additions & 14 deletions py/src/braintrust/integrations/anthropic/tracing.py
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
import base64
import logging
import time
import warnings

from braintrust.bt_json import bt_safe_deep_copy
from braintrust.integrations.anthropic._utils import Wrapper, extract_anthropic_usage
from braintrust.logger import Attachment, log_exc_info_to_span, start_span
from braintrust.integrations.utils import (
_attachment_filename_for_mime_type,
_attachment_from_base64_data,
_image_url_payload,
)
from braintrust.logger import log_exc_info_to_span, start_span


log = logging.getLogger(__name__)
Expand DownExpand Up@@ -410,10 +414,8 @@ def _start_batch_results_span(args, kwargs):


def _attachment_filename_for_media_type(media_type: str, block_type: str) -> str:
extension = media_type.split("/", 1)[1] if "/" in media_type else "bin"
extension = extension.split("+", 1)[0]
prefix = "image" if block_type == "image" else "document"
return f"{prefix}.{extension}"
return _attachment_filename_for_mime_type(media_type, prefix=prefix)


def _convert_base64_source_to_attachment(block_type, source):
Expand All@@ -427,15 +429,10 @@ def _convert_base64_source_to_attachment(block_type, source):
if not isinstance(media_type, str) or not isinstance(data, str):
return None

try:
binary_data = base64.b64decode(data, validate=True)
except Exception:
return None

return Attachment(
data=binary_data,
return _attachment_from_base64_data(
data,
media_type,
filename=_attachment_filename_for_media_type(media_type, block_type),
content_type=media_type,
)


Expand All@@ -452,7 +449,7 @@ def _process_input_attachments(value):
if attachment is not None:
processed = {k: _process_input_attachments(v) for k, v in value.items() if k != "source"}
processed["source"] = {k: _process_input_attachments(v) for k, v in source.items() if k != "data"}
processed["image_url"] = {"url": attachment}
processed.update(_image_url_payload(attachment))
return processed

return {k: _process_input_attachments(v) for k, v in value.items()}
Expand Down
42 changes: 14 additions & 28 deletions py/src/braintrust/integrations/google_genai/tracing.py
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
"""Google GenAI-specific span creation, metadata extraction, stream handling, and output normalization."""

import base64
import binascii
import contextvars
import dataclasses
import logging
Expand All@@ -12,6 +10,12 @@
from typing import TYPE_CHECKING, Any

from braintrust.bt_json import bt_safe_deep_copy
from braintrust.integrations.utils import (
_attachment_filename_for_mime_type,
_attachment_from_base64_data,
_attachment_from_bytes,
_image_url_payload,
)
from braintrust.logger import Attachment, start_span
from braintrust.span_types import SpanTypeAttribute
from braintrust.util import clean_nones
Expand DownExpand Up@@ -114,16 +118,11 @@ def _serialize_content_item(item: Any) -> Any:

# Ensure data is bytes
if isinstance(data, bytes):
# Determine file extension from mime type
extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
filename = f"file.{extension}"

# Create an Attachment object
attachment = Attachment(data=data, filename=filename, content_type=mime_type)
attachment = _attachment_from_bytes(data, mime_type)

# Return the attachment object in image_url format
# The SDK's _extract_attachments will replace it with its reference when logging
return {"image_url": {"url": attachment}}
return _image_url_payload(attachment)

# Try to use built-in serialization if available
if hasattr(item, "model_dump"):
Expand DownExpand Up@@ -156,21 +155,6 @@ def _serialize_tools(api_client: Any, input: Any | None) -> Any | None:
return None


def _attachment_from_base64_data(data: str, mime_type: str, *, label: str) -> Attachment | None:
raw_data = data
if raw_data.startswith("data:"):
_, _, encoded = raw_data.partition(",")
raw_data = encoded

try:
decoded = base64.b64decode(raw_data, validate=True)
except (ValueError, binascii.Error):
return None

extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
return Attachment(data=decoded, filename=f"{label}.{extension}", content_type=mime_type)


def _serialize_interaction_content_dict(value: dict[str, Any]) -> dict[str, Any]:
serialized = {key: _serialize_interaction_value(val) for key, val in value.items() if val is not None}

Expand DownExpand Up@@ -402,10 +386,12 @@ def _extract_generate_images_output(response: Any) -> dict[str, Any]:
# Convert image bytes to an Attachment so the SDK uploads them to
# object storage and the Braintrust UI can render the image.
if isinstance(image_bytes, bytes) and mime_type:
extension = mime_type.split("/")[1] if "/" in mime_type else "bin"
filename = f"generated_image_{i}.{extension}"
attachment = Attachment(data=image_bytes, filename=filename, content_type=mime_type)
image_entry["image_url"] = {"url": attachment}
attachment = _attachment_from_bytes(
image_bytes,
mime_type,
filename=_attachment_filename_for_mime_type(mime_type, prefix=f"generated_image_{i}"),
)
image_entry.update(_image_url_payload(attachment))

serialized_images.append(image_entry)

Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
interactions:
- request:
body: !!binary |
LS0xYWVjMzE5NmZmOTMxMWI1NzJjNjI3YmZlNmFiOTg0ZA0KQ29udGVudC1EaXNwb3NpdGlvbjog
Zm9ybS1kYXRhOyBuYW1lPSJwcm9tcHQiDQoNCkFkZCBhIGJsdWUgYm9yZGVyDQotLTFhZWMzMTk2
ZmY5MzExYjU3MmM2MjdiZmU2YWI5ODRkDQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9Im1vZGVsIg0KDQpkYWxsLWUtMg0KLS0xYWVjMzE5NmZmOTMxMWI1NzJjNjI3YmZlNmFi
OTg0ZA0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJyZXNwb25zZV9mb3Jt
YXQiDQoNCnVybA0KLS0xYWVjMzE5NmZmOTMxMWI1NzJjNjI3YmZlNmFiOTg0ZA0KQ29udGVudC1E
aXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJzaXplIg0KDQoyNTZ4MjU2DQotLTFhZWMzMTk2
ZmY5MzExYjU3MmM2MjdiZmU2YWI5ODRkDQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9ImltYWdlIjsgZmlsZW5hbWU9ImJyYWludHJ1c3QtdGVzdC1pbWFnZS5wbmciDQpDb250
ZW50LVR5cGU6IGltYWdlL3BuZw0KDQqJUE5HDQoaCgAAAA1JSERSAAAAQAAAAEAIBgAAAKppcd4A
AACUSURBVHic7dAxEQAwEMOw8Cf9haGhHrT7vNvuZ9MBWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1
QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYA
HaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoD0OI4dJt2PESAAAAAElFTkSuQmCC
DQotLTFhZWMzMTk2ZmY5MzExYjU3MmM2MjdiZmU2YWI5ODRkLS0NCg==
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate, zstd
Connection:
- keep-alive
Content-Length:
- '781'
Content-Type:
- multipart/form-data; boundary=1aec3196ff9311b572c627bfe6ab984d
Host:
- api.openai.com
User-Agent:
- OpenAI/Python 2.24.0
X-Stainless-Arch:
- arm64
X-Stainless-Async:
- 'false'
X-Stainless-Lang:
- python
X-Stainless-OS:
- MacOS
X-Stainless-Package-Version:
- 2.24.0
X-Stainless-Runtime:
- CPython
X-Stainless-Runtime-Version:
- 3.13.3
x-stainless-read-timeout:
- '600'
x-stainless-retry-count:
- '0'
method: POST
uri: https://api.openai.com/v1/images/edits
response:
body:
string: "{\n \"created\": 1775759071,\n \"data\": [\n {\n \"url\":
\"https://oaidalleapiprodscus.blob.core.windows.net/private/org-gY2CWXtioLkEfpHBJTrcdNID/user-jIouncdtCNqBNU7Q41fsSvZ2/img-sWsBgQsG5L08pmtO95p4nUGz.png?st=2026-04-09T17%3A24%3A31Z&se=2026-04-09T19%3A24%3A31Z&sp=r&sv=2026-02-06&sr=b&rscd=inline&rsct=image/png&skoid=8b33a531-2df9-46a3-bc02-d4b1430a422c&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2026-04-09T18%3A21%3A40Z&ske=2026-04-10T18%3A21%3A40Z&sks=b&skv=2026-02-06&sig=IWn2M3VRWKx8z8T9b95nfRa5EjAhZCemDwua6t23EbQ%3D\"\n
\ }\n ]\n}"
headers:
CF-RAY:
- 9e9b8c57af1fa06e-YYZ
Connection:
- keep-alive
Content-Type:
- application/json
Date:
- Thu, 09 Apr 2026 18:24:31 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=31536000; includeSubDomains; preload
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
content-length:
- '544'
openai-organization:
- braintrust-data
openai-processing-ms:
- '9957'
openai-project:
- proj_vsCSXafhhByzWOThMrJcZiw9
openai-version:
- '2020-10-01'
set-cookie:
- __cf_bm=awSasqBRHVxTDWJEEP6Qw.Xnqko8SJvLBvYIJ5jhC_A-1775759061.7060604-1.0.1.1-NR9TiN9VkB6eP1aqSC3oqHyb_wYQQnIHT18qD4FrGpG6IOP0xE56iRyQ.EI8ZSpFKitT8V1qfALR7m2lodLMoXKxbNtwd..QCsUA1.7NbCTBFr61c7xZAZkBq7cQZGkp;
HttpOnly; Secure; Path=/; Domain=api.openai.com; Expires=Thu, 09 Apr 2026
18:54:31 GMT
x-request-id:
- req_23c05ec9d803459aa51a6bb3f029020a
status:
code: 200
message: OK
- request:
body: !!binary |
LS05Y2M1YWFiZWJlMmFkMTE4MzdlNGVmNjQ1MWEyMTcyOA0KQ29udGVudC1EaXNwb3NpdGlvbjog
Zm9ybS1kYXRhOyBuYW1lPSJwcm9tcHQiDQoNCkFkZCBhIGJsdWUgYm9yZGVyDQotLTljYzVhYWJl
YmUyYWQxMTgzN2U0ZWY2NDUxYTIxNzI4DQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9Im1vZGVsIg0KDQpkYWxsLWUtMg0KLS05Y2M1YWFiZWJlMmFkMTE4MzdlNGVmNjQ1MWEy
MTcyOA0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJyZXNwb25zZV9mb3Jt
YXQiDQoNCnVybA0KLS05Y2M1YWFiZWJlMmFkMTE4MzdlNGVmNjQ1MWEyMTcyOA0KQ29udGVudC1E
aXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJzaXplIg0KDQoyNTZ4MjU2DQotLTljYzVhYWJl
YmUyYWQxMTgzN2U0ZWY2NDUxYTIxNzI4DQpDb250ZW50LURpc3Bvc2l0aW9uOiBmb3JtLWRhdGE7
IG5hbWU9ImltYWdlIjsgZmlsZW5hbWU9ImJyYWludHJ1c3QtdGVzdC1pbWFnZS5wbmciDQpDb250
ZW50LVR5cGU6IGltYWdlL3BuZw0KDQqJUE5HDQoaCgAAAA1JSERSAAAAQAAAAEAIBgAAAKppcd4A
AACUSURBVHic7dAxEQAwEMOw8Cf9haGhHrT7vNvuZ9MBWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1
QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYA
HaA1QAdoDdABWgN0gNYAHaA1QAdoDdABWgN0gNYAHaA1QAdoD0OI4dJt2PESAAAAAElFTkSuQmCC
DQotLTljYzVhYWJlYmUyYWQxMTgzN2U0ZWY2NDUxYTIxNzI4LS0NCg==
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate, zstd
Connection:
- keep-alive
Content-Length:
- '781'
Content-Type:
- multipart/form-data; boundary=9cc5aabebe2ad11837e4ef6451a21728
Host:
- api.openai.com
User-Agent:
- OpenAI/Python 2.24.0
X-Stainless-Arch:
- arm64
X-Stainless-Async:
- 'false'
X-Stainless-Lang:
- python
X-Stainless-OS:
- MacOS
X-Stainless-Package-Version:
- 2.24.0
X-Stainless-Runtime:
- CPython
X-Stainless-Runtime-Version:
- 3.13.3
x-stainless-read-timeout:
- '600'
x-stainless-retry-count:
- '0'
method: POST
uri: https://api.openai.com/v1/images/edits
response:
body:
string: "{\n \"created\": 1775759080,\n \"data\": [\n {\n \"url\":
\"https://oaidalleapiprodscus.blob.core.windows.net/private/org-gY2CWXtioLkEfpHBJTrcdNID/user-jIouncdtCNqBNU7Q41fsSvZ2/img-dg5LcnpEkqDsbL996mUGtuR7.png?st=2026-04-09T17%3A24%3A40Z&se=2026-04-09T19%3A24%3A40Z&sp=r&sv=2026-02-06&sr=b&rscd=inline&rsct=image/png&skoid=7daae675-7b42-4e2e-ab4c-8d8419a28d99&sktid=a48cca56-e6da-484e-a814-9c849652bcb3&skt=2026-04-09T11%3A45%3A25Z&ske=2026-04-10T11%3A45%3A25Z&sks=b&skv=2026-02-06&sig=5xpj5xgDoSam7/osQpyjYWdD0WhqIvwfK6olzqGnNSw%3D\"\n
\ }\n ]\n}"
headers:
CF-RAY:
- 9e9b8c96db4c8e83-YYZ
Connection:
- keep-alive
Content-Type:
- application/json
Date:
- Thu, 09 Apr 2026 18:24:40 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=31536000; includeSubDomains; preload
Transfer-Encoding:
- chunked
X-Content-Type-Options:
- nosniff
alt-svc:
- h3=":443"; ma=86400
cf-cache-status:
- DYNAMIC
content-length:
- '544'
openai-organization:
- braintrust-data
openai-processing-ms:
- '8841'
openai-project:
- proj_vsCSXafhhByzWOThMrJcZiw9
openai-version:
- '2020-10-01'
set-cookie:
- __cf_bm=71VJ5AXIV3KbEjxMwRTgzN6wXFuq_FJpfnaclJQEftA-1775759071.815464-1.0.1.1-KlPEAAV9pa1hiqAJSUM_1Hphmoc2bA67hnze_M9BLdP4BVlQNYOk7VfapD42MqF4SAAUD2srxAuNDxLnBCFHf1KO76acIfz5vC2uIwFn8Zsbn04ItH_OHQSg_bkamfxn;
HttpOnly; Secure; Path=/; Domain=api.openai.com; Expires=Thu, 09 Apr 2026
18:54:40 GMT
x-request-id:
- req_4a84ca0d8b6641c0b92a54393a75f44b
status:
code: 200
message: OK
version: 1
Loading
Loading