Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why can't my API be called? I'm pretty sure there's no problem with the API #32

Open
JasonKid-maker opened this issue Aug 5, 2024 · 7 comments

Comments

@JasonKid-maker
Copy link

微信图片_20240805183836
Why can't my API be called? I'm pretty sure there's no problem with the API

@arksenu
Copy link

arksenu commented Aug 6, 2024

You are probably passing a body that isn't a valid JSON with a request that probably speccifies 'application/json'.

@space-dweeb
Copy link

I'm having this same issue, even with no JSON files attached to the assistant; I'm also getting this error, even though I haven't touched the code other than the .env file:

image

@The-Heyman
Copy link

It might be that your API key doesn't have the right permissions as I got the similar error and it turned out from the logs from the terminal that I missed some permissions. Bad error messaging on the UI I would say from whoever wrote this code but here is the error log:

error: { message: "You have insufficient permissions for this operation. Missing scopes: api.assistants.read. Check that you have the correct role in your organization (Reader, Writer, Owner) and project (Viewer, Member, Owner), and if you're using a restricted API key, that it has the necessary scopes.", type: 'invalid_request_error', param: null, code: 'missing_scope' }, code: 'missing_scope', param: null, type: 'invalid_request_error' }

@natalie230
Copy link

Hi I also got the errors above but saw that there is invalid api error when I look at the terminal. It seems that the problem might be that there is no code to read the api key in the .env file and to call the api?

I tried inserting the api key under the openai.ts file directly and it works without errors above which i experienced earlier

original:

import OpenAI from "openai";
export const openai = new OpenAI();

changed:

import OpenAI from "openai";
export const openai = new OpenAI({
    apiKey: "sk-...."
});

However, I would like to use the .env file(where i saved the api key) so that i do not paste the api key directly. I did this:

import dotenv from "dotenv";
dotenv.config();
import OpenAI from "openai";

export const openai = new OpenAI({
    apiKey: process.env.OPENAI_API_KEY
});

But it still returns the invalid api error and does not read the key? Pls send help :')

@The-Heyman
Copy link

@natalie230 Did you rename the .env.example file to .env?
Ensure you have done that, add the API key and the assistant Id and just use:
import OpenAI from "openai"; export const openai = new OpenAI();
It should work

@srivatsavsurya
Copy link

export OPENAI_API_KEY="your_api_key"

@AlmondMilk4242
Copy link

can we please close issue this issue as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants