Building public GPTs for custom PDFs

I tried creating a GPT by uploading a PDF. It worked well from the UI and was able to answer questions. But when I sent the link to some one they need to be ChatGPT plus users to use it. So I tried using an API and linking assistant with ChatCompletion end point but that kept on giving me errors. I also tried passing file id to chatCompletion but that did not work. Below are relevant code snippets - please guide on suitable approach.

file = client.files.create(
file=open(“mydoc.pdf”, “rb”),

Add the file to the assistant

assistant = client.beta.assistants.create(
instructions="You will answer question on the pdf document that I have uploaded. … ",
tools=[{“type”: “retrieval”}],

while True:
# Get user input
user_input = input("You: ") #followed by exit code

#using assitant with chat
response =
messages=[{“role”: “user”, “content”: user_input}]

#using file id with ChatCompletion
response = client.ChatCompletion.create(
{“role”: “system”, “content”: “You will answer question on the pdf document that I have uploaded. …”},
{“role”: “user”, “content”: user_input}


Did you try using the assistant API with threads and messages instead of the ChatCompletion API?

Thanks, using the Assistant API fixed this.

1 Like