feat: add optional OpenAI usage/cost tracking for presentation generation#421
Open
mlimarenko wants to merge 3 commits intopresenton:mainfrom
Open
feat: add optional OpenAI usage/cost tracking for presentation generation#421mlimarenko wants to merge 3 commits intopresenton:mainfrom
mlimarenko wants to merge 3 commits intopresenton:mainfrom
Conversation
added 3 commits
February 22, 2026 14:55
Track OpenAI token usage and estimated USD cost for presentation generation when enabled.\n\n- add context-aware OpenAI usage tracker with per-model aggregation\n- capture usage from chat completions, responses API, streaming chunks, and image generation\n- support pricing defaults for gpt-5.2 and gpt-image-1.5 with OPENAI_PRICING_JSON overrides\n- extend generate request/response models with track_openai_usage and openai_usage summary\n- wire tracking through presentation generation pipeline and document env flags\n- add unit tests for pricing, cached tokens, overrides, and unpriced models
Add zstd package to both production and development Docker images so dependencies and runtime paths that rely on zstd support do not fail in containerized environments.
Update built-in OpenAI pricing defaults used by usage tracker to match official rates for gpt-5.2 and gpt-image-1.5, and adjust unit test expectations accordingly.
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.
Summary
This PR adds optional end-to-end OpenAI usage and cost tracking for presentation generation, including LLM and image
generation calls.
What’s included
track_openai_usageinGeneratePresentationRequestopenai_usageinPresentationPathAndEditPathservers/fastapi/services/openai_usage_tracker.pyservers/fastapi/models/openai_usage_cost.pygenerate_presentation_handlerexecution in tracker contextchat.completions(regular + structured + streaming withinclude_usage)responsesAPI (web search path)images.generategpt-5.2andgpt-image-1.5OPENAI_PRICING_JSONTRACK_OPENAI_USAGEOPENAI_PRICING_JSONservers/fastapi/tests/test_openai_usage_tracker.pyAdditional fix
zstdin both Docker images:DockerfileDockerfile.devValidation
uv run pytest -q tests/test_openai_usage_tracker.py→ passedtrack_openai_usage=truereturned populatedopenai_usagewith total USD cost andper-model breakdown.
Backward compatibility
track_openai_usage=true, orTRACK_OPENAI_USAGE=true.