Skip to content

Response API stream support #148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 7, 2025
Merged

Response API stream support #148

merged 10 commits into from
Jun 7, 2025

Conversation

jamesrochabrun
Copy link
Owner

Response API Streaming Support - Summary of Changes

Implementation strategy

  • Generated tests for all API Response models and events.
  • With that foundation, vibe coded all the API updates.

New Features

  1. Full Response API Streaming Support
  • Added ResponseStreamEvent enum with 40+ event types covering all Response API streaming scenarios
  • Implemented responseCreateStream() method for real-time streaming responses
  • Support for text deltas, function calls, tool usage, reasoning summaries, web search, file search,
    and image generation events
  1. Conversation State Management Fix
  • Added id field to InputMessage struct to support response ID tracking
  • Fixed 400 error when sending follow-up messages containing previous assistant responses
  • Proper handling of previousResponseId parameter for multi-turn conversations
  1. Complete Demo Implementation
  • ResponseStreamProvider: Full-featured streaming implementation with conversation history
  • ResponseStreamDemoView: SwiftUI demo showing real-time text streaming
  • Message accumulation, error handling, and stream cancellation support

Code Changes

Updated Files:

  • Sources/OpenAI/Public/Parameters/Response/InputType.swift - Added id field to InputMessage
  • Sources/OpenAI/Public/ResponseModels/Response/ResponseStreamEvent.swift - New comprehensive
    streaming events
  • Examples/SwiftOpenAIExample/SwiftOpenAIExample/ResponseAPIDemo/ResponseStreamProvider.swift -
    Streaming implementation
  • Examples/SwiftOpenAIExample/SwiftOpenAIExample/ResponseAPIDemo/ResponseStreamDemoView.swift - Demo
    UI
  • README.md - Added streaming documentation and examples

Documentation Updates

README additions:

  • Streaming Responses section with detailed examples
  • Input Types documentation showing new message structure
  • Multiple code examples for streaming scenarios:
    • Basic streaming
    • Streaming with conversation state
    • Streaming with tools and function calling
    • Stream cancellation
    • Complete implementation example

Technical Details

Key improvements:

  • Assistant messages in conversation history now sent as simple InputMessage with text content
  • Response IDs properly tracked through previousResponseId parameter
  • SwiftFormat applied to all modified files
  • No breaking changes - id field is optional with default nil value

jamesrochabrun and others added 10 commits June 6, 2025 23:19
… continuity

## Summary
- Added full streaming support for Response API with 40+ event types in ResponseStreamEvent
- Fixed conversation state management by adding `id` field to InputMessage for response tracking
- Implemented ResponseStreamProvider demo showing real-time streaming with conversation history
- Updated README with comprehensive streaming documentation and examples

## Changes
- **Response API Streaming**:
  - Added ResponseStreamEvent enum with all streaming event types
  - Implemented stream event parsing for text deltas, function calls, tool usage, etc.
  - Added support for reasoning summaries, web search, file search events

- **Conversation State Fix**:
  - Added `id` field to InputMessage to support response IDs in conversation history
  - Fixed 400 error when sending follow-up messages with previous assistant responses
  - Simplified assistant message handling in conversation arrays

- **Demo Implementation**:
  - Created ResponseStreamProvider with full streaming capabilities
  - Added ResponseStreamDemoView showing real-time UI updates
  - Implemented message accumulation and conversation state management

- **Documentation**:
  - Added comprehensive streaming section to README
  - Documented all new Response API types and structures
  - Included multiple code examples for various streaming scenarios

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@jamesrochabrun jamesrochabrun merged commit f44490f into main Jun 7, 2025
2 checks passed
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.

1 participant