# Configure API Keys for OpenAI

**URL:** https://meta.discourse.org/t/configure-api-keys-for-openai/280783
**Category:** Integrations
**Tags:** how-to, ai
**Created:** [October 2, 2023, 6:04pm UTC](https://meta.discourse.org/t/configure-api-keys-for-openai/280783 "2023-10-02T18:04:22Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![Discourse](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/discourse/32/148734_2.png) [@Discourse](https://meta.discourse.org/u/Discourse)
#### Post date: [October 2, 2023, 6:04pm UTC](https://meta.discourse.org/t/configure-api-keys-for-openai/280783/1 "2023-10-02T18:04:23Z")

</div>

> 🔖 This guide explains how to configure API keys for OpenAI to enable Discourse AI features that require 3rd party LLM keys.
> 
> 🙋 Required user level: Administrator

In this example, we are using OpenAI to generate the keys.

> **Note** : You will likely need a paid plan and have to pay per usage. See here for up-to-date[details and pricing](https://openai.com/product).

Platforms will always change so this guide may not reflect 100% process.

> ℹ In order to use certain AI modules, users must have an API Key from a 3rd party provider such as OpenAI (ChatGPT), Anthropic (Claude), Google (Gemini), etc.
> 
> Please check each AI module to see which 3rd party providers can be used for it.

## Generate the API key

1. Log in to Open AI. An API key can be obtained here [OpenAI Platform](https://platform.openai.com/account/api-keys)
2. Generate the API Key
3. Once the key is generated, store it in a safe and secure place and copy it

## Using API key for Discourse AI

Discourse AI uses a **Secrets** system to manage API keys. Instead of pasting keys directly into individual LLM configurations, you create a named secret and then reference it from one or more LLMs.

### Create a Secret (optional can be done inline)

1. Go to `Admin` → `Plugins` → `AI` → `Secrets` tab
2. Click **New Secret**
3. Enter a name for the secret (e.g. “OpenAI API Key”)
4. Paste your API key into the **Secret** field
5. Save the secret

### Configure an LLM

1. Go to `Admin` → `Plugins` → `AI` → `LLMs` tab
2. Select a pre-configured model template (e.g. an OpenAI model) and click its **Configure** button, or click **Edit** on an already configured LLM
3. In the **API Key** field, select the secret you created from the dropdown. You can also create a new secret inline by clicking the **+** button next to the dropdown.
4. Save the LLM

> Last edited by @sam 2026-03-23T21:53:37Z
> 
> > **Check document**
> >
> > Perform check on document:

---

<div class="post-metadata">

### Author: ![silvacarl](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@silvacarl](https://meta.discourse.org/u/silvacarl)
#### Post date: [February 22, 2024, 11:38pm UTC](https://meta.discourse.org/t/configure-api-keys-for-openai/280783/4 "2024-02-22T23:38:59Z")

</div>

no matter what we do, it always says openai gpt-4 not configured.

what am i missing?

---

<div class="post-metadata">

### Author: ![Saif](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/saif/32/318253_2.png) [@Saif](https://meta.discourse.org/u/Saif)
#### Post date: [February 23, 2024, 3:47pm UTC](https://meta.discourse.org/t/configure-api-keys-for-openai/280783/5 "2024-02-23T15:47:33Z")

</div>

Where is this popping up for you and I’m assuming you have inputted in the OpenAI key? where there any other settings you have changed? have you tried a refresh on the browser post inputting in the key - does that help?

---

<div class="post-metadata">

### Author: ![silvacarl](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@silvacarl](https://meta.discourse.org/u/silvacarl)
#### Post date: [February 23, 2024, 4:11pm UTC](https://meta.discourse.org/t/configure-api-keys-for-openai/280783/6 "2024-02-23T16:11:45Z")

</div>

we have three valid openai keys we use for other things so i know they work.

no matter what we do, this is an example of the rror we get:

 ![image](https://global.discourse-cdn.com/meta/original/4X/7/a/7/7a709fa390a03c4ec87ab98008de8f9544b5bc74.png)

---

<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: [February 23, 2024, 4:14pm UTC](https://meta.discourse.org/t/configure-api-keys-for-openai/280783/7 "2024-02-23T16:14:14Z")

</div>

What’s the output of running

```plaintext
curl https://api.openai.com/v1/chat/completions -H "Content-Type: application/json" -H "Authorization: Bearer $OPENAI_API_KEY" -d '{
    "model": "gpt-4",
    "messages": [
      {
        "role": "system",
        "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair."
      },
      {
        "role": "user",
        "content": "Compose a poem that explains the concept of recursion in programming."
      }
    ]
  }'

```

in your Discourse server? Don’t forget to place your API key on the command.

---

<div class="post-metadata">

### Author: ![silvacarl](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@silvacarl](https://meta.discourse.org/u/silvacarl)
#### Post date: [February 23, 2024, 4:17pm UTC](https://meta.discourse.org/t/configure-api-keys-for-openai/280783/8 "2024-02-23T16:17:24Z")

</div>

will login to our server and check this out.

---

<div class="post-metadata">

### Author: ![silvacarl](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@silvacarl](https://meta.discourse.org/u/silvacarl)
#### Post date: [February 23, 2024, 4:50pm UTC](https://meta.discourse.org/t/configure-api-keys-for-openai/280783/9 "2024-02-23T16:50:46Z")

</div>

{  
“id”: “chatcmpl-8vT2UYe6i5m9EO0N4KdG6klcO4dVJ”,  
“object”: “chat.completion”,  
“created”: 1708707014,  
“model”: “gpt-4-0613”,  
“choices”: [  
{  
“index”: 0,  
“message”: {  
“role”: “assistant”,  
“content”: “A tale within a tale untold,\nAn echo of a mirrored call,\nSuch is used in software’s sprawl,\nA concept called recursion, all.\n\nImagine a box within a box,\nEach pregnant with the one before,\nEach step to the origin restores,\nInfinite layers, like paradox.\n\nLike Russian dolls, a dream within,\nEach smaller than the one outside,\nYet hiding life within they reside,\nA patterned approach to chaos, therein.\n\nFrom problem to sub-problem, there,\nEach atom is an image proud,\nOf the larger form that’s to be found,\nTwisted whirls of logic’s flare.\n\nConjuring functions that call their own,\nIt tumbles down, a spiral vast,\nBut in the base case, it rests at last,\nThe seeds of recursion thus are sown.\n\nIn every loop’s heart you’ll find,\nA recursion lightly spinning, twined.\nWith every thread of question lined,\nIt folds back on itself, yet unconfined.\n\nBut dear programmers, mind your step,\nInfinite loops are hell’s gateway,\nKeep thy base case in the array,\nThe art of recursion, now adept.\n\nRepeating tasks, yet ever smaller,\nWith each pass, yet closer to end,\nDecomposing problems, our trusted friend,\nRecursion in code, the infinite caller.”  
},  
“logprobs”: null,  
“finish\_reason”: “stop”  
}  
],  
“usage”: {  
“prompt\_tokens”: 39,  
“completion\_tokens”: 265,  
“total\_tokens”: 304  
},  
“system\_fingerprint”: null  
}

---

<div class="post-metadata">

### Author: ![silvacarl](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@silvacarl](https://meta.discourse.org/u/silvacarl)
#### Post date: [February 23, 2024, 4:55pm UTC](https://meta.discourse.org/t/configure-api-keys-for-openai/280783/10 "2024-02-23T16:55:23Z")

</div>

claude-v2 does not return an error.

---

<div class="post-metadata">

### Author: ![Aaron\_Walsh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aaron_walsh/32/312661_2.png) [@Aaron\_Walsh](https://meta.discourse.org/u/Aaron_Walsh)
#### Post date: [August 3, 2024, 9:26am UTC](https://meta.discourse.org/t/configure-api-keys-for-openai/280783/11 "2024-08-03T09:26:17Z")

</div>

![Screenshot_20240803_102316_Chrome](https://global.discourse-cdn.com/meta/original/4X/c/9/0/c90fd82d3f7867df6ca8d7e118f974dada5fbba5.jpeg)

I’ve been prompted to use another model as they are moving away from GPT-3.5 Turbo from OpenAI. However, I’m getting this error message when I “Run Test,” and for the life of me, I can’t remember if I’m missing anything.

---

<div class="post-metadata">

### Author: ![Aaron\_Walsh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aaron_walsh/32/312661_2.png) [@Aaron\_Walsh](https://meta.discourse.org/u/Aaron_Walsh)
#### Post date: [August 3, 2024, 5:29pm UTC](https://meta.discourse.org/t/configure-api-keys-for-openai/280783/14 "2024-08-03T17:29:11Z")

</div>

This is now fixed. I removed all of the LLMs and restarted again. Most of the settings took a while to start again, especially having to undo them and then enable them again. But after a few attempts, it is all up and running using 4 Mini.

---

<div class="post-metadata">

### Author: ![satonotdead](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/satonotdead/32/447830_2.png) [@satonotdead](https://meta.discourse.org/u/satonotdead)
#### Post date: [September 22, 2024, 3:43pm UTC](https://meta.discourse.org/t/configure-api-keys-for-openai/280783/15 "2024-09-22T15:43:04Z")

</div>

It’s possible to use third-party OpenAI API services like `https://api.aimlapi.com/v1/embeddings`?

I get 500 errors when trying.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [November 11, 2024, 7:04am UTC](https://meta.discourse.org/t/configure-api-keys-for-openai/280783/17 "2024-11-11T07:04:27Z")

</div>

Did you debug using:

> [@Configure API Keys for OpenAI](https://meta.discourse.org/t/configure-api-keys-for-openai/280783/7):
>
> What’s the output of running curl https://api.openai.com/v1/chat/completions -H "Content-Type: application/json" -H "Authorization: Bearer $OPENAI\_API\_KEY" -d '{ "model": "gpt-4", "messages": [ { "role": "system", "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair." }, { "role": "user", "content": "Compose a poem that explains the concept of recursion in programming." …
