How I had to access OPEN AI KEY in Windows

I was never able to use utils to get the OPENAI Key to work. Instead I did it this way. If you are having similar issues try this. And make sure you have an API key in Environment System Variables.

using openai and os then just use whatever models you want there. Now to get Anthropic working…

import os

import openai
warnings.filterwarnings(‘ignore’)

from crewai import Agent, Task, Crew

import os
import openai

openai.api_key = os.getenv(“OPENAI_API_KEY”)
#os.environ[“OPENAI_MODEL_NAME”] = ‘gpt-4o’
os.environ[“OPENAI_MODEL_NAME”] = ‘gpt-3.5-turbo-0125’

1 Like

I used the Enviroment System Variable for a while, but am pleased to report that i now got it working by placing a .env file and the utils.py file in the same directory as the lesson. The .env file has both my openai and serper keys.
Some key lessons I learnt;
the filename of the .env file does not have any name before the ‘.’
the environment variables are case sensitive.

2 Likes