RFC 0010: Audio content and media over 5 MiB

  • Status: Accepted (decision); audio deferred to 2.0
  • Author(s): llm4s maintainers
  • Tracking issue: #3154
  • Pull request: the epic #3137 multimodal PR

Summary

llm4s 1.x does not add ContentPart.Audio. Audio input waits for 2.0, where it is a new case of the sealed ContentPart. Large private media (over the 5 MiB inline bound) goes by reference: a URL the provider fetches, or a MediaSource.ProviderFile uploaded to the provider’s Files API. Each provider adds file references as an internal change, with no new API.

Motivation

ContentPart is Text | Image | Document. MediaType defines WAV, MP3, FLAC and Ogg, but no part carries them, so OpenAI input_audio, Gemini audio inlineData and llm4s-speech output cannot reach a model. Separately, the 5 MiB inline bound applies to every client.complete, and Anthropic and OpenAI images have no file route, so a 10 MB private PDF cannot be sent to Anthropic at all (#3154).

Detailed design

Audio. Not in 1.x. In 2.0: final case class Audio(source: MediaSource, mediaType: AudioMediaType) beside Image and Document, encoded by OpenAI (input_audio), Gemini and Vertex AI (inlineData / fileData) and the openai-compatible dialects that declare it, and refused with UnsupportedContentPartError everywhere else. ContentPartContract gains its cases.

Media over 5 MiB. The bound stays one value for every part, wherever it is built. The stored-JSON codec enforces it too, so a per-call bound would produce parts a checkpoint cannot read back. Larger media is sent by reference:

  • MediaSource.Url where the provider fetches web URLs;
  • MediaSource.ProviderFile for a file uploaded to the provider. Anthropic (Files API) and OpenAI images (file_id) gain encoders for it in their modules. That is an internal change to each client, tracked as a follow-up of #3154, and needs no new type.

Alternatives

  • Add ContentPart.Audio in a 1.x minor release. This is binary compatible, but it is a source break: every exhaustive match on ContentPart in user code gains a warning, which -Werror turns into an error. The compatibility policy rules that out for a @Stable type in 1.x (“no new abstract member”, and source compatibility across 1.x). Rejected.
  • Carry audio as a Document with an audio MediaType. Document takes a DocumentMediaType, so the media type hierarchy would need widening. Every provider’s document encoder would then have to tell audio from documents, and a provider that sends documents but not audio could silently send an audio file as a PDF-like attachment. Rejected: it trades a visible source break for an invisible behaviour hazard.
  • An @Experimental audio part outside the sealed trait (for example a separate AudioPart that only some clients take). This would need a parallel path through Message, the codecs and every provider. Rejected as more surface than the 2.0 case it would duplicate.

Compatibility impact

  • Modules and tiers: none in 1.x; llm4s-core (@Stable ContentPart) in 2.0.
  • Binary / source / behaviour / wire formats: unchanged in 1.x. In 2.0, a new ContentPart case and its JSON ("type": "audio"), which a 1.x reader refuses.