Skip to content

Typo: Duplicate header name in authentication error message #3962

Description

@dajiaohuang

name: Typo bug report
about: Typo in authentication error message (duplicate "Authorization")
title: 'Typo: Duplicate header name in authentication error message'
labels: bug, documentation
assignees: ''

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • This is an issue with the Python library

Describe the bug

There is a copy-paste typo in the _validate_headers error message in both the sync and async clients. The message says:

"Authorization or Authorization headers to be explicitly omitted"

But it should mention both supported auth headers: Authorization (Bearer tokens) and api-key (API key auth).

Looking at the X.509 auth code in src/openai/auth/_x509.py:66, the SDK actually checks for api-key, x-api-key, and proxy-authorization headers as well.

Locations

File: src/openai/_client.py

  1. Sync client, line 664:
raise TypeError(
    '"Could not resolve authentication method. Expected either api_key or admin_api_key to be set. Or for one of the `Authorization` or `Authorization` headers to be explicitly omitted"'
)
  1. Async client, line 1428:
raise TypeError(
    '"Could not resolve authentication method. Expected either api_key or admin_api_key to be set. Or for one of the `Authorization` or `Authorization` headers to be explicitly omitted"'
)

Proposed fix

Change the error message to correctly list the auth headers:

raise TypeError(
    "Could not resolve authentication method. Expected either api_key or admin_api_key to be set. Or for one of the `Authorization` or `api-key` headers to be explicitly omitted"
)

(Also note the original message has extra leading/trailing double quotes inside the string which is also unnecessary.)

To Reproduce

Call any API method without setting credentials and without explicitly omitting auth headers.

Library version

v2.x latest (main branch)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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