I've got three different apps I've been building using openAI API keys. none of them are working now, and they all worked before. the Keys are not being honored for some reason, coming back as 'undefined'. has there been a change in format or something? I still have a balance remaining so I don't think that's the problem. this is incredibly frustrating, I've wasted three entire days on this issue and I'm about to poke my eyes out. someone please help
#API keys no longer working
17 messages · Page 1 of 1 (latest)
server@1.0.0 start
node server.js
OpenAIApi {
basePath: 'https://api.openai.com/v1',
axios: <ref *1> [Function: wrap] {
request: [Function: wrap],
getUri: [Function: wrap],
delete: [Function: wrap],
get: [Function: wrap],
head: [Function: wrap],
options: [Function: wrap],
post: [Function: wrap],
put: [Function: wrap],
patch: [Function: wrap],
defaults: {
transitional: [Object],
adapter: [Function: httpAdapter],
transformRequest: [Array],
transformResponse: [Array],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
validateStatus: [Function: validateStatus],
headers: [Object]
},
interceptors: { request: [InterceptorManager], response: [InterceptorManager] },
create: [Function: create],
Axios: [Function: Axios],
Cancel: [Function: Cancel],
CancelToken: [Function: CancelToken] { source: [Function: source] },
isCancel: [Function: isCancel],
VERSION: '0.26.1',
all: [Function: all],
spread: [Function: spread],
isAxiosError: [Function: isAxiosError],
default: [Circular *1]
},
configuration: Configuration {
apiKey: undefined,
organization: undefined,
username: undefined,
password: undefined,
accessToken: undefined,
basePath: undefined,
baseOptions: { headers: [Object] },
formDataCtor: [Function: FormData] {
LINE_BREAK: '\r\n',
DEFAULT_CONTENT_TYPE: 'application/octet-stream'
}
}
}
Server is running on port http://127.0.0.1:5000
what I just posted is a console log of an instance of my configuration.
checking the api.openai.com/v1 url reveals the following: {
"error": {
"message": "Invalid URL (GET /v1)",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
but this was working fine before. could the /v1 be the issue here?
You're just sending requests to a site named /v1/completions. Try changing that to the full https://api.openai.com/v1/completions.
thanks i'll check that out and report back
actually where would I even put that url? nowhere in my code does '/v1/completions' appear. that's set by openai. all I've got is " '/' " as in: app.post('/', async etc...
Here's my server.js code:
import * as dotenv from 'dotenv';
import cors from 'cors';
import { Configuration, OpenAIApi } from 'openai';
dotenv.config();
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
console.log(openai)
const app = express();
app.use(cors());
app.use(express.json());
app.get('/', async (req, res) => {
res.status(200).send({
message: 'Hello from CodeX',
})
});
app.post('/', async (req, res) => {
try {
const prompt = req.body.prompt;
const response = await openai.createCompletion({
model: "text-davinci-003",
prompt:`${prompt}`,
temperature: 0, //temperature determines level of risk the AI can take in terms of giving information it already knows or searching for new information
max_tokens: 3000, //max number of characters to generate in a complete answer
top_p: 1,
frequency_penalty: 0.5, //determines how repetitive AI can be in its answers
presence_penalty: 0, //determines how much AI can talk about topics that are not in the prompt
});
res.status(200).send({
bot: response.data.choices[0].text
})
} catch (error) {
console.log(error);
res.status(500).send({ error })
}
})
app.listen(5000, () => console.log('Server is running on port http://127.0.0.1:5000'));
and here's my client/script.js file:
import bot from './assets/bot.svg';
import user from './assets/user.svg';
import * as dotenv from 'dotenv';
dotenv.config();
const form = document.querySelector('form');
const chat_container = document.querySelector('#chat_container');
let loadInterval;
function loader(element) {
element.textContent = ''
loadInterval = setInterval(() => {
element.textContent += '.';
if (element.textContent === '....') {
element.textContent = '';
}
},300)
}
function typeText(element, text) {
let index = 0
let interval = setInterval(() => {
if (index < text.length) {
element.innerHTML += text.charAt(index)
index++
} else {
clearInterval(interval)
}
}, 20)
}
function generateUniqueId() {
const timestamp = Date.now();
const randomNumber = Math.random();
const hexadecimalString = randomNumber.toString(16);
return `id-${timestamp}-${hexadecimalString}`
}
function chatStripe (isAi, value, uniqueId) {
return (
`
<div class="wrapper ${isAi && 'ai'}">
<div class="chat">
<div class="profile">
<img
src= ${isAi ? bot : user}
alt="${isAi ? 'bot' : 'user'}"
/>
</div>
<div class="message" id=${uniqueId}>${value}</div>
</div>
</div>
`
)
}
const handleSubmit = async (e) => {
e.preventDefault();
const data = new FormData(form);
//user's chatstripe
chat_container.innerHTML += chatStripe(false, data.get('prompt'));
form.reset();
//bot's chatstripe
const uniqueId = generateUniqueId();
chat_container.innerHTML += chatStripe(true, " ", uniqueId);
chat_container.scrollTop = chat_container.scrollHeight;
const messageDiv = document.getElementById(uniqueId);
loader(messageDiv)
const response = await fetch('http://127.0.0.1:5000/ ', {
method: 'POST',
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer process.env.OPENAI_API_KEY",
"Organization": "org-XqVQFxoLFDmlHSQwruBTaIy8",
"Access-Control-Allow-Origin":"*"
},
body: JSON.stringify({
prompt: data.get('prompt')
})
})
clearInterval(loadInterval)
messageDiv.innerHTML = " "
if (response.ok) {
const data = await response.json();
const parsedData = data.bot.trim()
typeText(messageDiv, parsedData)
} else {
const err = await response.text()
messageDiv.innerHTML = "Something went wrong"
alert(err)
}
}
form.addEventListener('submit', handleSubmit);
form.addEventListener('keyup', (e) => {
if (e.keyCode === 13) {
handleSubmit(e);
}
})
Oh. I don't have any other ideas, sorry.
thanks anyways.
why isn't there anywhere to create a ticket and get some direct help? or is there?
I'm not sure
how do i get the attention of an admin or someone who is actually OpenAI support?
Did you ask ChatGPT to debug the code and explain the error message?
yeah to no avail the problem isn't in my code, the problem is with the API