openai/openai-python · error · TypeError
Missing required arguments: {human_join([quote(arg) for arg
Error message
Missing required arguments: {human_join([quote(arg) for arg in missing])} What it means
The same @required_args decorator verifies that all parameters required by at least one overload variant were supplied. When the intersection of provided args and each variant's required set is empty, it raises this TypeError listing the missing names (from the first variant). It reproduces pyright-style 'Missing required argument' errors at runtime for methods whose signatures the type checker cannot fully enforce.
Source
Thrown at src/openai/_utils/_utils.py:297
matches = all((param in given_params for param in variant))
if matches:
break
else: # no break
if len(variants) > 1:
variations = human_join(
["(" + human_join([quote(arg) for arg in variant], final="and") + ")" for variant in variants]
)
msg = f"Missing required arguments; Expected either {variations} arguments to be given"
else:
assert len(variants) > 0
# TODO: this error message is not deterministic
missing = list(set(variants[0]) - given_params)
if len(missing) > 1:
msg = f"Missing required arguments: {human_join([quote(arg) for arg in missing])}"
else:
msg = f"Missing required argument: {quote(missing[0])}"
raise TypeError(msg)
return func(*args, **kwargs)
return wrapper # type: ignore
return inner
_K = TypeVar("_K")
_V = TypeVar("_V")
@overload
def strip_not_given(obj: None) -> None: ...
@overload
def strip_not_given(obj: Mapping[_K, _V | NotGiven]) -> dict[_K, _V]: ...
View on GitHub (pinned to 9917c6e28e)
Solutions
- Add the missing keyword argument named in the message
- If fields are conditional, default them explicitly or branch so every call includes all required kwargs
- Check the method's docstring/signature for required vs optional params after upgrades
- Run pyright/mypy on call sites — these errors are statically detectable
Example fix
# before
f = client.files.create(file=open("x.jsonl","rb"))
# after
f = client.files.create(file=open("x.jsonl","rb"), purpose="assistants") Defensive patterns
Strategy: validation
Validate before calling
import inspect
required = {n for n,p in inspect.signature(method).parameters.items() if p.default is inspect.Parameter.empty}
missing = required - provided
assert not missing, f"missing {missing}" Type guard
def required_args_satisfied(method, kwargs: dict) -> bool:
import inspect
req = {n for n,p in inspect.signature(method).parameters.items()
if p.default is inspect.Parameter.empty and p.kind in (p.POSITIONAL_OR_KEYWORD, p.KEYWORD_ONLY)}
return req <= set(kwargs) | {n for n,p in inspect.signature(method).parameters.items() if p.default is inspect.Parameter.empty} & set(kwargs) or bool(req & set(kwargs)) Try / catch
try:
method(**payload)
except TypeError as e:
if "required argument" in str(e): collect_and_retry(payload) Prevention
- Run pyright/mypy on call sites
- Add schema validation for config-built payloads
- Re-read method docs after version upgrades
When it happens
Trigger: Calling an SDK method without one of its required kwargs, e.g. client.completions.create(model="gpt-4o") without prompt/messages, or client.files.create(file=f) without purpose; conditional code paths that sometimes skip a required keyword.
Common situations: Config-driven request builders that conditionally include fields; refactoring that renamed a parameter; new SDK versions adding a required parameter; forgetting purpose on file uploads.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- {func.__name__}() takes {len(positional)} argument(s) but {l
- Invalid `http_client` argument; Expected an instance of `htt
- Passing both `body` and `content` is not supported
- Passing both `files` and `content` is not supported
- Invalid `http_client` argument; Expected an instance of `htt
AI-assisted analysis of openai/openai-python@9917c6e28e (2026-08-28).
Data as JSON: /api/errors/b3f57463c4f7574f.
Report an issue: GitHub.