No API key provided in Command Prompt when trying to fine-tune

Hi all,

I’m having trouble submitting a fine-tune job with Windows Command prompt.

I have successfully installed python and the openai CLI, and I’ve successfully used the CLI Data Preparation Tool to turn my .csv file into a JSONL file (two, actually, since the tool recommended creating a training file and a validation file).

I have created an environment variable using the Windows GUI AND by running the command setx OPEN_API_KEY "<my_key>" in the Command Prompt, and I have confirmed that it has been set because it is echoed when I type echo %OPEN_API_KEY% in a new Command Prompt.

But when I try and submit my fine-tune job using the openai CLI, I get an error in the Command Prompt. My command is:

openai api fine_tunes.create -t "pennyTrainingData01_prepared_train.jsonl" -v "pennyTrainingData01_prepared_valid.jsonl" -m "ada"

and the error I get is

←[91mError:←[0m No API key provided. You can set your API key in code using 'openai.api_key = <API-KEY>', or you can set the environment variable OPENAI_API_KEY=<API-KEY>). If your API key is stored in a file, you can point the openai module at it with 'openai.api_key_path = <PATH>'. You can generate API keys in the OpenAI web interface. See https://onboard.openai.com for details, or email support@openai.com if you have any questions.

If I do what that error suggests, and run openai.api_key = <API-KEY>, I get the error 'openai.api_key' is not recognized as an internal or external command, operable program or batch file.

Can anyone help please?

Many thanks

1 Like

The problem could be that the variable name should be OPENAI_API_KEY and not OPEN_API_KEY.

The only thing I can contribute from my own experience is don’t bother setting the variable using the CLI, just create a script and run it from CLI. Although, as the other response indicated, you probably just have a simple naming mismatch issue.

I fiddled around with attempting to run both the data prep tool and a fine-tune job and settled on the below solution because it doesn’t really save any time setting an environment variable if you’re copying and pasting or running from a script anyway, not to mention if you’re using multiple API keys, etc…

To get it to run, use the syntax openai --api-key [yourvaluehere] api fine_tunes.create -t "[yourfilelocationhere]" -m [modelhere] --suffix "[optional]"

3 Likes

Thanks both, for your suggestions. @janekFa I see I spelled OPENAI_API_KEY incorrectly in my original post, but I think I had it correct when I was trying to set it in the command prompt. I tried again today anyway and got the same error with the correct spelling.

@IMTheJuggernautX your suggestion works, so I’m going to use that command from now on. And you’re right - I can use different keys easily this way. Thanks again, guys :o)

2 Likes

Thank you for this method! way simpler indeed!