Skip to content

[Good First Issue] Port GPT-4 Turbo cost tracking fix to Python SDK #52

Description

@nagasatish007

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

  1. Update get_model_pricing() in the Python SDK to use longest-prefix matching
  2. Add enable_cost_tracking option to the Python OpenAI client
  3. Expose response.cost as a numeric field
  4. Add tests for GPT-4 Turbo preview and dated model aliases

Acceptance criteria

  • get_model_pricing() uses longest-prefix match
  • gpt-4-turbo-preview returns Turbo pricing, not GPT-4 pricing
  • Tests pass: pytest tests/cost/
  • Behavior matches TypeScript SDK exactly

Difficulty

🟢 Beginner — direct port from TypeScript, logic is straightforward

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomershelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions