Hello,
I’m developing an application that analyzes PDF files using OpenAI’s Chat Completion API. I’m experiencing inconsistent results that are causing difficulties and would appreciate any help.
Problem:
- When uploading the same PDF file and requesting analysis with the same code, sometimes the analysis works properly, while other times I receive responses like “Please upload a PDF” or “Please attach a file.”
- This issue shows an unpredictable pattern where out of 10 requests with the same PDF, some succeed while others fail.
Details:
- API Used:
chat.completions.create
endpoint (GPT-4o model) - Code Example:
Copy# Step 1: Upload PDF file
with open(pdf_path, "rb") as f:
file_response = client.files.create(file=f, purpose="user_data")
file_id = file_response.id
# Step 2: Ask question with Chat Completion
completion = client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "user",
"content": [
{
"type": "file",
"file": {
"file_id": file_id,
},
},
{
"type": "text",
"text": "Please analyze the content of this PDF.",
},
],
}
],
)
Solutions Attempted:
- Added delay time (
sleep()
) after file upload to allow for processing - Implemented retry logic
- Used different API keys
- Created new OpenAI projects
However, while these methods may provide temporary solutions, the issue continues to occur intermittently.
Questions:
- What is the root cause of this inconsistency?
- Is this a known issue that OpenAI is aware of?
- Are there better ways to solve or mitigate this problem?
- Is there more detailed technical documentation on the PDF analysis process?
Any help or insights would be greatly appreciated. Thank you.