# API is too difficult for WIX beginner🥺 : \[error\] Incorrect API key provided

**URL:** <https://forum.wixstudio.com/t/api-is-too-difficult-for-wix-beginner-error-incorrect-api-key-provided/51256>\
**Category:** Ask the community\
**Tags:** design, code\
**Created:** [August 6, 2023, 1:52pm UTC](https://forum.wixstudio.com/t/api-is-too-difficult-for-wix-beginner-error-incorrect-api-key-provided/51256 "2023-08-06T13:52:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![NadiaHeo](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/nadiaheo/32/80609_2.png) [@NadiaHeo](https://forum.wixstudio.com/u/NadiaHeo)\
**Post date:** [August 6, 2023, 1:52pm UTC](https://forum.wixstudio.com/t/api-is-too-difficult-for-wix-beginner-error-incorrect-api-key-provided/51256/1 "2023-08-06T13:52:15Z")

</div>

I wanted to put a chat GPT chat window on the Wicks homepage, so I studied hard while watching the YouTuber’s video(The Wix Wiz - How To Create an AI Chatbot with OpenAI and WIX). However, there is an error when trying to run it. I even used a new API code just in case. What’s wrong with my code? 🥹

 ![IMG_3033](https://us1.discourse-cdn.com/wix/original/3X/6/c/6cb93586617f259a578a6faf20b9e818f2ef7557.jpeg)  
(sorry… i can’t put over 2 pictures because i’m new user… ☹ So)

---

<div class="post-metadata">

**Author:** ![thomasj](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/thomasj/32/30791_2.png) [@thomasj](https://forum.wixstudio.com/u/thomasj)\
**Post date:** [August 7, 2023, 4:27pm UTC](https://forum.wixstudio.com/t/api-is-too-difficult-for-wix-beginner-error-incorrect-api-key-provided/51256/2 "2023-08-07T16:27:41Z")

</div>

Hi,

Your code looks mostly correct! I noticed that you used the [Wix-Secrets-Backend](https://www.wix.com/velo/reference/wix-secrets-backend) API which is a great way to make sure your authorization key stays secure.

The issue I see is that the authorization header uses single quotes (') instead of backquotes (`) which is required for template literals in JavaScript. Additionally, you have to make sure your API Key is stored in a variable named “apiKey” instead of “apiKei” based on your authorization header.

The following modifications should fix your code:

**Line 6**

```javascript
const apiKey = await getSecret("OPENAI-API-KEY");

```

**Line 17**

```javascript
'Authorization': `Bearer ${apiKey}`

```

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [December 29, 2023, 12:55am UTC](https://forum.wixstudio.com/t/api-is-too-difficult-for-wix-beginner-error-incorrect-api-key-provided/51256/3 "2023-12-29T00:55:15Z")

</div>

1. Instead of passing your API, key from backend (where it **WAS** secure) to frontend, do both processes on —\> BACKEND → a) FETCH-REQUEST including b) SECRETS-REQUEST and send only the RESULTS you got from CHAT-GPT back to FRONT-END.

2. Your structure should look like…  
a) backend-code-1 jsw-module —\> openAi.jsw  
b) backend-code-2 jsw-module → secrets.jsw

3. Process-flow…

Step-1:  
Calling the fetch-request on FRONT-END to start the fetch-process on BACKEND.

Step-2: Inside of your fetch-request, you first call (asynchronous) → wix-secrets from secrets.jsw (which is also on backend) to get your API-Key first.

Step-3: You got your API-KEy from SECRETS.JSW → your fetch-process continues and gets all data from OPEN-AI.

Step-4: You return the found OPEN-AI-RESULTS back to → FRONT-END.

**ABSOLUTELY SAFE PROCESS, WITHOUT ANY RISKS TO EXPLOITE YOUR SECRETS (API-KEYS) on —\> FRONTEND !!!** —\> SAFE-PROCESS.

If you need a complete Open-Ai CHAT-GPT-Manager → [velo-ninja@outlook.com](mailto:velo-ninja@outlook.com)

Fully integrated into your Wix-Website with lot of features and functions.
