Skip to content

Feat: Make model optional in CreateModelResponseQuery for prompt_id flow#419

Merged
nezhyborets merged 1 commit into
mainfrom
claude/issue-385-optional-model-in-responses-query
May 18, 2026
Merged

Feat: Make model optional in CreateModelResponseQuery for prompt_id flow#419
nezhyborets merged 1 commit into
mainfrom
claude/issue-385-optional-model-in-responses-query

Conversation

@Krivoblotsky
Copy link
Copy Markdown
Contributor

What

Make model optional on CreateModelResponseQuery:

  • public let model: Stringpublic let model: String?
  • model: Stringmodel: String? = nil in init

JSONEncoder already omits nil keys, so when model is not provided the encoded request will not include the "model" field.

Why

Closes #385. The Responses API does not require model when a stored prompt is referenced via prompt_id (the model is taken from the prompt's configuration). The current type forced callers to pass model:, blocking the prompt-by-id flow.

Affected Areas

  • Sources/OpenAI/Public/Models/Responses API/CreateModelResponseQuery.swiftmodel and its init parameter are now optional.
  • Tests/OpenAITests/OpenAITestsDecoder.swift — new tests verifying that:
    • model is omitted from the encoded JSON when constructed with prompt: only;
    • model is still encoded as the model raw value when supplied.

More Info

  • Source-compat note: reading .model as non-optional becomes invalid for any consumer that previously did so; callers must unwrap. This matches the spec.
  • All existing call sites in the SDK and Demo already pass model: explicitly, so they compile unchanged.
  • All 38 OpenAITestsDecoder tests pass locally, including the 3 new ones (testCreateResponseQueryOmitsModelWhenNil, testCreateResponseQueryEncodesModelWhenProvided, plus the existing prompt-cache-key tests).

🤖 Generated with Claude Code

When referencing a stored prompt via prompt_id, the OpenAI Responses API
takes the model from the prompt configuration and does not require a
model field on the request. Force-requiring it on the Swift type blocks
that flow.

Make `model` an optional `String?` (defaulting to nil in the initializer)
so JSONEncoder omits it when not supplied. Existing call sites that pass
a model continue to work unchanged.

Closes #385

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@nezhyborets nezhyborets merged commit e7a3767 into main May 18, 2026
3 checks passed
@nezhyborets nezhyborets deleted the claude/issue-385-optional-model-in-responses-query branch May 18, 2026 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make model optional in CreateModelResponseQuery when referring prompts by "prompt_id"

2 participants