openai/openai-python · error · ValueError
model must be provided when creating a new response
Error message
model must be provided when creating a new response
What it means
Raised by Responses.stream() when you pass any 'new response' argument (e.g. input is implied by other create args) but omit the required `model` parameter. The Responses API requires a model identifier whenever a new response is being created via the streaming helper. The SDK validates this client-side before making any network request.
Source
Thrown at src/openai/resources/responses/responses.py:1225
"top_p": top_p,
"truncation": truncation,
"user": user,
"background": background,
}
new_response_args_names = [k for k, v in new_response_args.items() if is_given(v)]
if (is_given(response_id) or is_given(starting_after)) and len(new_response_args_names) > 0:
raise ValueError(
"Cannot provide both response_id/starting_after can't be provided together with "
+ ", ".join(new_response_args_names)
)
tools = _make_tools(tools)
if len(new_response_args_names) > 0:
if not is_given(input):
raise ValueError("input must be provided when creating a new response")
if not is_given(model):
raise ValueError("model must be provided when creating a new response")
if is_given(text_format):
if not text:
text = {}
if "format" in text:
raise TypeError("Cannot mix and match text.format with text_format")
text = copy(text)
text["format"] = _type_to_text_format_param(text_format)
api_request: partial[Stream[ResponseStreamEvent]] = partial(
self.create,
input=input,
model=model,
tools=tools,
context_management=context_management,
conversation=conversation,View on GitHub (pinned to 9917c6e28e)
Solutions
- Pass a valid model, e.g. client.responses.stream(model='gpt-4o', input='hello')
- If you meant to stream an existing response, pass response_id='resp_...' instead of create arguments
- Ensure model isn't None or NOT_GIVEN due to an env/config lookup (e.g. os.environ.get('OPENAI_MODEL') returning None)
Example fix
// before stream = client.responses.stream(input="hello") // after stream = client.responses.stream(model="gpt-4o", input="hello")
Defensive patterns
Strategy: validation
Validate before calling
from openai._utils import is_given
if not is_given(model) or not model:
raise ValueError('model is required to stream a new response')
stream = client.responses.stream(model=model, input='hello') Type guard
def has_model(kwargs: dict) -> bool:
m = kwargs.get('model')
return isinstance(m, str) and bool(m.strip()) Try / catch
try:
stream = client.responses.stream(model=model, input='hi')
except ValueError as e:
if 'model must be provided' in str(e):
model = model or DEFAULT_MODEL
stream = client.responses.stream(model=model, input='hi')
else:
raise Prevention
- Always pass model explicitly; never rely on defaults when calling stream()
- Centralize model selection in one config helper so it can't be forgotten
- Add unit tests asserting model is present before stream calls in wrappers
When it happens
Trigger: Calling client.responses.stream(input=...) or passing any create-only argument without model=..., e.g. client.responses.stream(input='hi', max_output_tokens=100) with no model. Only fires when len(new_response_args_names) > 0, i.e. at least one create argument was given.
Common situations: Migrating code from client.responses.create(stream=True) and forgetting to carry the model kwarg; refactoring where model was previously read from a config variable that is now None/NotGiven; copy-pasting a stream example that omits model.
Understand the failure class
Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.
Related errors
- id must be provided when streaming an existing response
- response_id must be provided when streaming an existing resp
- Expected a non-empty value for `response_id` but received {r
- Expected a non-empty value for `response_id` but received {r
- Cannot mix and match text.format with text_format
AI-assisted analysis of openai/openai-python@9917c6e28e (2026-08-28).
Data as JSON: /api/errors/77eb4ae0722b51b3.
Report an issue: GitHub.