Skip to content

fix(openaichat): send audio input as input_audio parts - #2951

Open
mtmcp wants to merge 1 commit into
stacklok:mainfrom
mtmcp:fix/openaichat-audio-input
Open

mtmcp wants to merge 1 commit into
stacklok:mainfrom
mtmcp:fix/openaichat-audio-input

Conversation

@mtmcp

@mtmcp mtmcp commented Nov 23, 2026

Copy link
Copy Markdown

Summary

The Chat Completions adapter refused every audio part before sending, so a
custom provider with api_flavor: openai-chat-completions could not send audio
even to a model that hears it. Chat Completions defines an input_audio user
content part, and llama.cpp's llama-server accepts it for models with an
audio projector.

  • Map inline audio parts to input_audio, with the format taken from the MIME
    type, ignoring case and parameters. Only audio/mpeg is IANA-registered; WAV
    has no registered type, so each toolchain uses its own name:
    • audio/wav: Go's MIME table
    • audio/wave: WHATWG sniffing, so http.DetectContentType and mecatui
    • audio/x-wav: Python mimetypes, libmagic, Linux /etc/mime.types
    • audio/vnd.wave: freedesktop shared-mime-info, so GIO and xdg-mime
    • audio/mpeg and audio/mp3 map to mp3; Chromium and shared-mime-info
      both recognize audio/mp3 as an alias of audio/mpeg.
  • Refuse URL-sourced audio and other audio types with an error naming the
    cause, since input_audio carries only inline wav or mp3 data.
  • Report Audio: true from Capabilities(). As in the Responses adapter, the
    bit describes what the wire can carry; per-model gating stays with
    composition's model metadata and the server hosting the model.
  • Correct the stale audio comments in internal/app and the multimodal input
    user documentation.

Issue relationship

Fixes #2949

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

Baseline checks

  • Linting (task lint)
  • Fast offline test suite (task test)
  • Pre-review race suite (task test:race)
  • Offline demo (go run ./cmd/mecademo)
  • Markdown changed: docs generation/link checks (task docs)
  • User docs/user-facing behavior changed: site build (task site:build)
  • Guarded engine API affected: compatibility check (task api:check)
  • Intentional engine API change: task api:update + engine/CHANGELOG.md

task site:build (needs Node 24 and pnpm) and the docs:grpc-ref step of
task docs (needs buf; no protobuf changes) were not run locally; left to CI.
No engine API change, so task api:check and task api:update do not apply.

Manual verification

Against llama.cpp llama-server (build b12633) serving
unsloth/gemma-4-E4B-it-GGUF:Q4_K_M, using the steps in #2949: before,
mecatui refuses the attachment; after, WAV and MP3 reach the model and it
answers questions about the clip. An audio/ogg part is refused before sending.

mecatl-local-audio-fixed

Changes

File Change
provider/openaichat/request.go Map audio parts to input_audio; MIME-to-format table; refusals
provider/openaichat/openaichat.go Capabilities() reports Audio: true; comment states the transmit-authority rule
provider/openaichat/multimodal_test.go New, like the openai and anthropic adapters' files: the image test (moved from request_test.go, renamed TestBuildParamsImagePart), tests for each MIME alias, the refusals, the request body on the wire, and the capability
provider/openaichat/request_test.go Image test moved out; its audio half became the tests above. New TestBuildParamsToolResultDropsMedia pins that tool messages stay text-only although Capabilities() now reports audio
provider/openaichat/session_header_test.go Extract drainStream so the new wire test reuses the stream-draining helper
internal/app/capability.go, capability_test.go, registry.go Correct stale comments that assumed no adapter carries audio
user-docs/features/sessions/multimodal-input.md Describe where audio input is available and the WAV/MP3 limit

User-facing change

Sessions on a custom provider with api_flavor: openai-chat-completions
advertise audio input, and mecatui lets users attach WAV and MP3 files. A
model that cannot hear is refused by its server. Responses and Messages
sessions are unchanged.

Special notes for reviewers

API compatibility: no break. No contract fields change. The existing
session_capabilities.audio flag reports true for sessions on Chat
Completions providers (see the opencode note below); mecatui and ACP already
handle that value. A newly enabled capability is a discoverable addition under
the wire API policy, so no major or feature-identifier change is needed. No
stored-data or Go API change.

opencode: the built-in provider uses the same adapter, so its sessions
can advertise audio until its model listing loads; the listing declares text
and image input, which then removes audio. Default and ACP sessions compute
capabilities before discovery runs, so with opencode as the default provider
they advertise audio. Its server refuses audio a model cannot take. This is the
same rule the fix applies everywhere: the adapter reports what the wire can
carry, and the model's server decides.

provider/openaichat is published independently; this changes its behavior,
not its exported API.

Map inline WAV and MP3 audio parts to Chat Completions input_audio and
report Audio: true, leaving per-model gating to composition and the
server. Refuse URL-sourced and other audio types with a clear error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

openaichat refuses audio input that Chat Completions servers accept

1 participant