Fellows, I’m new using the OpenAI APIs. Currently, I’m getting the following error when I call it:
{
“error”: {
“message”: “You didn’t provide an API key. You need to provide your API key in an Authorization header using Bearer auth (i.e. Authorization: Bearer YOUR_KEY), or as the password field (with blank username) if you’re accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys.”,
“type”: “invalid_request_error”,
“param”: null,
“code”: null
}
}
This is my Angular service and how I’m calling the API:
export class OpenaiService {
private openai: OpenAIApi;
response: any;
configuration = new Configuration({
apiKey: “MY_API_KEY”,
});constructor() {
delete this.configuration.baseOptions.headers[‘User-Agent’];
this.openai = new OpenAIApi(this.configuration);
}async generateText(prompt: string):Promise<string | undefined>{
try {
const response = await this.openai.createCompletion({
model: “text-davinci-003”,
prompt: prompt,
max_tokens: 256
});
return response.data.choices[0].text;
} catch (error) {
return ‘’;
}
}
}
I used this code as a base to create it:
Building AI-Chatbot App With ChatGPT API In Angular (c-sharpcorner.com)
And yes, I have a key:
Any idea, what am I doing wrong? Thanks for your support.
P.S.:
Currently, I’m only writing my key like this:
apiKey: “xx-XXXADASDASLAKSLAS”
Something like this, I’m not sure if it should look different. I also tried adding the “organization” (personal), but the result was the same.