TheoKanning / openai-java

OpenAI Api Client in Java
MIT License
4.72k stars 1.18k forks source link

Exception in thread "main" com.theokanning.openai.OpenAiHttpException: Incorrect API key provided #432

Open pdeitel opened 8 months ago

pdeitel commented 8 months ago

Hi, I am trying a slightly modified version of your OpenAiService demo with an OpenAI API key that I just created and confirmed is loading correctly into my code. Any idea why I might be getting "Incorrect API key provided"? The main difference below is that I chose a more recent model and used my own prompt (which I did not include here). The same API key and prompt work for me in Python.

    String apiKey = properties.getProperty("OPENAI_API_KEY");
    System.out.println(apiKey);

    var service = new OpenAiService(apiKey);
    var completionRequest = CompletionRequest.builder()
        .model("gpt-3.5-turbo-1106")
        .prompt("My prompt here")
        .echo(true)
        .build();
    service.createCompletion(completionRequest)
           .getChoices()
           .forEach(System.out::println);    

Thanks for your help.

namankhurpia commented 8 months ago

hi @pdeitel

I m not sure if this repository is maintained anymore, feel free to check my repository https://github.com/namankhurpia/Easy-open-ai