Skip to content

ggfeat(extractor): expose token usage via extract_with_usage methods#1447

Merged
joshua-mo-143 merged 1 commit into0xPlaygrounds:mainfrom
liamwh:main
Feb 28, 2026
Merged

ggfeat(extractor): expose token usage via extract_with_usage methods#1447
joshua-mo-143 merged 1 commit into0xPlaygrounds:mainfrom
liamwh:main

Conversation

@liamwh
Copy link
Copy Markdown
Contributor

@liamwh liamwh commented Feb 27, 2026

Add new methods that return both extracted data and token usage information, enabling users to track costs and token consumption when using extraction.

Changes:

  • Add ExtractionResponse struct containing data and total_usage fields
  • Add extract_with_usage() method returning ExtractionResponse
  • Add extract_with_chat_history_with_usage() method for chat history variant
  • Refactor extract_json to extract_json_with_usage to capture usage
  • Update existing extract() and extract_with_chat_history() to delegate internally
  • Export ExtractionResponse from rig-core::lib

Backward compatibility: Existing APIs unchanged, they delegate to new methods and discard usage information.

Usage accumulates across all retry attempts to provide complete cost picture.

Includes:

  • Updated example demonstrating both APIs
  • Integration tests for backward compatibility and new usage tracking

Add new methods that return both extracted data and token usage information,
enabling users to track costs and token consumption when using extraction.

Changes:
- Add ExtractionResponse<T> struct containing data and total_usage fields
- Add extract_with_usage() method returning ExtractionResponse
- Add extract_with_chat_history_with_usage() method for chat history variant
- Refactor extract_json to extract_json_with_usage to capture usage
- Update existing extract() and extract_with_chat_history() to delegate internally
- Export ExtractionResponse from rig-core::lib

Backward compatibility: Existing APIs unchanged, they delegate to new methods
and discard usage information.

Usage accumulates across all retry attempts to provide complete cost picture.

Includes:
- Updated example demonstrating both APIs
- Integration tests for backward compatibility and new usage tracking
Copy link
Copy Markdown
Contributor

@joshua-mo-143 joshua-mo-143 left a comment

Choose a reason for hiding this comment

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

lgtm, thanks liam!

@joshua-mo-143 joshua-mo-143 added this pull request to the merge queue Feb 28, 2026
Merged via the queue into 0xPlaygrounds:main with commit 137f9b1 Feb 28, 2026
6 checks passed
@github-actions github-actions Bot mentioned this pull request Feb 28, 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