Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🎯 Changes
Very Early WIP: Add audio output streaming support to OpenAI adapter
This PR adds support for streaming audio output from OpenAI's audio-capable models (e.g.,
gpt-4o-audio-preview) via the Chat Completions API.Opening as a discussion starter.
Background
The current OpenAI adapter uses the Responses API (
client.responses.create()), which does not support audio output modalities. Audio output streaming requires the Chat Completions API withmodalities: ['text', 'audio']andaudio: { voice, format }configuration.Changes
1. New
AudioStreamChunktype (packages/typescript/ai/src/types.ts)'audio'toStreamChunkTypeunionAudioStreamChunkinterface withdata(base64),transcript, andformatfieldsStreamChunkunion type2. Audio output options (
packages/typescript/ai-openai/src/text/text-provider-options.ts)OpenAIAudioOutputOptionsinterface withmodalitiesandaudioconfigExternalTextProviderOptions3. OpenAI adapter audio routing (
packages/typescript/ai-openai/src/openai-adapter.ts)chatStream()now detectsmodalities.includes('audio')in provider optionschatStreamWithAudio()methodchatStreamWithAudio()uses Chat Completions API instead of Responses APIAudioStreamChunkfor audio data andContentStreamChunkfor transcripts4. Model metadata (
packages/typescript/ai-openai/src/model-meta.ts)gpt-4o-audio-previewmodel definitionOpenAIAudioOutputOptionsto audio model provider option typesUsage
Real-world usage
This is being used by the Durable Streams story-app example - a child-friendly AI story generator that streams both narrated audio and synchronized text transcripts to a durable stream for resilient playback.
Open questions
modalitiesthe right approach?ChatCompletionsAdapteras a separate class for broader Chat Completions API support?✅ Checklist
pnpm run test:pr.🚀 Release Impact