Downloading a pdf and Summarizing it using Assistants API

Hi awesome OpenAI Developers Community!

I wrote a python script to download a pdf (using request) , then read the script (Code Below) and summarize the script using Assistants API + Retrieval Tool but I keep on getting
" requests.exceptions.HTTPError: 404 Client Error: Not Found for url:"

Please, can someone help me with why that error keeps occurring?

import os
import requests

# Environment variable for API key
api_key = os.environ.get("OPENAI_API_KEY")

def download_pdf(url, filename):
    response = requests.get(url)
    with open(filename, "wb") as file:

def summarize_pdf_with_assistant(assistant_id, pdf_file_path, prompt="Summarize the key points of this PDF for me"):
    headers = {"Authorization": f"Bearer {api_key}"}

    # Create thread
    thread_response =
        f"{assistant_id}/threads", headers=headers
    thread_id = thread_response.json()["data"]["id"]

    # Upload PDF with metadata
    files = {"file": (os.path.basename(pdf_file_path), open(pdf_file_path, "rb"), "application/pdf")}
    message_response =

    # Extract and return assistant response
    messages = message_response.json().get("data", {}).get("messages", [])
    for message in messages:
        if message.get("role") == "assistant":
            return message.get("content", {}).get("text", "No summary available")

    return "No assistant response found"

# Define URL and paths
url = ""
directory = "C:\\Users\\saya\\MyDrive\\Desktop\\python steps\\"
input_pdf = os.path.join(directory, "downloaded_pdf.pdf")
output_summary = os.path.join(directory, "summary.txt")

# Download and process PDF
download_pdf(url, input_pdf)

# Customize the prompt as needed
summary_prompt = "Summarize the key points of this PDF for me, focusing on the main regulations for entrepreneurs."

# Summarize PDF with customized prompt
summary = summarize_pdf_with_assistant(assistant_id="asst_NgiHE1odsYwZ2c1jb0IjwAOT", pdf_file_path=input_pdf, prompt=summary_prompt)

# Save summary (add error handling and consider user prompt for summary generation)
if summary != "Error in API call" and summary != "No assistant response found":
    with open(output_summary, "w") as file:
        print(f"Summary saved to {output_summary}")
    print("Failed to create a summary.")
type or paste code here