Issue with LlamaParse ... #458

Open
opened 2026-02-16 00:17:54 -05:00 by yindo · 1 comment
Owner

Originally created by @Yash-synergy on GitHub (Apr 18, 2025).

Basically my anthropic key is not being accepted when I am trying to use LVM for parsing.

job id: 4fcb9c15-4424-4cce-bf5f-97032018f2ef

This is the code I am using.
def submit_parsing_job_direct_api(pdf_path, api_key, vendor_api_key, instruction_prompt, vendor_model_name):
"""
Submits the document parsing job directly via API using a Llama API key and vendor API key.
Returns the job ID ('id') on success, or the HTTP status code (int)
on specific API errors (401, 429), or None for other errors.
Handles PDF files ONLY.
"""
file_extension = os.path.splitext(pdf_path)[1].lower()
file_name = os.path.basename(pdf_path)

if file_extension != '.pdf':
    print(f" > [{file_name}] Error: Unsupported file type '{file_extension}'. Only PDF files are supported. Skipping.")
    return None # Indicate failure, not a specific API error code

print(f"Submitting '{file_name}' via Llama Cloud API using {vendor_model_name}...")
upload_url = "https://api.cloud.llamaindex.ai/api/parsing/upload"
headers = {
    "Authorization": f"Bearer {api_key}", # Use the Llama API key
    "accept": "application/json",
}

# Prepare payload data
multipart_payload_data = {
'parsing_instruction': instruction_prompt,
'invalidate_cache': 'true',
'use_vendor_multimodal_model': 'false',
'vendor_multimodal_model_name': vendor_model_name,
'vendor_api_key': vendor_api_key,
'output_tables_as_html': 'true',
'parse_mode': 'parse_page_with_lvm'  # Added directly here

}

try:
    with open(pdf_path, 'rb') as f:
        files_payload = {
            'file': (file_name, f, 'application/pdf') # MIME type is fixed for PDF
        }
        for key, value in multipart_payload_data.items():
            files_payload[key] = (None, value)

        response = requests.post(upload_url, headers=headers, files=files_payload)

    print(f" > [{file_name}] API Submission Response Status: {response.status_code}")

    if response.status_code == 200:
        response_json = response.json()
        job_id = response_json.get("id")
        if job_id:
            print(f" > [{file_name}] Successfully submitted job. Job ID: {job_id}")
            return job_id # Return job ID string on success
        else:
            print(f" > [{file_name}] API response OK, but 'id' key not found: {response_json}")
            return None # Indicate other failure
    elif response.status_code in [401, 429]:
         # Return the specific status code for key-related errors
         print(f" > [{file_name}] API submission failed: Status {response.status_code}.")
         return response.status_code
    elif response.status_code == 400:
         print(f" > [{file_name}] API submission failed: Bad Request (400). Check file/request details.")
         print(f" > Response: {response.text}")
         return None # Indicate other failure
    else:
        print(f" > [{file_name}] API submission failed. Status: {response.status_code}, Response: {response.text}")
        return None # Indicate other failure

except requests.exceptions.RequestException as e:
    print(f" > [{file_name}] Error submitting job via API: {e}")
    return None # Indicate other failure
except FileNotFoundError:
    print(f" > [{file_name}] Error: File not found at {pdf_path}")
    return None # Indicate other failure
except Exception as e:
    print(f" > [{file_name}] An unexpected error occurred during submission: {e}")
    traceback.print_exc()
    return None # Indicate other failure

LVM with anthropic key and somehow it isn't right for llama parse when I try it on Ui, says connection invalid

Image
Originally created by @Yash-synergy on GitHub (Apr 18, 2025). Basically my anthropic key is not being accepted when I am trying to use LVM for parsing. job id: 4fcb9c15-4424-4cce-bf5f-97032018f2ef This is the code I am using. def submit_parsing_job_direct_api(pdf_path, api_key, vendor_api_key, instruction_prompt, vendor_model_name): """ Submits the document parsing job directly via API using a Llama API key and vendor API key. Returns the job ID ('id') on success, or the HTTP status code (int) on specific API errors (401, 429), or None for other errors. Handles PDF files ONLY. """ file_extension = os.path.splitext(pdf_path)[1].lower() file_name = os.path.basename(pdf_path) if file_extension != '.pdf': print(f" > [{file_name}] Error: Unsupported file type '{file_extension}'. Only PDF files are supported. Skipping.") return None # Indicate failure, not a specific API error code print(f"Submitting '{file_name}' via Llama Cloud API using {vendor_model_name}...") upload_url = "https://api.cloud.llamaindex.ai/api/parsing/upload" headers = { "Authorization": f"Bearer {api_key}", # Use the Llama API key "accept": "application/json", } # Prepare payload data multipart_payload_data = { 'parsing_instruction': instruction_prompt, 'invalidate_cache': 'true', 'use_vendor_multimodal_model': 'false', 'vendor_multimodal_model_name': vendor_model_name, 'vendor_api_key': vendor_api_key, 'output_tables_as_html': 'true', 'parse_mode': 'parse_page_with_lvm' # Added directly here } try: with open(pdf_path, 'rb') as f: files_payload = { 'file': (file_name, f, 'application/pdf') # MIME type is fixed for PDF } for key, value in multipart_payload_data.items(): files_payload[key] = (None, value) response = requests.post(upload_url, headers=headers, files=files_payload) print(f" > [{file_name}] API Submission Response Status: {response.status_code}") if response.status_code == 200: response_json = response.json() job_id = response_json.get("id") if job_id: print(f" > [{file_name}] Successfully submitted job. Job ID: {job_id}") return job_id # Return job ID string on success else: print(f" > [{file_name}] API response OK, but 'id' key not found: {response_json}") return None # Indicate other failure elif response.status_code in [401, 429]: # Return the specific status code for key-related errors print(f" > [{file_name}] API submission failed: Status {response.status_code}.") return response.status_code elif response.status_code == 400: print(f" > [{file_name}] API submission failed: Bad Request (400). Check file/request details.") print(f" > Response: {response.text}") return None # Indicate other failure else: print(f" > [{file_name}] API submission failed. Status: {response.status_code}, Response: {response.text}") return None # Indicate other failure except requests.exceptions.RequestException as e: print(f" > [{file_name}] Error submitting job via API: {e}") return None # Indicate other failure except FileNotFoundError: print(f" > [{file_name}] Error: File not found at {pdf_path}") return None # Indicate other failure except Exception as e: print(f" > [{file_name}] An unexpected error occurred during submission: {e}") traceback.print_exc() return None # Indicate other failure LVM with anthropic key and somehow it isn't right for llama parse when I try it on Ui, says connection invalid <img width="514" alt="Image" src="https://github.com/user-attachments/assets/1b5c4f13-e2b3-4f90-852c-ed587c5b70e0" />
yindo added the bug label 2026-02-16 00:17:54 -05:00
Author
Owner

@jlvanhulst commented on GitHub (Apr 28, 2025):

I have (had) the same problem - (still persists today) using the gpt4o mode with openai key provided. Would be nice to have received a heads up on change like that for people using this stuff in production ... :)

@jlvanhulst commented on GitHub (Apr 28, 2025): I have (had) the same problem - (still persists today) using the gpt4o mode with openai key provided. Would be nice to have received a heads up on change like that for people using this stuff in production ... :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: run-llama/llama_cloud_services#458