PrefectHQ/fastmcp · error · ValueError

AudioContent is not supported by the Anthropic API

Error message

AudioContent is not supported by the Anthropic API

What it means

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.

Source

Thrown at fastmcp_slim/fastmcp/client/sampling/handlers/anthropic.py:216

                                type="tool_use",
                                id=item.id,
                                name=item.name,
                                input=item.input,
                            )
                        )
                    elif isinstance(item, TextContent):
                        content_blocks.append(
                            TextBlockParam(type="text", text=item.text)
                        )
                    elif isinstance(item, ImageContent):
                        if message.role != "user":
                            raise ValueError(
                                "ImageContent is only supported in user messages "
                                "for Anthropic"
                            )
                        content_blocks.append(_image_content_to_anthropic_block(item))
                    elif isinstance(item, AudioContent):
                        raise ValueError(
                            "AudioContent is not supported by the Anthropic API"
                        )
                    elif isinstance(item, ToolResultContent):
                        # Extract text content from the result
                        result_content: str | list[TextBlockParam] = ""
                        if item.content:
                            text_blocks: list[TextBlockParam] = [
                                TextBlockParam(type="text", text=sub_item.text)
                                for sub_item in item.content
                                if isinstance(sub_item, TextContent)
                            ]
                            if len(text_blocks) == 1:
                                result_content = text_blocks[0]["text"]
                            elif text_blocks:
                                result_content = text_blocks

                        content_blocks.append(
                            ToolResultBlockParam(

View on GitHub (pinned to 1f02114297)

Solutions

  1. Remove AudioContent blocks from the sampling messages before calling the handler
  2. Transcribe audio to text (e.g. with a STT service) and send TextContent instead
  3. Route sampling for audio-bearing contexts to a provider that supports audio
  4. If you control the tool, return text transcripts rather than raw audio

Example fix

// before
content=[AudioContent(type="audio", data=b64, mimeType="audio/wav")]

// after
content=[TextContent(type="text", text=transcribe_audio(b64))]
Defensive patterns

Strategy: fallback

Validate before calling

from mcp.types import AudioContent
has_audio = any(isinstance(b, AudioContent) for m in messages for b in as_list(m.content))
if has_audio:
    messages = transcribe_or_drop_audio(messages)

Type guard

def audio_free(messages) -> bool:
    from mcp.types import AudioContent
    return not any(isinstance(b, AudioContent) for m in messages for b in as_list(m.content))

Try / catch

try:
    return anthropic_handler(messages, params, ctx)
except ValueError as e:
    if "AudioContent" in str(e):
        return anthropic_handler(sanitize(messages), params, ctx)
    raise

Prevention

When it happens

Trigger: Sampling through AnthropicSamplingHandler where a SamplingMessage with list content contains an AudioContent block.

Common situations: Voice/multimodal MCP servers returning audio alongside text; contexts forwarded from audio-capable providers (e.g. OpenAI) to Anthropic.

Related errors


AI-assisted analysis of PrefectHQ/fastmcp@1f02114297 (2026-08-29). Data as JSON: /api/errors/be8a33d5df8d7c52. Report an issue: GitHub.