Skip to content

Conversation

@langfuse-bot
Copy link
Collaborator

@langfuse-bot langfuse-bot commented Nov 26, 2025

Important

Introduces a tiered pricing model in the API, adding new classes for pricing tiers and updating the Model class to support conditional pricing.

  • Behavior:
    • Introduces tiered pricing model in Model class in model.py, replacing flat pricing.
    • Adds pricing_tiers field to Model for conditional pricing based on usage.
    • Deprecates input_price, output_price, and total_price fields in Model.
  • Models:
    • Adds PricingTier, PricingTierCondition, PricingTierInput, and PricingTierOperator classes in types.
    • Updates CreateModelRequest in create_model_request.py to support pricing_tiers.
  • Imports:
    • Updates imports in __init__.py files to include new pricing tier classes.

This description was created by Ellipsis for 723886b. You can customize this summary. It will automatically update as commits are pushed.

Disclaimer: Experimental PR review

Greptile Overview

Greptile Summary

This PR introduces tiered pricing support for model definitions, enabling accurate cost tracking for LLM providers with usage-based pricing variations.

Key Changes

  • Added four new types: PricingTier, PricingTierCondition, PricingTierInput, and PricingTierOperator
  • Extended Model with pricing_tiers array field and created_at timestamp
  • Updated CreateModelRequest to support optional pricing_tiers field
  • Marked legacy flat pricing fields (inputPrice, outputPrice, totalPrice, prices) as deprecated in favor of tiered pricing
  • All changes are auto-generated from the upstream API specification

Architecture

The tiered pricing system uses priority-based matching: tiers are evaluated in ascending priority order (lower numbers first), with the first tier where all conditions match being selected. Each model must have exactly one default tier (priority 0, no conditions) as a fallback. Conditional tiers use regex patterns to match against usage detail keys, summing matching values and comparing against thresholds.

Backward Compatibility

The implementation maintains backward compatibility by:

  • Keeping legacy price fields populated from the default tier
  • Making pricing_tiers optional in creation requests
  • Supporting both flat pricing (legacy) and tiered pricing (new) approaches

No issues found - all code is auto-generated, follows consistent patterns, has comprehensive documentation, and maintains proper backward compatibility.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk - all code is auto-generated from the API spec with no manual changes
  • Perfect score given because: (1) all files are auto-generated by Fern from the API specification with no manual modifications, (2) changes follow consistent patterns across the codebase, (3) comprehensive documentation is included for all new types, (4) backward compatibility is maintained through optional fields and deprecated markers, (5) no logical errors or syntax issues present, (6) imports are properly organized at module level, (7) the changes represent a well-designed additive feature that doesn't break existing functionality
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
langfuse/api/resources/commons/types/pricing_tier.py 5/5 added new PricingTier model with comprehensive documentation for tiered pricing support
langfuse/api/resources/commons/types/pricing_tier_condition.py 5/5 added PricingTierCondition model for regex-based usage threshold matching
langfuse/api/resources/commons/types/model.py 5/5 added pricing_tiers field and created_at field to Model, updated documentation to reflect tiered pricing support
langfuse/api/resources/models/types/create_model_request.py 5/5 added optional pricing_tiers field to model creation request, updated price field documentation to mark as deprecated

Sequence Diagram

sequenceDiagram
    participant Client
    participant API
    participant Model
    participant PricingTier
    participant PricingTierCondition

    Note over Client,PricingTierCondition: Creating a Model with Tiered Pricing
    
    Client->>API: POST /models with CreateModelRequest
    Note over Client,API: Contains pricing_tiers array with<br/>default tier + conditional tiers
    
    API->>Model: Create Model instance
    Model->>Model: Validate exactly one default tier exists
    Model->>Model: Store pricing_tiers array
    Model->>Model: Populate legacy prices field from default tier
    API-->>Client: Return Model with pricing_tiers

    Note over Client,PricingTierCondition: Cost Calculation with Tier Matching
    
    Client->>Model: Calculate cost for usage
    Note over Client,Model: Usage details: {input_tokens: 250000, output_tokens: 5000}
    
    Model->>PricingTier: Evaluate tiers by priority (1, 2, 3...)
    
    loop For each tier (ascending priority)
        PricingTier->>PricingTierCondition: Check all conditions
        
        alt All conditions match
            PricingTierCondition->>PricingTier: Conditions satisfied
            PricingTier->>Model: Use this tier's prices
            Model-->>Client: Return calculated cost
        else Conditions don't match
            PricingTierCondition->>PricingTier: Conditions not satisfied
            PricingTier->>PricingTier: Continue to next tier
        end
    end
    
    alt No conditional tier matched
        PricingTier->>Model: Use default tier (priority 0)
        Model-->>Client: Return calculated cost
    end
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

10 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@hassiebp hassiebp merged commit 8ceb236 into main Dec 1, 2025
12 checks passed
@hassiebp hassiebp deleted the api-spec-bot-ad16fa0 branch December 1, 2025 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants