Issue with OpenAI API key while using it in Windows
Asked Answered
T

4

6

I have to fine-tune the OpenAI model on my custom dataset. I have created the dataset in jsonl format. I use the following commands on windows command line:

set OPENAI_API_KEY=<API key>

openai tools fine_tunes.prepare_data -f "train_data.jsonl"

The above commands run successfully and give me some suggestions for updating jsonl file. After this, I run the following command to fine-tune the 'curie' model.

openai api fine_tunes.create 'openai.api_key = <API key>' -t "train_data.jsonl" -m "curie"

But I am getting following issue:

←[91mError:←[0m Incorrect API key provided: "sk-iQJX*****************************************mux". You can find your API key at https://beta.openai.com. (HTTP status code: 401)

Can anybody help me out with this issue.

Trahan answered 16/6, 2022 at 10:16 Comment(0)
E
3

Use the following in the windows command prompt

openai --api-key <OPENAI_API_KEY> api fine_tunes.create -t "[yourfilelocationhere]" -m [modelhere] --suffix "[optional]"
Ethanethane answered 10/3, 2023 at 6:6 Comment(0)
U
0

This is a common issue with an earlier version of the openai's CLI. If you haven't already, make sure you upgrade to the most recent version by doing

pip install --upgrade openai

One possible workaround is to just use a python script to do what you would normally do in the CLI.

# To train a model:
import os
import openai
os.environ["OPENAI_API_KEY"] = "sk-iQJX*****************************************mux"
os.system("openai api fine_tunes.create -t train_data.jsonl -m curie")
Unicycle answered 15/8, 2022 at 16:21 Comment(0)
B
0

When assigning the API key in command line, dont use double quotes like:

API_KEY=ab-123123123123123231

This will solve the issue

Bautzen answered 12/2, 2023 at 17:29 Comment(0)
M
0

Hi this code will solve the problem. Make sure you set your environment variable properly before =OPENAI_API_KEY in this case:

Get-ExecutionPolicy
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
$headers = @{
"Authorization" = "Bearer $env:OPENAI_API_KEY"
"model" = "text-davinci-002"
}
Invoke-WebRequest -Uri "https://api.openai.com/v1/models" -Headers  $headers
Get-ChildItem Env:OPENAI_API_KEY

Best, Alexis

Magdalenmagdalena answered 9/3, 2023 at 4:43 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Quickie

© 2022 - 2024 — McMap. All rights reserved.