Skip to content

OPENAI_API_KEY is not set, skipping trace export #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lonngxiang opened this issue Mar 17, 2025 · 8 comments
Closed

OPENAI_API_KEY is not set, skipping trace export #190

lonngxiang opened this issue Mar 17, 2025 · 8 comments
Labels
bug Something isn't working

Comments

@lonngxiang
Copy link

from agents import Agent, Runner, AsyncOpenAI, OpenAIChatCompletionsModel, ModelSettings, handoff
from agents.extensions.handoff_prompt import prompt_with_handoff_instructions
import asyncio
import json
from pydantic import BaseModel, ValidationError

# 设置OpenAI客户端
openai_client = AsyncOpenAI(base_url="https://api.deepseek.com", api_key="sk-******")

Image

@lonngxiang lonngxiang added the bug Something isn't working label Mar 17, 2025
@WSQsGithub
Copy link

You need to export env var explicly in your terminal using export OPEN_API_KEY=sk-xxxx or use load_env() to do that.
It seems like agents-sdk doesn't have an interface like openai sdk.

@Salaudev
Copy link

Salaudev commented Mar 17, 2025

@lonngxiang

if you want to use an external LLM, you need to disable tracing

Image

@EnggQasim
Copy link
Contributor

from agents import set_tracing_disabled
set_tracing_disabled(disabled=True)

Just apply this code.

@jaijuneja
Copy link

jaijuneja commented Mar 21, 2025

Just wanted to add to this that I get the same error when using python_dotenv. I'm using OpenAI's models, not a 3P model.

I set OPENAI_API_KEY in my .env file and then have this at the top of my code:

from dotenv import load_dotenv

load_dotenv(override=True)

# Rest of code

This still raises the same warning message about skipping trace export.

I've found two ways to address this:

1 - set the environment variable explicitly in the terminal (export OPENAI_API_KEY=<key>)

2 -

import os
from dotenv import load_dotenv

load_dotenv(override=True)

OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")

if OPENAI_API_KEY:
    from agents import set_tracing_export_api_key
    set_tracing_export_api_key(OPENAI_API_KEY)

@rm-openai
Copy link
Collaborator

@jaijuneja good point. #289 should fix it.

@Leon-Sander
Copy link

@rm-openai is it already in the main branch? Still getting the error

@rm-openai
Copy link
Collaborator

Its merged but not released, the next version (v0.0.7) will have it

@sgb-io
Copy link

sgb-io commented Mar 29, 2025

This fix is available now -- https://github.com/openai/openai-agents-python/releases/tag/v0.0.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants