openai/openai-python · error · ValueError
Expected a non-empty value for `vector_store_id` but receive
Error message
Expected a non-empty value for `vector_store_id` but received {vector_store_id!r} What it means
Creating a vector store file via `client.vector_stores.files.create` requires a non-empty `vector_store_id`. The SDK validates path parameters before the POST to `/vector_stores/{vector_store_id}/files` and raises ValueError for empty values to avoid malformed requests.
Source
Thrown at src/openai/resources/vector_stores/files.py:96
attributes: Set of 16 key-value pairs that can be attached to an object. This can be useful
for storing additional information about the object in a structured format, and
querying for objects via API or the dashboard. Keys are strings with a maximum
length of 64 characters. Values are strings with a maximum length of 512
characters, booleans, or numbers.
chunking_strategy: The chunking strategy used to chunk the file(s). If not set, will use the `auto`
strategy. Only applicable if `file_ids` is non-empty.
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 vector_store_id:
raise ValueError(f"Expected a non-empty value for `vector_store_id` but received {vector_store_id!r}")
extra_headers = {"OpenAI-Beta": "assistants=v2", **(extra_headers or {})}
return self._post(
path_template("/vector_stores/{vector_store_id}/files", vector_store_id=vector_store_id),
body=maybe_transform(
{
"file_id": file_id,
"attributes": attributes,
"chunking_strategy": chunking_strategy,
},
file_create_params.FileCreateParams,
),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
extra_body=extra_body,
timeout=timeout,
security={"bearer_auth": True},
),View on GitHub (pinned to 9917c6e28e)
Solutions
- Use the id from creation: `vs = client.vector_stores.create(...)` then `vs.id`
- If passing an object, extract `.id`: `vector_store_id=store.id`
- Print/log the variable right before the call to confirm it is populated
Example fix
# before client.vector_stores.files.create(vector_store_id="", file_id="file-abc") # after vs = client.vector_stores.create(name="docs") file = client.vector_stores.files.create(vector_store_id=vs.id, file_id="file-abc")
Defensive patterns
Strategy: validation
Validate before calling
vs_id = getattr(store, "id", store) # accept object or id
if not isinstance(vs_id, str) or not vs_id:
raise ValueError(f"vector_store_id must be a non-empty string, got {vs_id!r}")
file = client.vector_stores.files.create(vector_store_id=vs_id, file_id=file_id) Type guard
from openai.types.vector_store import VectorStore
def resolve_store_id(v: str | VectorStore) -> str:
return v.id if isinstance(v, VectorStore) else v Try / catch
try:
file = client.vector_stores.files.create(vector_store_id=vs_id, file_id=file_id)
except ValueError as e:
logger.error("Bad arguments: %s", e)
raise Prevention
- Capture vs.id from client.vector_stores.create immediately
- Use keyword arguments to avoid positional mix-ups
- Centralize id resolution (object or string) in one helper
When it happens
Trigger: Calling `client.vector_stores.files.create(vector_store_id="" or None, file_id="file-abc")`, or when the vector store was created but its `.id` was not captured; `upload` and `upload_and_poll` forward their `vector_store_id` argument and hit the same check.
Common situations: Passing a `VectorStore` object instead of its `.id`, an unset environment/config variable holding the store id, or a store created in a different flow/variable scope.
Related errors
- Pagination is only supported with mappings
- Expected a non-empty value for `file_id` but received {file_
- No next page expected; please check `.has_next_page()` befor
- max_retries cannot be None. If you want to disable retries,
- Unexpected JSON data type, {type(json_data)}, cannot merge w
AI-assisted analysis of openai/openai-python@9917c6e28e (2026-08-28).
Data as JSON: /api/errors/4754e8528bd7e538.
Report an issue: GitHub.