Can I attach a file and prompt via the API?

I’ve got pdfs which I can currently manually passing through to GPT via the user interface with a prompt (can you summarise the attached file). I have created a python script which reads the PDF and passes that through, but given the 4000 token limit, I don’t always get the full contents in and context could be lost as I have to split the document. Is there a way to replicate what I can do via the user interface through the API?

Cheers