crewAIInc/crewAI · error · TypeError

Unsupported content type for Responses API: {content_type}

Error message

Unsupported content type for Responses API: {content_type}

What it means

The OpenAI Responses API formatter only accepts images (input_image) and PDFs (input_file) as file content blocks. When a FileReference is formatted and its content_type is neither an image MIME type nor application/pdf, it raises TypeError with the unsupported content type in the message. This is a hard capability boundary of the Responses API, mirrored by the library.

Source

Thrown at lib/crewai-files/src/crewai_files/formatting/openai.py:66

        Raises:
            TypeError: If resolved type is not supported.
        """
        is_image = content_type.startswith("image/")
        is_pdf = content_type == "application/pdf"

        if isinstance(resolved, FileReference):
            if is_image:
                return {
                    "type": "input_image",
                    "file_id": resolved.file_id,
                }
            if is_pdf:
                return {
                    "type": "input_file",
                    "file_id": resolved.file_id,
                }
            raise TypeError(
                f"Unsupported content type for Responses API: {content_type}"
            )

        if isinstance(resolved, UrlReference):
            if is_image:
                return {
                    "type": "input_image",
                    "image_url": resolved.url,
                }
            if is_pdf:
                return {
                    "type": "input_file",
                    "file_url": resolved.url,
                }
            raise TypeError(
                f"Unsupported content type for Responses API: {content_type}"
            )

View on GitHub (pinned to 754d7323be)

Solutions

  1. Convert the file content to text and include it in the prompt instead of as a file block.
  2. Only attach image/* or application/pdf files via FileReference to Responses API calls.
  3. Re-encode the document to PDF before uploading if the model must 'see' it as a document.
  4. Branch on content_type before formatting and drop/skip unsupported attachments with a warning.

Example fix

# before
ref = FileReference(file_id="file-123", content_type="text/csv")  # not image/pdf
block = responses_formatter.format_block(ref)  # TypeError

# after
if ref.content_type.startswith("image/") or ref.content_type == "application/pdf":
    block = responses_formatter.format_block(ref)
else:
    csv_text = download_and_read(ref)
    task_context += f"\nFile contents:\n{csv_text}"
Defensive patterns

Strategy: validation

Validate before calling

def responses_attachable(content_type: str) -> bool:
    return content_type.startswith("image/") or content_type == "application/pdf"

if isinstance(resolved, FileReference) and not responses_attachable(resolved.content_type):
    # inline as text instead of a file block
    attachments_text.append(read_file_text(resolved))

Type guard

def is_responses_file(ref: FileReference) -> TypeGuard[FileReference]:
    ct = ref.content_type or ""
    return ct.startswith("image/") or ct == "application/pdf"

Try / catch

try:
    block = responses_formatter.format_block(resolved)
except TypeError as e:
    if "Unsupported content type" in str(e):
        logger.warning("dropping unsupported attachment %s", getattr(resolved, 'content_type', '?'))
        block = None  # or inline text
    else:
        raise

Prevention

When it happens

Trigger: Attaching a FileReference whose content_type is e.g. text/csv, audio/mpeg, video/mp4, or application/json to an OpenAI Responses-API crew; uploading a .txt or .docx via the files API and passing the resulting file_id reference to the formatter.

Common situations: Porting a pipeline from Chat Completions (which took plain text file content) to the Responses API; assuming any file type can be attached because file_id uploads succeed; feeding provider-agnostic attachments into an OpenAI-specific formatter.

Related errors


AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15). Data as JSON: /api/errors/ddf025f73006d49c. Report an issue: GitHub.