Skip to content

PathLike file contents fail when passed inside upload tuples #3473

Description

@VectorPeak

Summary

PathLike upload content works when passed directly, but fails when used as the content element inside multipart upload tuples such as ("custom.txt", Path("input.jsonl")).

The README documents file uploads as accepting bytes, PathLike, or a tuple of (filename, contents, media type), and the internal FileTypes aliases model tuple contents as FileContent, which includes PathLike.

Expected behavior

The SDK should accept PathLike consistently in documented file upload shapes, including tuple inputs where the second element is file contents.

Reproduction shape

from pathlib import Path
from openai._files import to_httpx_files

to_httpx_files({"file": ("custom.txt", Path("README.md"))})

Actual behavior

The tuple is treated as final file content before the tuple branch can normalize the second element. The PathLike value is passed through to httpx, which later expects file-like behavior and can fail with an error such as AttributeError: 'WindowsPath' object has no attribute 'read'.

Impact

Users following the documented tuple upload interface cannot combine a custom filename, media type, or headers with path-like file content.

Proposed fix

Normalize upload tuples before treating values as final file content, so the tuple content element is converted through the same PathLike reading path used for direct file inputs.

I have a focused patch ready and would like to be assigned to this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions