openai/openai-python · error · ValueError

Expected a non-empty value for `project_id` but received {pr

Error message

Expected a non-empty value for `project_id` but received {project_id!r}

What it means

Raised when `projects.users.create` is called with an empty `project_id`. The SDK validates path parameters client-side before POSTing to `/organization/projects/{project_id}/users`, so an empty project ID fails before any network activity.

Source

Thrown at src/openai/resources/admin/organization/projects/users/users.py:91

        be added to a project.

        Args:
          role: `owner` or `member`

          email: Email of the user to add.

          user_id: The ID of the user.

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        """
        if not project_id:
            raise ValueError(f"Expected a non-empty value for `project_id` but received {project_id!r}")
        return self._post(
            path_template("/organization/projects/{project_id}/users", project_id=project_id),
            body=maybe_transform(
                {
                    "role": role,
                    "email": email,
                    "user_id": user_id,
                },
                user_create_params.UserCreateParams,
            ),
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                security={"admin_api_key_auth": True},
            ),
            cast_to=ProjectUser,

View on GitHub (pinned to 9917c6e28e)

Solutions

  1. Set project_id to the real 'proj_...' identifier from the Admin API or dashboard
  2. Check that the variable holding the project ID is assigned before the call (await it if it comes from a coroutine)
  3. Fail fast at startup on missing required configuration

Example fix

# before
client.admin.organization.projects.users.create(project_id="", role="member", email=email)
# after
project_id = os.environ["OPENAI_PROJECT_ID"]
client.admin.organization.projects.users.create(project_id=project_id, role="member", email=email)
Defensive patterns

Strategy: validation

Validate before calling

import os
project_id = os.environ["OPENAI_PROJECT_ID"]
client.admin.organization.projects.users.create(project_id=project_id, role="member", email=email)

Type guard

def is_valid_project_id(v: object) -> bool:
    return isinstance(v, str) and v.startswith("proj_")

Prevention

When it happens

Trigger: Calling `client.admin.organization.projects.users.create(project_id="" or None, role=..., email=...)` (sync or async).

Common situations: The OPENAI_PROJECT_ID-style env var is unset, the project ID is loaded asynchronously and not awaited, or the project name is passed instead of the 'proj_...' ID.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


AI-assisted analysis of openai/openai-python@9917c6e28e (2026-08-28). Data as JSON: /api/errors/b3cb3f390bfcfc7e. Report an issue: GitHub.