Skip to content

AsyncOpenAI(api_key="") raises OpenAIError in v2.34.0, breaking OpenAI-compatible local servers #3224

Closed as not planned

Description

@tbille

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

In v2.34.0, AsyncOpenAI(api_key="") now raises OpenAIError: Missing credentials. In v2.33.0 and earlier, passing an empty string was silently accepted.

This is a breaking change for anyone using the OpenAI Python SDK to talk to OpenAI-compatible local servers (llama.cpp, llamafile, LM Studio, vLLM, etc.) that do not require authentication. These wrappers intentionally pass api_key="" because no credentials are needed for a local HTTP server.

The root cause appears to be the new credential validation logic in _client.py around line 700, which now checks not self.api_key (falsy for ""), along with the new workload_identity and admin_api_key checks added in 2.34.0.

Previous behavior (v2.33.0): AsyncOpenAI(api_key="", base_url="http://localhost:8080/v1") succeeded and produced a usable client.

New behavior (v2.34.0): The same call raises:

openai.OpenAIError: Missing credentials. Please pass an `api_key`, `workload_identity`,
`admin_api_key`, or set the `OPENAI_API_KEY` or `OPENAI_ADMIN_KEY` environment variable.

The workaround is to pass a non-empty placeholder string (e.g., api_key="not-needed"), but this is surprising since api_key="" worked in all prior versions.

To Reproduce

  1. Install openai==2.34.0
  2. Run the code below
  3. Observe OpenAIError raised

Code snippets

from openai import AsyncOpenAI

# Works in 2.33.0, fails in 2.34.0
client = AsyncOpenAI(
    api_key="",
    base_url="http://localhost:8080/v1",
)

OS

Linux and macOS (all platforms)

Python version

Python 3.11, 3.12, 3.13

Library version

openai v2.34.0

Activity

  1. bheemaguli commented on May 12, 2026

    @bheemaguli

    +1 for this. Tests and other CI are failing because of hard requirement.

  2. added a commit that references this issue on May 18, 2026
    9d040af
  3. SanskaarUndale21 commented on May 19, 2026

    @SanskaarUndale21

    Hey, I'd like to hop in on this. I see PR #3225 from the issue author is already open.

    My approach: capture whether api_key was explicitly provided by the caller before the env var fallback. A flag _api_key_explicitly_provided = api_key is not None is set right before os.environ.get('OPENAI_API_KEY') in both OpenAI.__init__() and AsyncOpenAI.__init__(). The credentials check then becomes:

    if (
        _enforce_credentials
        and not self.api_key
        and not _api_key_explicitly_provided   # <-- skip error if caller passed api_key=""
        and self._api_key_provider is None
        and workload_identity is None
        and self.admin_api_key is None
    ):

    This way passing api_key="" (explicit intent, local servers) is allowed, while omitting api_key entirely with no env var still raises. Also initialising the flag to False before the workload_identity branch keeps it safe regardless of path taken. Happy to open a PR with tests if this direction works for the maintainers.

  4. added a commit that references this issue on May 19, 2026
    cb9bfd0
  5. added 3 commits that reference this issue on May 26, 2026
    1feb1e7
    5c8518b
    aee59d3
  6. added a commit that references this issue on Jun 15, 2026
    9be7185
  7. added a commit that references this issue on Jun 22, 2026
    7292b2d
  8. added a commit that references this issue on Jun 25, 2026
  9. added a commit that references this issue on Aug 5, 2026
    e8c5dfe
  10. Xsidz commented on Aug 16, 2026

    @Xsidz

    Working on this in PR #3630.

  11. marcuswood-oai commented on Sep 10, 2026

    @marcuswood-oai
    Contributor

    Thanks for reporting this, and sorry for the disruption to existing integrations. We’re keeping the empty-key check to catch missing credentials early. For local servers that don’t require authentication, please pass an explicit placeholder such as api_key="not-needed" alongside your local base_url.

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