Discourse-ai does not allow updating openai key

Searching for this issue, I only found two other posts and no solution.

Enable AI Helper and
GPT 3.5 is not configured despite having an API key

I’ve had OpenAI integration enabled on my self-hosted Discourse for a long time. A few days ago, I decided to use the project’s feature in OpenAI to keep better track on where my keys were used. So, I revoked my “only key” and started generating new projects and new keys in different places I use OpenAI. It works fine everywhere else, but after updating the ai openai api key under admin, the OpenAI integration in Discourse has been broken.

For instance, when trying to use the AI for reading a post, it results in an “error 500” dialog, and the Chrome console shows an error 500 at /discourse-ai/ai-helper/suggest:1. In the /var/www/discourse/log/production.log, I see a:

DiscourseAi::Completions::Endpoints::OpenAi: status: 401 - body: {
    "error": {
        "message": "Incorrect API key provided: sk-lg0jD***************************************GBv4. You can find your API key at https://platform.openai.com/account/api-keys.",
        "type": "invalid_request_error",
        "param": null,
        "code": "invalid_api_key"
    }
}

However, this is NOT the key I typed in the admin settings!!!
( it should say sk-proj***************************************tmDr )

I tried removing it, generating a new key, and setting it. I’ve updated Discourse to the latest version (3.3.0.beta5-dev) and restarted the server. I’ve also run ./launcher rebuild app, but nothing works, and it just keeps failing, using the wrong key.
How do i make Discourse use the right key ?

We are in the middle of moving AI credentials to a new dedicated screen under /admin/plugins/discourse-ai/ai-llms.

Can you update your API key there and try again?

1 Like

I should ask this on other topic, I reckon, but because your job isn’t finished yet…

I’m using another API on general settings because I thought I.E. AI helper uses it and other API for LLM.

Is that so and if yes will it stay so?

That was it !!! … thank you :slight_smile:

Sorry, for late reply, didn’t see it until now.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.