openai-java icon indicating copy to clipboard operation
openai-java copied to clipboard

Can't create completion giving null error HTTP 429

Open Tc554 opened this issue 2 years ago • 7 comments

Already checked the HTTP 429 issue but still error

Code:

OpenAiService service = new OpenAiService("token here");
CompletionRequest completionRequest = CompletionRequest.builder()
                .prompt(scanner.next())
                .model("text-davinci-003")
                .echo(true)
                .temperature(0.7)
                .maxTokens(96)
                .topP(1.0)
                .frequencyPenalty(0.0)
                .presencePenalty(0.3)
                .build();
CompletionResult result = service.createCompletion(completionRequest); // <---- null here

Tc554 avatar Feb 04 '23 10:02 Tc554

Exception in thread "main" retrofit2.adapter.rxjava2.HttpException: HTTP 429 at retrofit2.adapter.rxjava2.BodyObservable$BodyObserver.onNext(BodyObservable.java:57) at retrofit2.adapter.rxjava2.BodyObservable$BodyObserver.onNext(BodyObservable.java:38) at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:48) at io.reactivex.Observable.subscribe(Observable.java:10151) at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:35) at io.reactivex.Observable.subscribe(Observable.java:10151) at io.reactivex.internal.operators.observable.ObservableSingleSingle.subscribeActual(ObservableSingleSingle.java:35) at io.reactivex.Single.subscribe(Single.java:2517) at io.reactivex.Single.blockingGet(Single.java:2001) at com.theokanning.openai.OpenAiService.createCompletion(OpenAiService.java:116) at me.TastyCake.Main.main(Main.java:26)

Process finished with exit code 1

Tc554 avatar Feb 04 '23 10:02 Tc554

(Sorry saw you already checked code) HTTP 429 is too many requests. I think basic accounts get 10 requests per minute, but with the popularity of the service, it might be handling it in aggregate.

https://status.openai.com/

Make sure that your license can handle the number of requests, i.e. credit card for overages, using the right license key, etc. Also make sure your code can handle non-200 HTTP result codes.

			if ((response.statusCode() / 100) != 2) {
				System.out.println("response code: " + response.statusCode());
				System.out.println("response body: " + response.body());
			} 

CompletionResult uses annotation lombok @Data Make sure that the latest lombok.jar is correctly configured and on path. I used 1.18.24

Finally, for your scanner.next(), make sure the prompt is properly quoted or even clean it from other characters. Hope any of this helps.

cryptoapebot avatar Feb 04 '23 15:02 cryptoapebot

I copied the @Data tag from the CompletionResult code, but now I'm wondering if the capital T is screwing up the annotation. Nope, it's correct in code. Github comments just though I was referencing a diff account of user "DaTa" by using the at sign.

cryptoapebot avatar Feb 04 '23 15:02 cryptoapebot

thank you for responding I do see some outusage image but how can I fix it I just want to generate one response

OpenAiService service = new OpenAiService("token here");
CompletionRequest completionRequest = CompletionRequest.builder()
                .prompt(scanner.next())
                .model("text-davinci-003")
                .echo(true)
                .temperature(0.7)
                .maxTokens(96)
                .topP(1.0)
                .frequencyPenalty(0.0)
                .presencePenalty(0.3)
                .build();
CompletionResult result = service.createCompletion(completionRequest); // <---- null here

this code is on the main method running just one time

Tc554 avatar Feb 04 '23 19:02 Tc554

I tried recreating your issue, but I can't, so that means maybe it's an environment issue? Try taking .echo out. Only advice I have is to just compare a curl command with the exact same parameters/prompt and see what it says.

cryptoapebot avatar Feb 04 '23 19:02 cryptoapebot

I got the exact same issue. I don't think it has to do with the environment as the token is only a string value that can be assigned directly to OpenAiService.

I tried the following (also with echo() ):

CompletionRequest completionRequest = CompletionRequest.builder()
                .model("ada") //Cheapest option
                .prompt("Somebody once told me the world is gonna roll me")
                .build();

Magnus1987 avatar Feb 06 '23 22:02 Magnus1987

same issue here, it doesn't work, usage shows 0%

Screen Shot 2023-02-09 at 1 35 50 PM Screen Shot 2023-02-09 at 1 24 23 PM

AlexUrrutia avatar Feb 09 '23 18:02 AlexUrrutia

I'm seeing the same issue with a brand new token on a brand new account, using the smashmouth sample code. Usage on openai is showing 0 requests, and status page says all systems are operational.

I see that this issue is closed. What is the resolution? I'm using v0.12.0. Thanks.

martylamb avatar Apr 16 '23 12:04 martylamb

Nevermind, sorry for the noise. This is clearly not an issue with the library and not your problem to solve.

But for anyone else who stumbles on this thread, adding a credit card to my new account ended up resolving the issue despite the fact that the free account provides $18 in credit. This seems to have bitten quite a few folks.

martylamb avatar Apr 16 '23 12:04 martylamb

你需要开通支付账户

chenkangck50 avatar Jul 06 '23 06:07 chenkangck50

I added a credit card to my new account, but still met the same error. Is there any other solution?

peri103 avatar Jul 18 '23 08:07 peri103

I have the same issue; newly created account says my phone number is already in use and I cannot use credits (I didn't register there before!), so I was forced to add $10. Now, OpenAiApiExample created downloadable "dancing with frog" image, I can see that I was charged $0.02 for that, but console still shows error 429.

I am using v.0.18.2

[UPDATE]

When I run this example 2nd time, after about 10 minutes, I don't have any issue. So, I assume "billing setup" takes some time at their site.

$0.04 already ;)

FuadEfendi avatar May 04 '24 13:05 FuadEfendi