paper-qa icon indicating copy to clipboard operation
paper-qa copied to clipboard

"AuthenticationError: OpenAIException - Error code: 401" with Docs object

Open bigboisw opened this issue 6 months ago • 1 comments

I am trying to set up PaperQA with Ollama running locally. I am trying to use the Docs object, except I keep running into the following error when using the code below:

from paperqa import Settings, ask, Docs
import os

model = "ollama/llama3.1" 
embedding = "ollama/mxbai-embed-large"

local_llm_config = {
    "model_list": [
        {
            "model_name": "ollama/llama3.1",
            "litellm_params": {
                "model": "ollama/llama3.1",
                "api_base": "http://localhost:11434",
                "set_verbose": True
            },
        }
    ]
}

docs = Docs()
docs.add("papers_new/ahuja-et-al-2008-1-moving-beyond-schumpeter-management-research-on-the-determinants-of-technological-innovation (1).pdf")
settings = Settings(
        llm="ollama/llama3.1",
        llm_config=local_llm_config,
        summary_llm="ollama/llama3.1",
        summary_llm_config=local_llm_config,
        embedding=embedding,
        paper_directory="papers_new",
    )

answer_response = docs.aquery("What is Schumpeterian tradition?", settings=settings)

Error:

Exception has occurred: AuthenticationError
litellm.AuthenticationError: AuthenticationError: OpenAIException - Error code: 401 - {'error': {'message': 'Incorrect API key provided: sk-no-ke******ired. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}
Received Model Group=gpt-4o-2024-08-06
Available Model Group Fallbacks=None
httpx.HTTPStatusError: Client error '401 Unauthorized' for url 'https://api.openai.com/v1/chat/completions'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401

During handling of the above exception, another exception occurred:

openai.AuthenticationError: Error code: 401 - {'error': {'message': 'Incorrect API key provided: sk-no-ke******ired. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}

During handling of the above exception, another exception occurred:

litellm.llms.OpenAI.openai.OpenAIError: Error code: 401 - {'error': {'message': 'Incorrect API key provided: sk-no-ke******ired. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}

During handling of the above exception, another exception occurred:

  File "C:\Users\Sean\Documents\Python Testing\PaperQA\test.py", line 21, in <module>
    docs.add("papers_new/ahuja-et-al-2008-1-moving-beyond-schumpeter-management-research-on-the-determinants-of-technological-innovation (1).pdf")
litellm.exceptions.AuthenticationError: litellm.AuthenticationError: AuthenticationError: OpenAIException - Error code: 401 - {'error': {'message': 'Incorrect API key provided: sk-no-ke******ired. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}
Received Model Group=gpt-4o-2024-08-06
Available Model Group Fallbacks=None

I tried setting a dummy API key as an .env variable like some suggested for the "ask" function, but it doesn't seem to work with docs. Is it possible to use Docs without an OpenAI key?

bigboisw avatar May 14 '25 05:05 bigboisw