Decode the error object in OpenAI Responses results - #270
Merged
Merged
Conversation
The Responses API returns `error` as an object with a code and a message, or null. OpenAILanguageModel declared it as an array of JSON values, so a response with a non-null error failed to decode as a whole. It now decodes the object, as the Open Responses provider does.
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused type correction matches the API payload and has appropriate regression coverage.
Review effort: Balanced
Findings: None
What changed in this PR
Corrects OpenAI Responses API error-object decoding while preserving existing response behavior.
Changes:
- Models
erroras a nullable response-error object. - Adds regression coverage for OpenAI and Open Responses providers.
| File | Description |
|---|---|
Sources/AnyLanguageModel/Models/OpenAILanguageModel.swift |
Corrects the Responses error type. |
Tests/AnyLanguageModelTests/ProviderUsageTests.swift |
Verifies error objects decode successfully. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
The Responses API returns
erroras an object with a code and a message, ornull.OpenAILanguageModeldeclared it as[JSONValue]?, so a non-streaming response with a non-nullerrorfailed to decode as a whole, and the caller got a decoding error instead of the response.This PR decodes
erroras that object, the wayOpenResponsesLanguageModelalready does, and adds a test that decodes a response with an error object for both providers. The error isn't surfaced yet; that's separate from getting the response to decode.