{"record":{"id":"77eb4ae0722b51b3","repo":"openai/openai-python","slug":"model-must-be-provided-when-creating-a-new-respons","errorCode":null,"errorMessage":"model must be provided when creating a new response","messagePattern":"model must be provided when creating a new response","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/openai/resources/responses/responses.py","lineNumber":1225,"sourceCode":"            \"top_p\": top_p,\n            \"truncation\": truncation,\n            \"user\": user,\n            \"background\": background,\n        }\n        new_response_args_names = [k for k, v in new_response_args.items() if is_given(v)]\n\n        if (is_given(response_id) or is_given(starting_after)) and len(new_response_args_names) > 0:\n            raise ValueError(\n                \"Cannot provide both response_id/starting_after can't be provided together with \"\n                + \", \".join(new_response_args_names)\n            )\n        tools = _make_tools(tools)\n        if len(new_response_args_names) > 0:\n            if not is_given(input):\n                raise ValueError(\"input must be provided when creating a new response\")\n\n            if not is_given(model):\n                raise ValueError(\"model must be provided when creating a new response\")\n\n            if is_given(text_format):\n                if not text:\n                    text = {}\n\n                if \"format\" in text:\n                    raise TypeError(\"Cannot mix and match text.format with text_format\")\n\n                text = copy(text)\n                text[\"format\"] = _type_to_text_format_param(text_format)\n\n            api_request: partial[Stream[ResponseStreamEvent]] = partial(\n                self.create,\n                input=input,\n                model=model,\n                tools=tools,\n                context_management=context_management,\n                conversation=conversation,","sourceCodeStart":1207,"sourceCodeEnd":1243,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/resources/responses/responses.py#L1207-L1243","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)"],"exampleFix":"// before\nstream = client.responses.stream(input=\"hello\")\n// after\nstream = client.responses.stream(model=\"gpt-4o\", input=\"hello\")","handlingStrategy":"validation","validationCode":"from openai._utils import is_given\nif not is_given(model) or not model:\n    raise ValueError('model is required to stream a new response')\nstream = client.responses.stream(model=model, input='hello')","typeGuard":"def has_model(kwargs: dict) -> bool:\n    m = kwargs.get('model')\n    return isinstance(m, str) and bool(m.strip())","tryCatchPattern":"try:\n    stream = client.responses.stream(model=model, input='hi')\nexcept ValueError as e:\n    if 'model must be provided' in str(e):\n        model = model or DEFAULT_MODEL\n        stream = client.responses.stream(model=model, input='hi')\n    else:\n        raise","preventionTips":["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"],"tags":["responses","stream","missing-argument","validation","python"],"backgroundTag":"missing-required-parameter","analyzedSha":"9917c6e28e66e90e1227b3d223c06a8c5441515a","analyzedAt":"2026-08-28T11:46:34.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}