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 client-side by the openai-python SDK before any HTTP request. Assigning a role to a group via client.admin.organization.projects.groups.roles.create(...) requires a non-empty project_id because it is interpolated into /projects/{project_id}/groups/{group_id}/roles. The guard prevents a malformed URL and echoes the invalid value in the error message.
Source
Thrown at src/openai/resources/admin/organization/projects/groups/roles.py:74
extra_body: Body | None = None,
timeout: float | httpx2.Timeout | None | NotGiven = not_given,
) -> RoleCreateResponse:
"""
Assigns a project role to a group within a project.
Args:
role_id: Identifier of the role to assign.
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}")
if not group_id:
raise ValueError(f"Expected a non-empty value for `group_id` but received {group_id!r}")
return self._post(
path_template("/projects/{project_id}/groups/{group_id}/roles", project_id=project_id, group_id=group_id),
body=maybe_transform({"role_id": role_id}, role_create_params.RoleCreateParams),
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=RoleCreateResponse,
)
def retrieve(
self,
role_id: str,View on GitHub (pinned to 9917c6e28e)
Solutions
- Verify and populate project_id before the call; print repr() to confirm the problem.
- Load the id from a required setting and validate at application startup.
- Derive it from client.admin.organization.projects.list()/retrieve() responses.
Example fix
# before
client.admin.organization.projects.groups.roles.create(project_id=os.getenv("PROJECT"), group_id=gid, role_id=rid)
# after
project_id = os.environ["PROJECT_ID"]
client.admin.organization.projects.groups.roles.create(project_id=project_id, group_id=gid, role_id=rid) Defensive patterns
Strategy: validation
Validate before calling
if not project_id:
raise ValueError("project_id must be set to assign group roles")
client.admin.organization.projects.groups.roles.create(project_id=project_id, group_id=group_id, role_id=role_id) Type guard
def valid_project_id(pid: object) -> bool:
return isinstance(pid, str) and pid.strip() != "" Try / catch
try:
client.admin.organization.projects.groups.roles.create(project_id=pid, group_id=gid, role_id=rid)
except ValueError as e:
raise ConfigError(f"bad arguments for role assignment: {e}") from e Prevention
- Pass required ids as explicit function arguments, not ambient globals.
- Assert on id presence in provisioning entry points.
- Keep a single source of truth for project/group/role ids in config.
When it happens
Trigger: Calling roles.create(project_id='', group_id=..., role_id=...) where project_id is None or empty (unset env var, missing config key, failed lookup).
Common situations: Missing project id in CI secrets; scripts where the project id is fetched from a prior API call that returned no data; copy-paste from examples that hardcode placeholder ids like 'proj_abc' replaced with blanks.
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
- Expected a non-empty value for `group_id` but received {grou
- Expected a non-empty value for `role_id` but received {role_
- Expected a non-empty value for `group_id` but received {grou
- Expected a non-empty value for `role_id` but received {role_
- Expected a non-empty value for `user_id` but received {user_
AI-assisted analysis of openai/openai-python@9917c6e28e (2026-08-28).
Data as JSON: /api/errors/0471502d18ede7e2.
Report an issue: GitHub.