feat(api): update API spec from langfuse/langfuse ad16fa0 #1454
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Important
Introduces a tiered pricing model in the API, adding new classes for pricing tiers and updating the
Modelclass to support conditional pricing.Modelclass inmodel.py, replacing flat pricing.pricing_tiersfield toModelfor conditional pricing based on usage.input_price,output_price, andtotal_pricefields inModel.PricingTier,PricingTierCondition,PricingTierInput, andPricingTierOperatorclasses intypes.CreateModelRequestincreate_model_request.pyto supportpricing_tiers.__init__.pyfiles to include new pricing tier classes.This description was created by
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
PricingTier,PricingTierCondition,PricingTierInput, andPricingTierOperatorModelwithpricing_tiersarray field andcreated_attimestampCreateModelRequestto support optionalpricing_tiersfieldinputPrice,outputPrice,totalPrice,prices) as deprecated in favor of tiered pricingArchitecture
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:
pricing_tiersoptional in creation requestsNo issues found - all code is auto-generated, follows consistent patterns, has comprehensive documentation, and maintains proper backward compatibility.
Confidence Score: 5/5
Important Files Changed
File Analysis
PricingTiermodel with comprehensive documentation for tiered pricing supportPricingTierConditionmodel for regex-based usage threshold matchingpricing_tiersfield andcreated_atfield toModel, updated documentation to reflect tiered pricing supportpricing_tiersfield to model creation request, updated price field documentation to mark as deprecatedSequence 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