Skip to content

Python: Accept the registered audio/mpeg media type for MP3 input content - #8787

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 4 commits into
microsoft:mainfrom
Lesereingrape:fix/openai-audio-mpeg-mp3-media-type
Oct 2, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 4 commits into
microsoft:mainfrom
Lesereingrape:fix/openai-audio-mpeg-mp3-media-type

Conversation

@Lesereingrape

Copy link
Copy Markdown
Contributor

Motivation & Context

MP3 is the only audio format besides WAV that OpenAI's input_audio part accepts, and both OpenAI chat clients support it — but only when the caller writes the non-standard media type audio/mp3. The registered type for MP3 is audio/mpeg (RFC 3008), and because the format is chosen by substring-matching "mp3"/"wav" against content.media_type, audio/mpeg falls through to the "unsupported" branch and the whole content item is silently dropped (warning in the Responses client, debug log in the Chat Completions client).

The framework's own helpers produce the rejected spelling:

  • detect_media_type_from_base64() returns "audio/mpeg" for MP3 magic bytes (python/packages/core/agent_framework/_types.py:171), and the Content.from_data() docstring points callers at that helper to set media_type; "audio/mpeg" is also listed in core's KNOWN_MEDIA_TYPES.
  • agent-framework-hosting-telegram labels inbound audio messages as "audio/mpeg" (_parsing.py:30-35), so a Telegram audio message sent to an OpenAI-based agent disappears from the request without any error reaching the caller.

Description & Review Guide

  • What are the major changes? Accept audio/mpeg (and other mpeg-spelled MP3 types such as audio/x-mpeg, audio/mpeg3) as MP3 when converting audio content, in both OpenAIChatClient (_chat_client.py:2123) and OpenAIChatCompletionClient (_chat_completion_client.py:1318): "mp3" in content.media_type or "mpeg" in content.media_type. Two one-line changes; both clients had the identical defect, so both are fixed to keep them in parity.
  • What is the impact of these changes? MP3 data/uri content that carries the standard media type is now converted to {"type": "input_audio", "input_audio": {..., "format": "mp3"}} instead of being dropped. Nothing else in the branch changes: the WAV check still runs first, and genuinely unsupported audio types (audio/ogg, audio/flac, ...) still return {} as before — audio/ogg is asserted in both test modules and stays green.
  • What do you want reviewers to focus on? Whether mpeg as a substring is the right shape for the alias, versus an explicit media type allow list. I kept the existing substring style so the diff stays minimal and the already-supported audio/mp3 keeps working, but I am happy to switch to an explicit set if that is preferred.

Local run of the package's full gate (uv run python scripts/workspace_poe_tasks.py check --package openai): fmt and lint pass, all five typing checkers (pyright, mypy, ty, pyrefly, zuban) report 0 errors, and 623 tests pass with 94% coverage on the package. Before the source change, the two added audio/mpeg assertions fail with KeyError: 'type' in test_openai_chat_client.py::test_prepare_content_for_openai_audio_content and test_openai_chat_completion_client.py::test_prepare_content_for_openai_data_content_image.

Related Issue

Fixes #8786

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Sep 28, 2026
@moonbox3

Copy link
Copy Markdown
Contributor

Grapette.L (@Lesereingrape) please agree to the CLA.

@eavanvalkenburg

Copy link
Copy Markdown
Member

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAF Automated Review — Iteration 1

Result: Findings reported
Scope: full PR (1 commit(s)): f65c1c35219a
Model: gpt-5.6-sol

Overview

This PR makes both OpenAI serializers recognize the standard audio/mpeg media type, with parity across the Responses and Chat Completions clients and tests preserving WAV, audio/mp3, and unsupported OGG behavior. Core detection, Telegram, and DevUI provide concrete producers of audio/mpeg. However, the unbounded substring match also reclassifies unrelated MPEG-family media types and can send incompatible payloads as MP3, so the alias check needs to be narrowed.

Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
1 verified finding remained after source verification (1 medium) across 1 file. Details are attached to the affected lines below.

Affected areas: python/packages/openai/agent_framework_openai/_chat_client.py

Comment thread python/packages/openai/agent_framework_openai/_chat_client.py Outdated
@Lesereingrape

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

Normalize the media type (drop parameters, case-fold) and compare it
against the registered MP3 aliases so audio/mpegurl and
audio/mpeg4-generic take the unsupported-content path in both
serializers.
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 2, 2026
Merged via the queue into microsoft:main with commit 3e1289d Oct 2, 2026
48 checks passed

This branch was successfully deployed

1 active deployment
github-app-auth — e0ba2eb1 Deployed Oct 2, 2026 by Lesereingrape via add_label #24237
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: OpenAI chat clients drop MP3 audio content that uses the standard audio/mpeg media type

4 participants