Skip to content

Add audio input support to Responses API - #999

Open
Akshay Sonawane (apsonawane) wants to merge 2 commits into
mainfrom
asonawane/gemma4-responses-audio
Open

Add audio input support to Responses API#999
Akshay Sonawane (apsonawane) wants to merge 2 commits into
mainfrom
asonawane/gemma4-responses-audio

Conversation

@apsonawane

@apsonawane Akshay Sonawane (apsonawane) commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Add audio input support to Responses API

Summary

Extend the SDK v2 Responses API multimodal pipeline to support audio alongside text and images.

Changes

  • Decode base64 input_audio payloads into owned AudioItem instances.
  • Reject empty formats, empty payloads, and invalid base64.
  • Detect audio content during chat-session processing.
  • Generalize vision processing into a shared media path.
  • Add <|audio|> markers to multimodal prompts.
  • Route requests through:
    • ProcessImages for images
    • ProcessAudios for audio
    • ProcessImagesAndAudios for combined media
  • Calculate the token budget from processed input_ids.
  • Apply existing first-turn and cache restrictions to all media.
  • Preserve text-only and image-only behavior.

Motivation

The Responses schema already parsed input_audio, and the runtime already provided AudioItem and ORT GenAI audio-processing APIs. However, the Responses converter rejected audio before it reached the model.

Media expansion also happened after generator sizing, which could produce an insufficient max_length.

Copilot AI balanced review requested due to automatic review settings August 14, 2026 01:07
@vercel

vercel Bot commented Aug 14, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
foundry-local Ready Ready Preview Aug 14, 2026 1:37am

Request Review

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.

Pull request overview

Extends the C++ Responses API pipeline to accept audio alongside text and images.

Changes:

  • Decodes and validates base64 audio input.
  • Adds audio and combined-media prompt processing.
  • Calculates token budgets after multimodal expansion and adds unit coverage.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
response_converter_test.cc Tests audio conversion and invalid base64.
onnx_chat_generator_vision_test.cc Tests audio and combined-media markers.
response_converter.cc Converts audio payloads into owned items.
onnx_chat_generator.h Generalizes generator interfaces for media.
onnx_chat_generator.cc Processes image/audio inputs and token sizing.
chat_session.cc Detects and routes audio media turns.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +433 to +434
} else if (part.view && part.view->type == FOUNDRY_LOCAL_ITEM_AUDIO) {
audios.push_back(static_cast<const AudioItem*>(part.view));
Comment on lines +198 to +201
if (part.view->type == FOUNDRY_LOCAL_ITEM_IMAGE) {
content.push_back(nlohmann::json{{"type", "image"}});
} else if (part.view->type == FOUNDRY_LOCAL_ITEM_AUDIO) {
content.push_back(nlohmann::json{{"type", "audio"}});
Comment thread sdk_v2/cpp/src/inferencing/generative/chat/onnx_chat_generator.h Outdated
Comment thread sdk_v2/cpp/src/inferencing/generative/chat/onnx_chat_generator.cc Outdated
EXPECT_EQ(bytes[3], 4u);
}

TEST(ResponseConverterTest, ToSessionRequest_InputAudio_RejectsInvalidBase64) {
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.

2 participants