I am a beginner. I purchased tokens to use GPT-4 and finally figured out how to import the GPT-4 model into my Jupyter Notebook.

%env OPENAI_API_KEY= (my key goes here)

!pip install --upgrade openai wandb

from openai import OpenAI

LLM = OpenAI()

response = LLM.chat.completions.create(


messages=[{'role': 'user', 'content': 'What is 1+1?'}],)


Now, I would like to upload a PDF document and prompt GPT-4 to extract important headings from the document. Can you provide the code for how to do this? Specifically the part where you upload the PDF, and prompt GPT-4 with an example instruction.

If I'm not mistaken, I don't need to process the PDF into text format because GPT-4 can work directly with PDFs? That's why I wanted to use GPT-4, because when I was converting the PDF to text, it was very messy due to tables, headers, footers, etc.


1 Answer 1


OpenAI's API does not support providing PDFs. Therefore, what you intend to do is not possible. You have other options though:

  • Parse the PDF locally and send text to GPT4. The parse may consist of extracting only text or something more involved like trying to convert the PDF to something structured like latex (e.g. this) and sending the result to GPT4 to process.
  • Convert the PDF to images locally and send them to GPT4-V for it to extract information the way you want and, optionally, send back the returned text to GPT-4 for further processing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.