Add response.done message handling for Realtime API error reporting#181
Merged
jamesrochabrun merged 2 commits intomainfrom Nov 17, 2025
Merged
Conversation
- Add responseDone case to OpenAIRealtimeMessage enum to capture response completion events - Implement handler for response.done messages in OpenAIRealtimeSession - Parse and expose error details from status_details.error for API errors (insufficient_quota, invalid_api_key, etc.) - Improve logging: upgrade unhandled message warnings from debug to warning level - Add detailed JSON logging for debugging unhandled message types This change ensures that critical API errors like quota exhaustion and authentication failures are properly surfaced to consuming applications instead of being silently discarded. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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