Skip to content

[codex] Fix OpenAI costs parsing#1000

Closed
SergeyLavrentev wants to merge 1 commit into
steipete:mainfrom
SergeyLavrentev:codex/fix-openai-costs-string-values
Closed

[codex] Fix OpenAI costs parsing#1000
SergeyLavrentev wants to merge 1 commit into
steipete:mainfrom
SergeyLavrentev:codex/fix-openai-costs-string-values

Conversation

@SergeyLavrentev
Copy link
Copy Markdown

Summary

  • Decode OpenAI organization cost amount.value when it is returned as a numeric string.
  • Keep existing numeric decoding support for documented numeric responses.
  • Add a regression fixture covering the string value shape observed from the live API.

Fixes #999

Root cause

The OpenAI Costs API can return amount.value as a string such as "12.50". OpenAIAPIUsageFetcher decoded this field as Double?, so a successful HTTP 200 costs response failed JSON decoding and OpenAI Admin API usage rendered an error.

Validation

  • Live probe against /v1/organization/costs with an Admin API key decoded 31 cost buckets using the tolerant decoder.
  • swift test --filter OpenAIAPICreditBalanceTests could not complete in this local environment because only Command Line Tools are installed; the macOS test target pulls KeyboardShortcuts, whose SwiftUI #Preview usage requires PreviewsMacros from full Xcode.

OpenAI organization costs responses may return amount.value as a numeric string. Decode both numeric and string values so Admin API usage does not fail parsing.
@steipete
Copy link
Copy Markdown
Owner

Thanks for the clean repro and patch. I landed the fix on main in f23a478 with the same tolerant decoding behavior, plus a small test tweak so the fixture covers both documented numeric values and the observed numeric-string value.

Validation:

  • swift test --filter OpenAIAPICreditBalanceTests
  • make check
  • Codex review: no actionable findings

Closing this draft PR since the fix is now shipped on main.

@steipete steipete closed this May 16, 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.

OpenAI Admin API usage fails when costs amount value is returned as a string

3 participants