Skip to content

chatapi/v1/got endpoint returns 200 with empty answer, bad OpenAI key #90

@jay-m-dev

Description

@jay-m-dev

Describe the bug
If the OPEN_AI_API Key is wrong or invalid, the chatapi/v1/got endpoint returns http code 200, but the "answer" is empty.
The DEBUG logs will show an error:

2024-05-15 21:50:32,910 DEBUG openai._base_client Thread-1 (process_request_thread) : HTTP Request: POST https://api.openai.com/v1/chat/completions "401 Unauthorized"
2024-05-15 21:50:32,911 INFO backoff Thread-1 (process_request_thread) : Backing off chat(...) for 0.7s (openai.AuthenticationError: Error code: 401 - {'error': {'message': 'Incorrect API key provided: 03********************5e. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}})

But this error is not being relayed by the chatapi/v1/got endpoint. The Frontend needs this information to display a helpful message to users.

To Reproduce
Steps to reproduce the behavior:

  1. Set an invalid OPENAI_API_KEY in the .env file
  2. Launch the backend server: docker compose up execgpt
  3. Call the POST chatapi/v1/got endpoint with a body similar to:
{
  "chatInput": "what genes are associated with Droperidol?"
}

The response comes back with an empty "answer" key and the DEBUG log shows the error above

Expected behavior
This endpoint needs to relay messages from calls to the OpenAI API.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions