fix(api): cost estimate uses active extraction config (closes #406)#407
Merged
Conversation
…d-coded gpt-4o (#406) The cost-estimate label on the ingest workspace showed "Extraction (gpt-4o)" regardless of the actually configured extraction provider, while the same panel's Total row correctly reflected the configured model's pricing — a visible inconsistency that misled operators investigating spend. Root cause was the fallback chain in JobAnalysisService: extraction_model = job_data.get("extraction_model") \ or os.getenv("OPENAI_EXTRACTION_MODEL", "gpt-4o") When job_data lacked an override (normal for the estimate-before- submit flow) and OPENAI_EXTRACTION_MODEL wasn't set, the label defaulted to the hard-coded string. The actual extraction code path loads the active config from kg_api.ai_extraction_config via load_active_extraction_config(), which is the authoritative source. Consult that same helper as the next layer in the fallback so the estimate matches what extraction will actually charge for. The env- var and hard-coded defaults remain as last-resort fallbacks for environments without a populated extraction config.
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.
Closes #406.
Summary
api/app/services/job_analysis.pyhardcoded"gpt-4o"as the final fallback for the cost-estimate model label. When neitherjob_data.extraction_modelnor theOPENAI_EXTRACTION_MODELenv var was set, the estimate panel rendered "Extraction (gpt-4o)" regardless of the actually configured provider — even though the same panel's Total row used the configured provider's pricing (Anthropic Sonnet etc.). Misleading side-by-side discrepancy.Fix: consult
load_active_extraction_config()(the same DB-backed helper the real extraction code path uses) as the middle layer of the fallback chain. Env-var and hard-coded defaults remain as last-resort fallbacks.Test plan
--no-approveagainst a fresh dev env configured for Claude Sonnet. Cost estimate now showsExtraction (claude-sonnet-4-6)(wasExtraction (gpt-4o)before the fix).pytest tests/unit/— 469 passFiles
api/app/services/job_analysis.py— fallback chain now consultsload_active_extraction_config()