Skip to content

Docs: Add guidance for using .env and load_dotenv() with Python #1634

@Muhammad-Talha33

Description

@Muhammad-Talha33

Problem
The current "Hello World" example in the docs assumes that the OPENAI_API_KEY
is already available in the system environment variables.

However, many Python developers store keys in a .env file.
If they don't call load_dotenv(), they run into the following error:

openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable

Suggested improvement
Add a note in the docs for Python users that if you are using a .env file,
you need to load it with:

from dotenv import load_dotenv
load_dotenv()

before creating the agent or runner.

Benefit
This will save beginners from confusion and make the SDK easier to adopt
for Python users following common .env practices.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions