feat: Add prompt parameter support for stored prompts in Responses API (Fixes #500) #501
+310
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements support for stored prompts in the OpenAI .NET SDK Responses API, addressing the feature request in issue #500. The implementation brings the .NET SDK to feature parity with the JavaScript SDK for stored prompt functionality.
Changes
Core Implementation
ResponsePrompt.cs
: New class representing stored prompts withId
,Version
, andVariables
propertiesResponsePrompt.Serialization.cs
: Complete JSON serialization support with trimming compatibility (IL2026 compliant)ResponseCreationOptions.cs
: AddedPrompt
property to enable stored prompt usageTesting & Examples
ResponsesTests.cs
Example03_StoredPrompts.cs
demonstrating synchronous usageExample03_StoredPromptsAsync.cs
demonstrating asynchronous usageFeatures
✅ Stored Prompt Support: Full implementation matching JavaScript SDK functionality
✅ Variable Substitution: Support for prompt variables with type-safe handling
✅ JSON Serialization: Custom IJsonModel implementation with proper error handling
✅ Trimming Compatibility: All IL2026 warnings resolved for AOT scenarios
✅ Pattern Compliance: Follows existing codebase conventions and patterns
✅ Comprehensive Testing: Unit tests covering serialization, deserialization, and integration
Usage Example
API Compatibility
This implementation enables the same functionality as the JavaScript SDK:
JavaScript:
C# (with this PR):
Technical Details
IJsonModel<ResponsePrompt>
implementation handles all primitive types and complex objectsWriteRawValue
for .NET 6.0+ with fallback for earlier versionsIDictionary<string, object>
with proper JSON deserializationResponseCreationOptions
workflowTesting
All tests pass and the project builds successfully in Release configuration:
Breaking Changes
None. This is a purely additive feature that maintains full backward compatibility.
Fixes #500