aider icon indicating copy to clipboard operation
aider copied to clipboard

Uncaught AuthenticationError in utils.py line 6747

Open moonmonsta opened this issue 1 year ago • 2 comments

Aider version: 0.56.0 Python version: 3.12.5 Platform: Linux-6.10.7-200.fc40.x86_64-x86_64-with-glibc2.39 Python implementation: CPython Virtual environment: No OS: Linux 6.10.7-200.fc40.x86_64 (64bit) Git version: git version 2.46.0

An uncaught exception occurred:

Traceback (most recent call last):
  File "openai.py", line 1033, in completion
    raise e
  File "openai.py", line 928, in completion
    openai_client = self._get_openai_client(
                    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "openai.py", line 750, in _get_openai_client
    _new_client = OpenAI(
                  ^^^^^^^
  File "_client.py", line 105, in __init__
    raise OpenAIError(
openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "main.py", line 1345, in completion
    raise e
  File "main.py", line 1318, in completion
    response = openai_chat_completions.completion(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "openai.py", line 1041, in completion
    raise OpenAIError(status_code=500, message=traceback.format_exc())
litellm.llms.openai.OpenAIError: Traceback (most recent call last):
  File "openai.py", line 1033, in completion
    raise e
  File "openai.py", line 928, in completion
    openai_client = self._get_openai_client(
                    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "openai.py", line 750, in _get_openai_client
    _new_client = OpenAI(
                  ^^^^^^^
  File "/home/jay/.local/lib/python3.12/site-packages/openai/_client.py", line 105, in __init__
    raise OpenAIError(
openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "aider", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "main.py", line 698, in main
    coder.run()
  File "base_coder.py", line 735, in run
    self.run_one(user_message, preproc)
  File "base_coder.py", line 778, in run_one
    list(self.send_message(message))
  File "base_coder.py", line 1202, in send_message
    saved_message = self.auto_commit(edited)
                    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "base_coder.py", line 1885, in auto_commit
    res = self.repo.commit(fnames=edited, context=context, aider_edits=True)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "repo.py", line 102, in commit
    commit_message = self.get_commit_message(diffs, context)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "repo.py", line 187, in get_commit_message
    commit_message = simple_send_with_retries(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "sendchat.py", line 44, in wrapper
    return decorated_func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "_sync.py", line 105, in retry
    ret = target(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^
  File "sendchat.py", line 106, in simple_send_with_retries
    _hash, response = send_completion(**kwargs)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "sendchat.py", line 86, in send_completion
    res = litellm.completion(**kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "utils.py", line 1078, in wrapper
    raise e
  File "utils.py", line 966, in wrapper
    result = original_function(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "main.py", line 2766, in completion
    raise exception_type(
          ^^^^^^^^^^^^^^^
  File "utils.py", line 8438, in exception_type
    raise e
  File "utils.py", line 6747, in exception_type
    raise AuthenticationError(
litellm.exceptions.AuthenticationError: litellm.AuthenticationError: AuthenticationError: OpenAIException - Traceback (most recent call last):
  File "openai.py", line 1033, in completion
    raise e
  File "openai.py", line 928, in completion
    openai_client = self._get_openai_client(
                    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "openai.py", line 750, in _get_openai_client
    _new_client = OpenAI(
                  ^^^^^^^
  File "/home/jay/.local/lib/python3.12/site-packages/openai/_client.py", line 105, in __init__
    raise OpenAIError(
openai.openaiError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable


moonmonsta avatar Sep 15 '24 05:09 moonmonsta

Thank you for filing this issue, aider should display this error condition in a more friendly way.

Regarding the actual problem: According to the error message you provided

The api_key client option must be set either by
passing api_key to the client or by setting the
OPENAI_API_KEY environment variable

It seems you did not setup the required OPENAI_API_KEY environment variable for accessing the OpenAI API. To set this up correctly or if you intended to use a different API or provider, please check the documentation -> https://aider.chat/docs/llms.html

fry69 avatar Sep 15 '24 08:09 fry69

The aider.docs instructions should be as follows: If you want to run Aider on another LLM and without any API key from OpenAI, you should do the following in the case of using Claude Sonnet:

1.Install aider python -m pip install aider-chat

2.Don't run aider yet, but first set up the Anthropic API key setx ANTHROPIC_API_KEY

3.If you're on Windows, restart the shell after using setx

4.To run aider, you first have to go to the directory with your git repo files. If you are in your git repo directory, type: aider --sonnet

Now it should work. The same steps apply for other LLMs, but with the following changes: point 2. setx Name_LLM_API_KEY and point 4. Run your specific LLM model by typing the model name you'll find in the Aider documentation: aider --modelName

kowalski-ptr avatar Sep 15 '24 16:09 kowalski-ptr

This looks like a duplicate of #1378, so I'm going to close it so discussion can happen there. Please let me know if you think it's actually a distinct issue.

paul-gauthier avatar Sep 20 '24 18:09 paul-gauthier