Skip to content

feat(sdk): Add Claude 3 and Gemini 1.5 Flash to pricing table - #33

Open
HeaTTap wants to merge 3 commits into
PxA-Labs:mainfrom
HeaTTap:feat/pricing-table-claude-gemini
Open

feat(sdk): Add Claude 3 and Gemini 1.5 Flash to pricing table#33
HeaTTap wants to merge 3 commits into
PxA-Labs:mainfrom
HeaTTap:feat/pricing-table-claude-gemini

Conversation

@HeaTTap

@HeaTTap HeaTTap commented Jul 30, 2026

Copy link
Copy Markdown

Description

This PR adds model pricing mappings for claude-3-haiku, claude-3-opus, and gemini-1.5-flash to packages/sdk/agentscope/_pricing.py as requested in issue #29.

Key Changes:

  • Added pricing mappings for:
    • claude-3-haiku: $0.25 input / $1.25 output per 1M tokens
    • claude-3-opus: $15.00 input / $75.00 output per 1M tokens
    • gemini-1.5-flash: $0.075 input / $0.30 output per 1M tokens
  • Added get_model_pricing helper supporting prefix-based lookup for minor and date-pinned model versions (e.g., claude-3-haiku-20240307, gemini-1.5-flash-001, gpt-4o-2024-05-13).
  • Updated packages/sdk/tests/test_sdk.py with unit tests for new model rates and date-pinned version matching.

Closes #29

Summary by CodeRabbit

  • New Features

    • Added pricing support for Claude Haiku, Claude Opus, and Gemini Flash models.
    • Added recognition for case variations and version- or date-specific model names.
    • Improved estimated cost calculations using prompt and completion token usage.
  • Bug Fixes

    • Unknown models now return a zero estimated cost.
    • Missing token counts default to zero.
    • Invalid negative token counts are now rejected.

- Add pricing lookup mappings for claude-3-haiku, claude-3-opus, and gemini-1.5-flash
- Support pricing lookup matching for minor and date-pinned versions
- Add unit tests verifying cost calculation for new models and date-pinned model names

Closes PxA-Labs#29
@github-actions github-actions Bot added pkg: sdk type: feature Auto-generated label for type: feature labels Jul 30, 2026
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: bd84e034-308b-4d84-8d83-99c4dec02eba

📥 Commits

Reviewing files that changed from the base of the PR and between b8ab2cb and 1feb892.

📒 Files selected for processing (2)
  • packages/sdk/agentscope/_pricing.py
  • packages/sdk/tests/test_sdk.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/sdk/tests/test_sdk.py
  • packages/sdk/agentscope/_pricing.py

📝 Walkthrough

Walkthrough

The SDK adds Claude 3 and Gemini 1.5 Flash pricing. Model lookup supports case-insensitive matching for versioned identifiers. Cost calculation resolves rates, handles missing models and token counts, and rejects negative counts. Tests cover aliases and validation.

Changes

Model pricing support

Layer / File(s) Summary
Pricing catalog and model lookup
packages/sdk/agentscope/_pricing.py
Adds Claude and Gemini pricing entries. Resolves exact and delimited version-suffixed model names without matching unrelated names.
Cost calculation and validation
packages/sdk/agentscope/_pricing.py, packages/sdk/tests/test_sdk.py
Calculates costs from resolved rates, handles missing pricing and token counts, rejects negative counts, and tests aliases and validation behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning Negative token rejection and altered unknown-model handling are not required by linked issue #29. Remove unrelated token-validation and unknown-model behavior changes, or link an issue that requires them.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the addition of Claude 3 and Gemini 1.5 Flash pricing support.
Linked Issues check ✅ Passed The changes add the required model mappings and support minor and date-pinned version lookup.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
packages/sdk/tests/test_sdk.py (1)

15-27: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add regression tests for lookup boundaries and casing.

The new tests cover lowercase versioned names, but not the documented case-insensitive behavior or rejection of unrelated names that merely share a prefix. Add cases such as an uppercase date-pinned identifier and an invalid non-delimited suffix.

