Google Colab Fine-Tuning Error:

I’m trying to train using Google Colab. Despite establishing the API, I am struck with the following error: " Error: No API key provided. (HINT: set your API key in code using "openai.api_key = <API-KEY>", or you can set the environment variable OPENAI_API_KEY=<API-KEY>). You can generate API keys in the OpenAI web interface. See []( for details, or email []( if you have any questions."

My code is as follows:

!pip install --upgrade openai
import openai
!export OPENAI_API_KEY="(actual API)"
!openai api fine_tunes.create -t "/content/Untitled spreadsheet (2)_prepared.jsonl" -m "ada"

1 Like

As far as I can tell, exporting a bash variable using !export VAR doesn’t work in colab (e.g. try

!export VAR="hello"
!echo $VAR


But you can set the env var with

os.environ["OPENAI_API_KEY"] = api_key

Thank you. That works!

This saved me, thank you.