@@ -395,7 +395,27 @@ function Request-Response {
395395 # region Construct parameters for API request
396396 $Response = $null
397397 $PostBody = [System.Collections.Specialized.OrderedDictionary ]::new()
398- $PostBody.model = $Model
398+
399+ # Reusable prompts
400+ $IsReusablePromptSpecified = $false
401+ if ($PromptId ) {
402+ $PromptOptions = @ {id = $PromptId }
403+ if ($PSBoundParameters.ContainsKey (' PromptVariables' )) {
404+ $PromptOptions.variables = $PromptVariables
405+ }
406+ if ($PSBoundParameters.ContainsKey (' PromptVersion' )) {
407+ $PromptOptions.version = $PromptVersion
408+ }
409+ $PostBody.prompt = $PromptOptions
410+
411+ # # When specifying a reusable prompt, normally required parameters such as model and input become optional.
412+ $IsReusablePromptSpecified = $true
413+ }
414+
415+ # Specify model
416+ if (-not $IsReusablePromptSpecified -or $PSBoundParameters.ContainsKey (' Model' )) {
417+ $PostBody.model = $Model
418+ }
399419
400420 if ($PreviousResponseId ) {
401421 $PostBody.previous_response_id = $PreviousResponseId
@@ -462,18 +482,6 @@ function Request-Response {
462482 $PostBody.stream = [bool ]$Stream
463483 }
464484
465- # Reusable prompts
466- if ($PromptId ) {
467- $PromptOptions = @ {id = $PromptId }
468- if ($PSBoundParameters.ContainsKey (' PromptVariables' )) {
469- $PromptOptions.variables = $PromptVariables
470- }
471- if ($PSBoundParameters.ContainsKey (' PromptVersion' )) {
472- $PromptOptions.version = $PromptVersion
473- }
474- $PostBody.prompt = $PromptOptions
475- }
476-
477485 # Reasoning
478486 $ReasoningOptions = @ {}
479487 if ($PSBoundParameters.ContainsKey (' ReasoningEffort' )) {
@@ -870,7 +878,7 @@ function Request-Response {
870878 # endregion
871879
872880 # Error if message is empty.
873- if ($Messages.Count -eq 0 ) {
881+ if (-not $IsReusablePromptSpecified -and $Messages.Count -eq 0 ) {
874882 Write-Error ' No message is specified. You must specify one or more messages.'
875883 return
876884 }
0 commit comments