{"record":{"id":"be8a33d5df8d7c52","repo":"PrefectHQ/fastmcp","slug":"audiocontent-is-not-supported-by-the-anthropic-api","errorCode":null,"errorMessage":"AudioContent is not supported by the Anthropic API","messagePattern":"AudioContent is not supported by the Anthropic API","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/client/sampling/handlers/anthropic.py","lineNumber":216,"sourceCode":"                                type=\"tool_use\",\n                                id=item.id,\n                                name=item.name,\n                                input=item.input,\n                            )\n                        )\n                    elif isinstance(item, TextContent):\n                        content_blocks.append(\n                            TextBlockParam(type=\"text\", text=item.text)\n                        )\n                    elif isinstance(item, ImageContent):\n                        if message.role != \"user\":\n                            raise ValueError(\n                                \"ImageContent is only supported in user messages \"\n                                \"for Anthropic\"\n                            )\n                        content_blocks.append(_image_content_to_anthropic_block(item))\n                    elif isinstance(item, AudioContent):\n                        raise ValueError(\n                            \"AudioContent is not supported by the Anthropic API\"\n                        )\n                    elif isinstance(item, ToolResultContent):\n                        # Extract text content from the result\n                        result_content: str | list[TextBlockParam] = \"\"\n                        if item.content:\n                            text_blocks: list[TextBlockParam] = [\n                                TextBlockParam(type=\"text\", text=sub_item.text)\n                                for sub_item in item.content\n                                if isinstance(sub_item, TextContent)\n                            ]\n                            if len(text_blocks) == 1:\n                                result_content = text_blocks[0][\"text\"]\n                            elif text_blocks:\n                                result_content = text_blocks\n\n                        content_blocks.append(\n                            ToolResultBlockParam(","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/client/sampling/handlers/anthropic.py#L198-L234","documentation":"ValueError from `_convert_to_anthropic_messages` (list-content branch): the Anthropic API has no audio input support, so any AudioContent in a message list is rejected outright.","triggerScenarios":"Sampling through AnthropicSamplingHandler where a SamplingMessage with list content contains an AudioContent block.","commonSituations":"Voice/multimodal MCP servers returning audio alongside text; contexts forwarded from audio-capable providers (e.g. OpenAI) to Anthropic.","solutions":["Remove AudioContent blocks from the sampling messages before calling the handler","Transcribe audio to text (e.g. with a STT service) and send TextContent instead","Route sampling for audio-bearing contexts to a provider that supports audio","If you control the tool, return text transcripts rather than raw audio"],"exampleFix":"// before\ncontent=[AudioContent(type=\"audio\", data=b64, mimeType=\"audio/wav\")]\n\n// after\ncontent=[TextContent(type=\"text\", text=transcribe_audio(b64))]","handlingStrategy":"fallback","validationCode":"from mcp.types import AudioContent\nhas_audio = any(isinstance(b, AudioContent) for m in messages for b in as_list(m.content))\nif has_audio:\n    messages = transcribe_or_drop_audio(messages)","typeGuard":"def audio_free(messages) -> bool:\n    from mcp.types import AudioContent\n    return not any(isinstance(b, AudioContent) for m in messages for b in as_list(m.content))","tryCatchPattern":"try:\n    return anthropic_handler(messages, params, ctx)\nexcept ValueError as e:\n    if \"AudioContent\" in str(e):\n        return anthropic_handler(sanitize(messages), params, ctx)\n    raise","preventionTips":["Transcribe audio to text before Anthropic sampling","Route audio workloads to audio-capable providers","Filter AudioContent blocks in middleware for Anthropic contexts","Document that Anthropic accepts no audio input"],"tags":["anthropic","sampling","audio","unsupported"],"backgroundTag":"unsupported-media-type","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}