Description
Port the longest-prefix model pricing fix from the TypeScript SDK (PR #2) to the Python SDK.
Context
In TypeScript, gpt-4-turbo-preview was matching gpt-4 pricing ($0.03/1K) instead of gpt-4-turbo pricing ($0.01/1K) — a 3x overcharge. The fix uses longest-prefix matching (sort by key length descending).
TypeScript PR: agentguard-ai/tealtiger-typescript-prod#2
What to change
- Update
get_model_pricing() in the Python SDK to use longest-prefix matching
- Add
enable_cost_tracking option to the Python OpenAI client
- Expose
response.cost as a numeric field
- Add tests for GPT-4 Turbo preview and dated model aliases
Acceptance criteria
Difficulty
🟢 Beginner — direct port from TypeScript, logic is straightforward
Description
Port the longest-prefix model pricing fix from the TypeScript SDK (PR #2) to the Python SDK.
Context
In TypeScript,
gpt-4-turbo-previewwas matchinggpt-4pricing ($0.03/1K) instead ofgpt-4-turbopricing ($0.01/1K) — a 3x overcharge. The fix uses longest-prefix matching (sort by key length descending).TypeScript PR: agentguard-ai/tealtiger-typescript-prod#2
What to change
get_model_pricing()in the Python SDK to use longest-prefix matchingenable_cost_trackingoption to the Python OpenAI clientresponse.costas a numeric fieldAcceptance criteria
get_model_pricing()uses longest-prefix matchgpt-4-turbo-previewreturns Turbo pricing, not GPT-4 pricingpytest tests/cost/Difficulty
🟢 Beginner — direct port from TypeScript, logic is straightforward