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 `retrieve` of the admin model permissions resource requires a non-empty `project_id` for the GET to `/organization/projects/{project_id}/model_permissions`. The SDK raises this ValueError before the request when the value is falsy.
Source
Thrown at src/openai/resources/admin/organization/projects/model_permissions.py:67
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx2.Timeout | None | NotGiven = not_given,
) -> ProjectModelPermissions:
"""
Returns model permissions for a project.
Args:
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._get(
path_template("/organization/projects/{project_id}/model_permissions", project_id=project_id),
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=ProjectModelPermissions,
)
def update(
self,
project_id: str,
*,
mode: Literal["allow_list", "deny_list"],
model_ids: SequenceNotStr[str],View on GitHub (pinned to 9917c6e28e)
Solutions
- Print or log project_id before the call
- Check the config key or CLI argument that supplies it
- Load the id from projects.list()/create() responses instead of manual entry
- Fail fast at startup if required ids are absent
Example fix
# before perms = client.admin.organization.projects.model_permissions.retrieve(project_id) # after assert project_id, "project_id must be set" perms = client.admin.organization.projects.model_permissions.retrieve(project_id)
Defensive patterns
Strategy: validation
Validate before calling
if not project_id:
raise ValueError("project_id required to read model permissions") Type guard
def valid_project_id(v: object) -> TypeGuard[str]:
return isinstance(v, str) and v.strip() != "" Try / catch
try:
perms = ...model_permissions.retrieve(project_id)
except ValueError as e:
if "project_id" in str(e):
raise ConfigError(str(e))
raise Prevention
- Validate config keys that hold project ids
- Log ids before API calls during onboarding scripts
- Pull ids from projects.list()
When it happens
Trigger: Calling `model_permissions.retrieve(project_id='')` while trying to read which models a project can access, with an id variable that was never populated.
Common situations: Scripts parameterized by project where the argument was not passed, or reading the id from a YAML/JSON config with a typo'd key.
Related errors
- Expected a non-empty value for `project_id` but received {pr
- Expected a non-empty value for `project_id` but received {pr
- Expected a non-empty value for `project_id` but received {pr
- Expected a non-empty value for `project_id` but received {pr
- Expected a non-empty value for `project_id` but received {pr
AI-assisted analysis of openai/openai-python@9917c6e28e (2026-08-28).
Data as JSON: /api/errors/02803ede91608750.
Report an issue: GitHub.