Add response.done message handling for Realtime API error reporting #181
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 adds proper handling for
response.donemessages in the Realtime API, enabling applications to properly surface critical API errors like quota exhaustion and authentication failures.Problem
Previously, the Realtime API silently swallowed
response.donemessages, which contain crucial error information. When API errors occurred (e.g.,insufficient_quota,invalid_api_key), they were logged as "Unhandled message type" but never surfaced to consuming applications, making debugging nearly impossible.Solution
1. New Message Type
responseDone(status: String, statusDetails: [String: Any]?)case toOpenAIRealtimeMessageenum2. Response.done Handler
OpenAIRealtimeSessionforresponse.donemessagesstatus_details.errorstructure3. Improved Logging
.debugto.warningfor better visibilityError Format
The handler correctly parses OpenAI's error structure:
{ "type": "response.done", "response": { "id": "resp_xxx", "status": "failed", "status_details": { "error": { "code": "insufficient_quota", "message": "You exceeded your current quota..." } } } }Breaking Changes
None - this is a purely additive change.
Testing
Tested with:
Impact
Applications using SwiftOpenAI Realtime API can now:
🤖 Generated with Claude Code