feat(api): update API spec from langfuse/langfuse ad16fa0
[!IMPORTANT] Introduces a tiered pricing model in the API, adding new classes for pricing tiers and updating the
Modelclass to support conditional pricing.
- Behavior:
- Introduces tiered pricing model in
Modelclass inmodel.py, replacing flat pricing.- Adds
pricing_tiersfield toModelfor conditional pricing based on usage.- Deprecates
input_price,output_price, andtotal_pricefields inModel.- Models:
- Adds
PricingTier,PricingTierCondition,PricingTierInput, andPricingTierOperatorclasses intypes.- Updates
CreateModelRequestincreate_model_request.pyto supportpricing_tiers.- Imports:
- Updates imports in
__init__.pyfiles to include new pricing tier classes.This description was created by
for 723886ba059edf14e47636690270db034399bf57. 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, andPricingTierOperator - Extended
Modelwithpricing_tiersarray field andcreated_attimestamp - Updated
CreateModelRequestto support optionalpricing_tiersfield - 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_tiersoptional 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