Skip to content

Uploading PDF via Files API and using in Streaming gives 400 bad request #2472

@emdrayallday

Description

@emdrayallday

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • This is an issue with the Python library

Describe the bug

File "/Users/emdray/code/work/scoutos/services/big_boi/.venv/lib/python3.13/site-packages/openai/_base_client.py", line 1584, in request
raise self._make_status_error_from_response(err.response) from None

openai.BadRequestError: Error code: 400 - {'error': {'message': "Invalid file data: 'file_id'. Expected a file with an application/pdf MIME type, but got unsupported MIME type 'None'.", 'type': 'invalid_request_error', 'param': 'file_id', 'code': 'invalid_value'}}

To Reproduce

Upload a file with the client sending the file bytes
Use the file id in the messages

Code snippets

file_metadata = await client.files.create(file=file_bytes, purpose="user_data")

messages = [
    {
     'role': 'user', 
     'content': 
         [
           {
            'type': 'file',
            'file': {'file_id': <file_metadata.id> }
           },
          {'role': 'user','content': 'summarize'},
         ]
      }, 
]

OS

macos

Python version

v3.12.0

Library version

1.93.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions