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

Support for Handling error e.g. HTTP 429 #31

Closed
adewandaru opened this issue Jun 25, 2021 · 3 comments
Closed

Support for Handling error e.g. HTTP 429 #31

adewandaru opened this issue Jun 25, 2021 · 3 comments

Comments

@adewandaru
Copy link

Hi.. thanks for the nice library!

I have a small question.. Is there a good way to handle error returned by openai api response?
For example, when you're running out of Quota, it will reply with HTTP 429 response.

Thanks.

@njerschow
Copy link
Owner

Here's how I do it:

try {
    await openai.complete({
        engine: 'davinci',
        prompt: 'this is a test',
        maxTokens: 5,
        temperature: 0.9,
        topP: 1,
        presencePenalty: 0,
        frequencyPenalty: 0,
        bestOf: 1,
        n: 1,
        stream: false,
        stop: ['\n', "testing"]
    });
 } catch(e) {
     console.error("[ERROR] OpenAI responded with status: " + e.response.status)
     if (e.response.status === 429) {
         console.log("OpenAI Quota exceeded")
         //handle this case
     }
 }

disclaimer: This is untested code

@adewandaru
Copy link
Author

Thanks much for the pointer.

@AlexanderKozhevin
Copy link

It's strange but I'm gettting this error frequently.
Taking into account that I have enough quota limit

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

3 participants