run-llama / llama_parse

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

Invalid authentication token. Even with newly generated cloud API key. #71

Closed ggjx22 closed 1 week ago

ggjx22 commented 4 months ago

Hello Team,

Really like your work on LlamaParse. The web app is working fine for PDF parsing but not the package. Even when a new cloud API key is used, I got the same error.

import nest_asyncio
nest_asyncio.apply()

from llama_parse import LlamaParse
import os
from dotenv import load_dotenv

load_dotenv()
LLAMA_CLOUD_API_KEY = os.getenv("LLAMA_PARSE_API")

parser = LlamaParse(api_key=LLAMA_CLOUD_API_KEY, result_type='markdown')

try:
    document = parser.load_data(file_path='data/file.pdf')
except Exception as error:
    print(f'An error occurred: {error}')
Error while parsing the PDF file 'data/filepdf': Failed to parse the PDF file: {"detail":"Invalid authentication token"}
An error occurred: Failed to parse the PDF file: {"detail":"Invalid authentication token"}
anoopshrma commented 4 months ago

Can you check if you are getting the correct API key from env.

ggjx22 commented 4 months ago

Hmm I'm not sure what's going on. I switch to a Mac workstation with the exact piece of code in my issue above and the parser is working.

anoopshrma commented 4 months ago

I think it could be that env was not being picked correctly on your previous setup. Try printing it and check if it is getting correct API key or not.

RaniBgz commented 4 months ago

Bumping this because I am getting the same issue here. Using a valid OpenAI key, initializing both in the environment as 'LLAMA_CLOUD_API_KEY', and passing it as a parameter to Llama Parse, but I get:

    raise Exception(f"Failed to parse the PDF file: {response.text}")
Exception: Failed to parse the PDF file: {"detail":"Invalid authentication token"}

I am on Linux (Ubuntu), in a conda environment using Python 3.9. The call to openAI models works with this api key. In the tutorials, I also see the llama api key as looking like "llx...", whereas all of my keys from OpenAI start with "sk-...". Is there a different place to generate a llama key, or should a regular OpenAI key work?

Thanks for any info!

anoopshrma commented 4 months ago

LlamaCloud keys are totally different from openai keys!

Llamacloud api keys are used to parse pdf files! You can generate one here: cloud.llamaindex.ai

RaniBgz commented 4 months ago

HAH! I am not familiar with the llama environment yet, so I was following the generic llama-index "getting started" guide, and trying to use an OpenAI key (https://docs.llamaindex.ai/en/stable/getting_started/starter_example.html)

Thank you so much for the link anoopshrma

-Rani

anoopshrma commented 4 months ago

Sure no worries. Happy to help! Feel free to post any issue 💪

me-jordankim commented 1 month ago

I got same error, but I solved this.

When I set api_key={My OpenAI API key} like the document said, I got an error. Just change api_key={My Llama cloud API key}. then the problem will be solved. (But I don't know why either. Maybe the document is wrong?)

You can get Llama Cloud API key in here: https://cloud.llamaindex.ai/