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

The sync project Groups `create` method validates `project_id` before POSTing `/organization/projects/{project_id}/groups` with group_id and role. A falsy value would corrupt the URL, so the SDK raises this ValueError client-side with no network activity.

Source

Thrown at src/openai/resources/admin/organization/projects/groups/groups.py:86

    ) -> ProjectGroup:
        """
        Grants a group access to a project.

        Args:
          group_id: Identifier of the group to add to the project.

          role: Identifier of the project role to grant to the group.

          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}/groups", project_id=project_id),
            body=maybe_transform(
                {
                    "group_id": group_id,
                    "role": role,
                },
                group_create_params.GroupCreateParams,
            ),
            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=ProjectGroup,
        )

View on GitHub (pinned to 9917c6e28e)

Solutions

  1. Pass the real project id from the dashboard or projects.list
  2. Validate required identifiers at startup in provisioning scripts
  3. Log the full argument set before create operations

Example fix

# before
client.admin.organization.projects.groups.create(project_id="", group_id="grp_123", role="member")

# after
client.admin.organization.projects.groups.create(project_id="proj_abc123", group_id="grp_123", role="member")
Defensive patterns

Strategy: validation

Validate before calling

if not project_id:
    raise ValueError("project_id required to add group")
client.admin.organization.projects.groups.create(project_id=project_id, group_id=group_id, role=role)

Type guard

def is_valid_project_id(v: str | None) -> bool:
    return isinstance(v, str) and bool(v.strip())

Try / catch

try:
    client.admin.organization.projects.groups.create(project_id=pid, group_id=gid, role=role)
except ValueError as e:
    logger.error("group create rejected: %s", e)
    raise

Prevention

When it happens

Trigger: Calling groups.create(project_id=..., group_id=..., role=...) with an empty project id; config or env lookups returning None.

Common situations: Onboarding automation missing required env config; empty project field in tenant data; placeholder never replaced.

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/14adfe2d5bda410e. Report an issue: GitHub.