run-llama / llama_parse

Parse files for optimal RAG
https://www.llamaindex.ai
MIT License
3.19k stars 312 forks source link

401: Invalid API Key when requesting job results #418

Open mjcourte opened 1 month ago

mjcourte commented 1 month ago

Describe the bug Write a concise description of what the bug is.

Bearer Token of \<my llama cloud API key> does not allow me to download my job results.

Using a new account API key, I was able to parse a .pdf document, and retrieve it once (my first ever usage of LlamaParse). My script did not locally store the markdown, and while debugging downstream code, I need to recreate the objects md_json_list in example:

https://github.com/run-llama/llama_parse/blob/main/examples/multimodal/product_manual_rag.ipynb

md_json_objs = parser.get_json_result(files)
md_json_list = md_json_objs[0]["pages"]
image_dicts = parser.get_images(md_json_objs, download_path="data_images")

without hitting the API with another parse job, so I assume the right thing would be to API request download the markdown result.

LLAMA_CLOUD_TIMEOUT = 5
job_id = "f6b7a044-b820-4498-bfc8-f5917999d66f"
base_url = f"https://api.cloud.llamaindex.ai//api/v1/parsing/job/{job_id}"
payload = {}
headers = {
    "Accept": "application/json",
    "Authorization": f"Bearer {os.getenv('LLAMA_CLOUD_API_KEY')}",
}
print(headers)
result_json = requests.request(
    "GET", f"{base_url}/result/json", data=payload, timeout=LLAMA_CLOUD_TIMEOUT
)
if result_json.status_code == 401:
    print(f"Request status code {result_json.status_code}")
    sys.exit()

The result status is always 401, so I attempted the same in the web docs UI at:

https://docs.cloud.llamaindex.ai/API/get-job-json-result-api-v-1-parsing-job-job-id-result-json-get

Using the same llama cloud API key and job id. (401)

{
  "detail": "Invalid API Key"
}

I created another LLama Cloud API key (both free tier, and I have credits remaining for the day), and it did not work either in python requests, or the web docs UI.

I can go to the job in my Parse tab at cloud.llamaindex.ai/parse, and export the items manually that way with no issue, but I will need this to work programmatically.

Files If possible, please provide the PDF file causing the issue.

The only file sent was a NASA Nov 2006 style guide pdf, freely available online.

Job ID If you have it, please provide the ID of the job you ran. You can find it here: https://cloud.llamaindex.ai/parse in the "History" tab.

f6b7a044-b820-4498-bfc8-f5917999d66f

Screenshots Feel free to also provide screenshots if relevant.

Client: Please remove untested options:

Options What options did you use? Multimodal, fast mode, parsing instructions, etc.

parser = LlamaParse(
    result="markdown",
    parsing_instruction="You are given style guide documents",
    use_vendor_multimodal_model=True,
    vendor_multimodal_model_name="openai-gpt4o",
    show_progress=True,
    language="en",
)

Additional context Add any additional context about the problem here.

Note that in the API reference documentation, the request headers contain the authorization bearer key twice. Probably unrelated.

https://docs.cloud.llamaindex.ai/API/get-job-json-result-api-v-1-parsing-job-job-id-result-json-get

import requests

url = "https://api.cloud.llamaindex.ai/api/v1/parsing/job/f6b7a044-b820-4498-bfc8-f5917999d66f/result/json"

payload={}
headers = {
  'Accept': 'application/json',
  'Authorization': 'Bearer <TOKEN>',
  'Authorization': 'Bearer <TOKEN>'
}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)
mosoai commented 1 month ago

Hi, I'm experiencing the same issue. My observation is that the API key is not being persisted. Although it's displayed in the popup during generation, but the column where the key should be shown (I guess with stars ***) remains empty.

marcosallustio commented 2 weeks ago

I have the same issue when I try to call API (for example on n8n) but with the tool of Parse in LlamaCloud the parsing is carried out

rodamora commented 18 hours ago

I am having the same problem. I can create a job with the API but cannot get the results. Getting a 401 Unauthorized response.

How can we fix this?