Skip to content

fix: accept quoted numeric strings in OrganizationCostsResult.Amount.value() (#769) - #771

Closed
kuntal1461 wants to merge 1 commit into
openai:mainfrom
kuntal1461:fix/issue-769-amount-value
Closed

kuntal1461 wants to merge 1 commit into
openai:mainfrom
kuntal1461:fix/issue-769-amount-value

Conversation

@kuntal1461

Copy link
Copy Markdown

Summary

  • Fixes GitHub issue OpenAI Java lib 4.41.0 throws OpenAIInvalidDataException in OrganizationCostsResult when parsing amount values #769: OrganizationCostsResult.Amount.value() threw OpenAIInvalidDataException when the live API returned amount.value as a quoted numeric string (e.g. "0E-6176") despite the OpenAPI spec declaring type: number
  • Root cause: Jackson's CoercionAction.Fail for String→Float caused tryDeserialize to return null for quoted numeric strings, leaving a JsonString in the JsonField which getOptional() rejected as invalid
  • Fix adds a BigDecimal fallback in Amount.value(): if asKnown() is absent and the backing field is a JsonString, parse via BigDecimal → Double with an isFinite() guard to reject overflow

Test plan

  • quoted 0E-6176 zero-cost string returns 0.0 — primary bug reproduction verified locally
  • Valid JSON number path unchanged
  • Non-numeric strings still throw OpenAIInvalidDataException
  • Overflow ("1e309") rejected by isFinite() guard
  • validate() benefits automatically (calls value() internally)

Authored-By: Kuntal maity [email protected]

…value() (openai#769)

The live API returns `OrganizationCostsResult.Amount.value` as a quoted
numeric string (e.g. "0E-6176") despite the OpenAPI spec declaring
`type: number`. Jackson's CoercionAction.Fail for String→Float causes
tryDeserialize to return null, leaving a JsonString in the JsonField
which getOptional() then rejects as invalid data.

Fix adds a BigDecimal fallback in Amount.value(): if asKnown() is absent
and the backing field is a JsonString, parse via BigDecimal → Double with
an isFinite() guard to reject overflow.

Authored-By: Kuntal maity <[email protected]>

Copy link
Copy Markdown
Contributor

Thanks for the contribution! The underlying issue in #769 was resolved server-side: the Costs API now returns amount.value as a JSON number, matching its documented contract. The original reporter also observed the corrected behavior.

Closing this PR because the client-side string-parsing workaround is no longer needed for this bug. We appreciate your work on the fix.

@dpiet-oai dpiet-oai closed this Sep 20, 2026
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