Suggested additions
+    assert calculate_cost("CLAUDE-3-HAIKU-20240307", 1_000_000, 1_000_000) == 1.50
+    assert calculate_cost("claude-3-haikuish", 100, 100) == 0.0
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/sdk/tests/test_sdk.py` around lines 15 - 27, Extend the
calculate_cost regression tests to verify case-insensitive matching with an
uppercase date-pinned model identifier and to reject an unrelated name with a
non-delimited suffix that merely shares a supported model prefix. Keep the
existing pricing assertions and use the established expected result or error
behavior for each boundary case.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/sdk/agentscope/_pricing.py`:
- Around line 49-53: Update the token normalization in the pricing calculation
so prompt_tokens and completion_tokens remain zero when None, but raise
ValueError for either negative count before computing input_cost or output_cost.
Use the existing input_tokens and output_tokens flow to validate both values
before the price calculations.
- Around line 25-27: Update the model-prefix matching loop in the pricing lookup
to require a hyphen separator immediately after the matched key, preventing
unrelated names such as gpt-4orange or claude-3-haikuish from matching. Preserve
the existing longest-key-first ordering and return behavior for valid versioned
identifiers.

---

Nitpick comments:
In `@packages/sdk/tests/test_sdk.py`:
- Around line 15-27: Extend the calculate_cost regression tests to verify
case-insensitive matching with an uppercase date-pinned model identifier and to
reject an unrelated name with a non-delimited suffix that merely shares a
supported model prefix. Keep the existing pricing assertions and use the
established expected result or error behavior for each boundary case.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a115e9d5-1576-4590-9092-883bbf754d8d

📥 Commits

Reviewing files that changed from the base of the PR and between 320e819 and b8ab2cb.

📒 Files selected for processing (2)
  • packages/sdk/agentscope/_pricing.py
  • packages/sdk/tests/test_sdk.py

Comment thread packages/sdk/agentscope/_pricing.py
Comment thread packages/sdk/agentscope/_pricing.py Outdated

@archittmittal archittmittal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you for the contribution! The changes look great and solve Issue #29 and Sub-Issue 6.1.

One minor request: could you please expand the test cases in packages/sdk/tests/test_sdk.py to also cover:

  1. Case-insensitivity verification using an uppercase date-pinned model name (e.g., CLAUDE-3-HAIKU-20240307).
  2. Ensuring that non-delimited suffixes that share a model prefix but are unrelated (e.g., claude-3-haikuish) do not match and return 0.0.

Once these tests are added, we will merge the PR!

@archittmittal

Copy link
Copy Markdown
Collaborator

Added the requested test cases in a commit here. Please pull from the branch to include in your PR:

#33

Additional test cases added:

  • claude-3-haikuish non-delimited suffix => 0.0
  • CLAUDE-3-HAIKU-20240307 uppercase date-pinned => 1.50
  • GEMINI-1.5-PRO uppercase base model => 6.25
  • GPT-4O-2024-05-13 uppercase known model => 12.50

You can pull the branch with:

git fetch origin feat/pricing-table-claude-gemini
git cherry-pick 412d334

Or just add these test cases manually to your packages/sdk/tests/test_sdk.py

… test cases

Signed-off-by: HeaTTap <heatver@gmail.com>
@HeaTTap
HeaTTap requested a review from purvanshjoshi as a code owner August 6, 2026 09:09
@HeaTTap

HeaTTap commented Aug 6, 2026

Copy link
Copy Markdown
Author

Thanks @archittmittal! I have expanded the test suite in packages/sdk/tests/test_sdk.py to cover both requested edge cases:

  1. Case-Insensitivity Verification: Added assertion for uppercase date-pinned identifier (CLAUDE-3-HAIKU-20240307).
  2. Non-Delimited Suffix Rejection: Added assertion for non-delimited model name suffix (claude-3-haikuish), verifying it returns 0.0.

@purvanshjoshi purvanshjoshi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed on behalf of @purvanshjoshi. All CI checks pass (Test Python SDK, Test FastAPI Server, Lint, CodeQL). Verified the current head addresses every prior review comment:

  • Hyphen-separator prefix guard (startswith(f{key}-)) — rejects gpt-4orange / claude-3-haikuish false matches (CodeRabbit inline + archittmittal request).
  • Negative token counts now raise ValueError; None tokens default to 0 (CodeRabbit inline).
  • Regression tests cover uppercase date-pinned identifiers and non-delimited suffix rejection (both requests).

Approving. One non-blocking note for a follow-up: the new prefix matching means gpt-4o-mini now resolves to gpt-4o pricing (previously 0.0), which will overstate cost ~10x for that model. Consider adding an explicit gpt-4o-mini entry (or ordering a more specific key first) — this also applies to the equivalent logic in #66.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: sdk type: feature Auto-generated label for type: feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(sdk): Add support for Claude 3 (Haiku/Opus) and Gemini 1.5 Flash in pricing table

3 participants