Skip to content

[non-fatal] Tracing client error 401, Incorrect API key provided #535

Closed
@liudonghua123

Description

@liudonghua123

Please read this first

  • Have you read the custom model provider docs, including the 'Common issues' section? Model provider docs
  • Have you searched for related issues? Others may have faced similar issues.

Describe the question

I just use another model for the example code.

# openai_agents_demo.py
import os
from agents import Agent, OpenAIChatCompletionsModel, Runner

from dotenv import load_dotenv
import httpx
from openai import AsyncOpenAI, OpenAI

load_dotenv()

asyncClient = AsyncOpenAI(
    api_key=os.getenv("OPENAI_API_KEY"),
    base_url=os.getenv("OPENAI_BASE_URL"),
    http_client=httpx.AsyncClient(verify=False),
)
syncClient = OpenAI(
    api_key=os.getenv("OPENAI_API_KEY"),
    base_url=os.getenv("OPENAI_BASE_URL"),
    http_client=httpx.Client(verify=False),
)

agent = Agent(
    name="Assistant",
    instructions="You are a helpful assistant",
    model=OpenAIChatCompletionsModel(
        model=os.getenv("OPENAI_MODEL_NAME"), openai_client=asyncClient
    ),
)

result = Runner.run_sync(agent, "Write a bubble sort algorithm in python code")
print(result.final_output)

# Code within the code,
# Functions calling themselves,
# Infinite loop's dance.
> python openai_agents_demo.py
[non-fatal] Tracing client error 401: {
  "error": {
    "message": "Incorrect API key provided: 5bed90d6************************48a5. You can find your API key at https://platform.openai.com/account/api-keys.",
    "type": "invalid_request_error",
    "param": null,
    "code": "invalid_api_key"
  }
}


Here's an implementation of the bubble sort algorithm in Python with optimizations to improve efficiency:

```python
def bubble_sort(arr):
    n = len(arr)
    for i in range(n - 1):
        swapped = False
        for j in range(n - 1 - i):
            if arr[j] > arr[j + 1]:
                arr[j], arr[j + 1] = arr[j + 1], arr[j]
                swapped = True
        if not swapped:
            break
    return arr
```

**Explanation:**

1. **Outer Loop (i):** Iterates through each element in the list (n-1 times, as after n-1 passes, the list is guaranteed to be sorted).

2. **Inner Loop (j):** Compares adjacent elements. The range decreases by `i` each iteration because the largest `i` elements have already bubbled to their correct positions.

3. **Swapped Flag:** Checks if any swaps occurred during the pass. If no swaps are made, the list is already sorted, and the algorithm exits early.

**Example Usage:**

```python
my_list = [64, 34, 25, 12, 22, 11, 90]
print(bubble_sort(my_list))  # Output: [11, 12, 22, 25, 34, 64, 90]
```

This implementation has a time complexity of O(n²) in the worst case, but the early exit optimization brings it closer to O(n) for nearly-sorted lists.
[non-fatal] Tracing client error 401: {
  "error": {
    "message": "Incorrect API key provided: 5bed90d6************************48a5. You can find your API key at https://platform.openai.com/account/api-keys.",
    "type": "invalid_request_error",
    "param": null,
    "code": "invalid_api_key"
  }
}
> 

Debug information

  • Agents SDK version: (e.g. v0.0.3) openai-1.75.0 openai-agents-0.0.11
  • Python version (e.g. Python 3.10) 3.12

Repro steps

python openai_agents_demo.py

Expected behavior

No such errors like the following.

[non-fatal] Tracing client error 401: {
  "error": {
    "message": "Incorrect API key provided: 5bed90d6************************48a5. You can find your API key at https://platform.openai.com/account/api-keys.",
    "type": "invalid_request_error",
    "param": null,
    "code": "invalid_api_key"
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions