Not able to replicate code mentioned in learning video and getting error: Did not find openai_api_key

Hi There,

I am trying to replicate the code which is taught in the course however i am getting following error

Did not find openai_api_key, please add an environment variable OPENAI_API_KEY which contains it, or pass openai_api_key as a named parameter. (type=value_error)

My code is as follows:

%pip install crewai==0.28.8 crewai_tools==0.1.6 langchain_community==0.0.29

Warning control

import warnings

from crewai import Agent, Task,Crew
import os
import openai

from dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv())
openai.api_key = os.getenv(‘$OPENAI_API_KEY’)
os.environ[“OPENAI_MODEL_NAME”] = ‘gpt-3.5-turbo’

planner = Agent(
role=“Content Planner”,
goal=“Plan engaging and factually accurate content on {topic}”,
backstory="You’re working on planning a blog article "
“about the topic: {topic}.”
"You collect information that helps the "
"audience learn something "
"and make informed decisions. "
"Your work is the basis for "
“the Content Writer to write an article on this topic.”,

hi @wanigaurav11

you need to get your openai api keys to run these codes successfully in your local environment.


Hi @wanigaurav11,

If you want to replicate the notebook code, you’d need two things:

  • a valid open ai API key
  • and a .env file. If you don’t know what they are, you can search online about it. For example, this video.