{"record":{"id":"aef06941b621c212","repo":"microsoft/semantic-kernel","slug":"audiocontent-must-have-data-bytes","errorCode":null,"errorMessage":"AudioContent must have Data bytes.","messagePattern":"AudioContent must have Data bytes\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Connectors/Connectors.OpenAI/Core/ClientCore.ChatCompletion.cs","lineNumber":912,"sourceCode":"            return ChatMessageContentPart.CreateImagePart(BinaryData.FromBytes(data), imageContent.MimeType, detailLevel);\n        }\n\n        if (imageContent.Uri is not null)\n        {\n            return ChatMessageContentPart.CreateImagePart(imageContent.Uri, detailLevel);\n        }\n\n        throw new ArgumentException($\"{nameof(ImageContent)} must have either Data or a Uri.\");\n    }\n\n    private static ChatMessageContentPart GetAudioContentItem(AudioContent audioContent)\n    {\n        if (audioContent.Data is { IsEmpty: false } data)\n        {\n            return ChatMessageContentPart.CreateInputAudioPart(BinaryData.FromBytes(data), GetChatInputAudioFormat(audioContent.MimeType));\n        }\n\n        throw new ArgumentException($\"{nameof(AudioContent)} must have Data bytes.\");\n    }\n\n    private static ChatMessageContentPart GetBinaryContentItem(BinaryContent binaryContent)\n    {\n        if (binaryContent.Data is { IsEmpty: false } data)\n        {\n            return ChatMessageContentPart.CreateFilePart(BinaryData.FromBytes(data), binaryContent.MimeType, Guid.NewGuid().ToString());\n        }\n\n        throw new ArgumentException($\"{nameof(BinaryContent)} must have Data bytes.\");\n    }\n\n    private static ChatInputAudioFormat GetChatInputAudioFormat(string? mimeType)\n    {\n        if (string.IsNullOrWhiteSpace(mimeType))\n        {\n            return ChatInputAudioFormat.Mp3;\n        }","sourceCodeStart":894,"sourceCodeEnd":930,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.OpenAI/Core/ClientCore.ChatCompletion.cs#L894-L930","documentation":"Thrown by GetAudioContentItem. Unlike images, OpenAI input-audio parts are byte-only (no audio URI is accepted), so AudioContent MUST carry non-empty Data. Empty/null Data makes the part unbuildable and raises an ArgumentException.","triggerScenarios":"Building an AudioContent with empty Data (e.g. an audio stream that yielded zero bytes, or only a MimeType) and including it in a chat request.","commonSituations":"Microphone capture produced no frames; a file read returned empty; constructing AudioContent as a placeholder before bytes are loaded.","solutions":["Populate AudioContent.Data with a non-empty byte array before adding the content to a message.","Verify the source stream's Length > 0 before reading into Data.","Do not send AudioContent until the bytes are actually available."],"exampleFix":"// before\nvar audio = new AudioContent(null, \"audio/wav\");\n// after\nvar audio = new AudioContent(await File.ReadAllBytesAsync(path), \"audio/wav\");","handlingStrategy":"validation","validationCode":"static AudioContent BuildAudio(byte[]? data, string mime) => data is { Length: > 0 } ? new AudioContent(data, mime) : throw new ArgumentException(\"AudioContent needs non-empty Data\");","typeGuard":"static bool AudioContentIsUsable(AudioContent a) => a.Data is { IsEmpty: false };","tryCatchPattern":"try { await client.GetChatCompletionAsync(history); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Data bytes\")) { /* load bytes and retry */ }","preventionTips":["Verify the source stream is non-empty before reading.","OpenAI input audio is bytes-only — never assume a URI fallback."],"tags":["openai","audio-input","audio-content","argument-validation"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}