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` method of the admin hosted tool permissions resource requires a non-empty `project_id` because it is interpolated into `/organization/projects/{project_id}/hosted_tool_permissions`. The SDK raises this ValueError before any request when the value is None or empty.
Source
Thrown at src/openai/resources/admin/organization/projects/hosted_tool_permissions.py:66
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx2.Timeout | None | NotGiven = not_given,
) -> ProjectHostedToolPermissions:
"""
Returns hosted tool 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}/hosted_tool_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=ProjectHostedToolPermissions,
)
def update(
self,
project_id: str,
*,
code_interpreter: Optional[hosted_tool_permission_update_params.CodeInterpreter] | Omit = omit,
file_search: Optional[hosted_tool_permission_update_params.FileSearch] | Omit = omit,View on GitHub (pinned to 9917c6e28e)
Solutions
- Ensure project_id is a real id like 'proj_abc123' before the call
- Validate required env vars at startup and fail fast
- Pass the id from the project object returned by projects.create/list rather than typing it manually
- Add unit tests asserting the id is non-empty
Example fix
# before
perms = client.admin.organization.projects.hosted_tool_permissions.retrieve(project_id)
# after
if not project_id:
raise ValueError("project_id must be set (e.g. proj_abc123)")
perms = client.admin.organization.projects.hosted_tool_permissions.retrieve(project_id) Defensive patterns
Strategy: validation
Validate before calling
if not project_id or not project_id.startswith("proj_"):
raise ValueError(f"invalid project_id: {project_id!r}") Type guard
def valid_project_id(v: object) -> TypeGuard[str]:
return isinstance(v, str) and len(v) > 0 and v.startswith("proj_") Try / catch
try:
perms = ...retrieve(project_id)
except ValueError as e:
if "project_id" in str(e):
raise ConfigError(str(e))
raise Prevention
- Fail fast on missing env vars at startup
- Centralize project-id resolution in one validated function
- Add config schema validation (pydantic)
When it happens
Trigger: Calling `client.admin.organization.projects.hosted_tool_permissions.retrieve(project_id='')` or passing an unset variable, e.g. project_id = os.getenv('PROJECT_ID') when the env var is not defined.
Common situations: Tooling configured per-project where the project id env var is only set in some environments, or scripts copied between orgs without updating the project reference.
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/389fa6181add08f6.
Report an issue: GitHub.