# Discourse-ai does not allow updating openai key

**URL:** https://meta.discourse.org/t/discourse-ai-does-not-allow-updating-openai-key/318975
**Category:** Support
**Tags:** ai
**Created:** [July 29, 2024, 9:47am UTC](https://meta.discourse.org/t/discourse-ai-does-not-allow-updating-openai-key/318975 "2024-07-29T09:47:08Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![kijag73607](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@kijag73607](https://meta.discourse.org/u/kijag73607)
#### Post date: [July 29, 2024, 9:47am UTC](https://meta.discourse.org/t/discourse-ai-does-not-allow-updating-openai-key/318975/1 "2024-07-29T09:47:08Z")

</div>

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

[Enable AI Helper](https://meta.discourse.org/t/enable-ai-helper/283943/6) and  
[GPT 3.5 is not configured despite having an API key](https://meta.discourse.org/t/gpt-3-5-is-not-configured-despite-having-an-api-key/307186/5)

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:

```plaintext
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 ?

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [July 29, 2024, 5:30pm UTC](https://meta.discourse.org/t/discourse-ai-does-not-allow-updating-openai-key/318975/2 "2024-07-29T17:30:21Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Jagster](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jagster/32/192154_2.png) [@Jagster](https://meta.discourse.org/u/Jagster)
#### Post date: [July 29, 2024, 6:01pm UTC](https://meta.discourse.org/t/discourse-ai-does-not-allow-updating-openai-key/318975/3 "2024-07-29T18:01:58Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![kijag73607](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@kijag73607](https://meta.discourse.org/u/kijag73607)
#### Post date: [July 30, 2024, 10:58am UTC](https://meta.discourse.org/t/discourse-ai-does-not-allow-updating-openai-key/318975/4 "2024-07-30T10:58:56Z")

</div>

> [@Falco](#):
>
> `/admin/plugins/discourse-ai/ai-llms`.

That was it !!! .. thank you 🙂

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

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [August 29, 2024, 10:59am UTC](https://meta.discourse.org/t/discourse-ai-does-not-allow-updating-openai-key/318975/5 "2024-08-29T10:59:52Z")

</div>

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