Skip to content

Decode the error object in OpenAI Responses results - #270

Merged
mattt merged 1 commit into
mainfrom
mattt/responses-error-object
Sep 25, 2026
Merged

mattt merged 1 commit into
mainfrom
mattt/responses-error-object

Conversation

@mattt

@mattt mattt commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

The Responses API returns error as an object with a code and a message, or null. OpenAILanguageModel declared it as [JSONValue]?, so a non-streaming response with a non-null error failed to decode as a whole, and the caller got a decoding error instead of the response.

This PR decodes error as that object, the way OpenResponsesLanguageModel already 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.

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 error as 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.

@mattt
mattt merged commit 0626c0f into main Sep 25, 2026
13 checks passed
@mattt
mattt deleted the mattt/responses-error-object branch September 25, 2026 13:54
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.

2 participants