openai/openai-python · error · TypeError
Passing both `content` and `json_data` is not supported
Error message
Passing both `content` and `json_data` is not supported
What it means
The OpenAI Python SDK raises this ValueError when await client.vector_stores.file_batches.cancel() (async) is called with a falsy vector_store_id. It is a fast-fail client-side guard; no HTTP request is made when the store identifier is empty or None.
Source
Thrown at src/openai/_base_client.py:584
# request based on the truthiness of the "files" argument.
# This gets around that issue by generating a dict value that
# evaluates to true.
#
# https://github.com/encode/httpx/discussions/2399#discussioncomment-3814186
if not files:
files = cast(HttpxRequestFiles, ForceMultipartDict())
prepared_url = self._prepare_url(options.url)
# preserve hard-coded query params from the url
if params and prepared_url.query:
params = {**dict(prepared_url.params.items()), **params}
prepared_url = prepared_url.copy_with(raw_path=prepared_url.raw_path.split(b"?", 1)[0])
is_body_allowed = options.method.lower() != "get"
if is_body_allowed:
if options.content is not None and json_data is not None:
raise TypeError("Passing both `content` and `json_data` is not supported")
if options.content is not None and files is not None:
raise TypeError("Passing both `content` and `files` is not supported")
if options.content is not None:
kwargs["content"] = options.content
elif isinstance(json_data, bytes):
kwargs["content"] = json_data
elif not files:
# Don't set content when JSON is sent as multipart/form-data,
# since httpx's content param overrides other body arguments
kwargs["content"] = openapi_dumps(json_data) if is_given(json_data) and json_data is not None else None
kwargs["files"] = files
else:
headers.pop("Content-Type", None)
kwargs.pop("data", None)
timeout = self.timeout if isinstance(options.timeout, NotGiven) else options.timeout
request_url = str(prepared_url)
request_headers = list(headers.multi_items())View on GitHub (pinned to 9917c6e28e)
Solutions
- Thread the 'vs_...' store ID through to the cancellation code; verify it is set before awaiting cancel.
- When handling webhooks/jobs, validate that both vector_store_id and batch_id fields are present and non-empty before acting on them.
- Log the offending values at the call site to pinpoint where the ID was lost.
Example fix
# before
await client.vector_stores.file_batches.cancel(vector_store_id=store, batch_id=bid) # store is None
# after
if not store:
raise ValueError("cannot cancel batch: vector_store_id missing")
await client.vector_stores.file_batches.cancel(vector_store_id=store, batch_id=bid) Defensive patterns
Strategy: validation
Validate before calling
if not vector_store_id or not batch_id:
raise ValueError("cancel requires both vector_store_id and batch_id")
await client.vector_stores.file_batches.cancel(vector_store_id=vector_store_id, batch_id=batch_id) Type guard
def has_required_ids(vs: object, bid: object) -> bool:
return (
isinstance(vs, str) and vs.startswith("vs_")
and isinstance(bid, str) and bid.startswith("vsfb_")
) Try / catch
try:
await client.vector_stores.file_batches.cancel(vector_store_id=vs, batch_id=bid)
except ValueError:
# argument bug — fix caller; never retry with the same empty values
raise Prevention
- Pass full (store_id, batch_id) pairs through job queues and webhooks.
- Log both IDs at the cancellation call site for diagnosability.
When it happens
Trigger: Awaiting cancel(vector_store_id='', batch_id='vsfb_...') on the async resource, typically because the owning store's ID was never captured or was emptied by earlier logic.
Common situations: Cancellation code paths run from webhooks or background workers where the store reference was not passed along, or refactors that renamed variables holding the ID.
Related errors
- max_retries cannot be None. If you want to disable retries,
- Unexpected JSON data type, {type(json_data)}, cannot merge w
- Expected query input to be a dictionary for multipart reques
- Pagination is only supported with mappings
- No next page expected; please check `.has_next_page()` befor
AI-assisted analysis of openai/openai-python@9917c6e28e (2026-08-28).
Data as JSON: /api/errors/db2682fa8debf1dc.
Report an issue: GitHub.