Skip to content

fix: apply custom video pricing from deployment model_info - #21923

Merged
12 commits merged into
BerriAI:litellm_oss_staging_02_23_2026from
AtharvaJaiswal005:fix/custom-video-pricing-not-applied-21907
Feb 24, 2026
Merged

fix: apply custom video pricing from deployment model_info#21923
12 commits merged into
BerriAI:litellm_oss_staging_02_23_2026from
AtharvaJaiswal005:fix/custom-video-pricing-not-applied-21907

Conversation

@AtharvaJaiswal005

Copy link
Copy Markdown
Contributor

Summary

  • Custom pricing set via deployment model_info was not applied for video generation cost calculation (/v1/videos endpoint)
  • video_generation_cost() and default_video_cost_calculator() only looked up the global litellm.model_cost map, ignoring deployment-specific pricing
  • Added optional model_info parameter to both functions, following the existing batch_cost_calculator() pattern
  • In completion_cost(), extract model_info from litellm_logging_obj.litellm_params.metadata when custom_pricing=True and pass it through

Fixes #21907

Changes

  • litellm/llms/openai/cost_calculation.py - Accept optional model_info in video_generation_cost(), skip get_model_info() lookup when provided
  • litellm/cost_calculator.py - Accept optional model_info in default_video_cost_calculator(), use it before global lookup. Extract model_info from litellm_logging_obj in video branch of completion_cost()
  • tests/test_litellm/test_video_generation.py - 3 new tests covering custom pricing through all code paths

Test plan

  • test_video_generation_cost_with_custom_model_info - custom per-second pricing via model_info
  • test_video_generation_cost_custom_model_info_fallback_to_per_second - fallback key in model_info
  • test_video_generation_cost_custom_pricing_through_completion_cost - full flow through completion_cost with mock litellm_logging_obj
  • All 45 existing video generation tests pass
  • All 33 cost calculator tests pass

@vercel

vercel Bot commented Feb 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Feb 23, 2026 1:20pm

Request Review

@greptile-apps

greptile-apps Bot commented Feb 23, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes custom video pricing not being applied for /v1/videos endpoint cost calculations (issue #21907). Previously, video_generation_cost() and default_video_cost_calculator() only looked up the global litellm.model_cost map, ignoring deployment-specific pricing set via model_info.

  • Added optional model_info parameter to video_generation_cost() (in litellm/llms/openai/cost_calculation.py) and default_video_cost_calculator() (in litellm/cost_calculator.py), following the existing batch_cost_calculator() pattern
  • In completion_cost(), the video branch now extracts model_info from litellm_logging_obj.litellm_params.metadata when custom_pricing=True and passes it through to both calculators
  • Added 3 well-structured mock tests covering unit pricing, fallback key, and full completion_cost flow — all without real network calls
  • Provider-specific pricing logic remains within litellm/llms/ (openai) and cost calculation (litellm/cost_calculator.py), consistent with the project's architectural rules

Confidence Score: 5/5

  • This PR is safe to merge — it adds an optional parameter with no breaking changes to existing behavior.
  • The change is minimal, well-scoped, and follows an established pattern (batch_cost_calculator). The new model_info parameter is optional with a default of None, so all existing call sites remain unaffected. The refactoring in default_video_cost_calculator is purely structural (indentation change), and the logic is identical. Three new tests verify the fix without making network calls. No security concerns, no DB queries in the critical path, no provider-specific code outside llms/.
  • No files require special attention

Important Files Changed

Filename Overview
litellm/cost_calculator.py Added model_info parameter to default_video_cost_calculator() and extraction logic in completion_cost() video branch; clean structural refactoring with no behavioral regressions.
litellm/llms/openai/cost_calculation.py Added optional model_info parameter to video_generation_cost() to skip global get_model_info() lookup when deployment-specific pricing is provided; minimal and focused change.
tests/test_litellm/test_video_generation.py Added 3 new mock-only tests covering custom pricing through default_video_cost_calculator and the full completion_cost flow; no real network calls made.

Sequence Diagram

sequenceDiagram
    participant CC as completion_cost()
    participant LO as litellm_logging_obj
    participant VGC as video_generation_cost()
    participant DVCC as default_video_cost_calculator()
    participant GMI as get_model_info() / model_cost

    CC->>CC: Check call_type in _VIDEO_CALL_TYPES
    alt custom_pricing=True & litellm_logging_obj present
        CC->>LO: Extract litellm_params.metadata.model_info
        LO-->>CC: _video_model_info (deployment pricing)
    end

    alt duration_seconds available in usage
        CC->>VGC: model, duration_seconds, model_info
        alt model_info provided
            VGC->>VGC: Use provided model_info directly
        else model_info is None
            VGC->>GMI: get_model_info(model)
            GMI-->>VGC: global model_info
        end
        VGC-->>CC: cost (float)
    else no duration_seconds
        CC->>DVCC: model, duration=0.0, model_info
        alt model_info provided
            DVCC->>DVCC: Use provided model_info directly
        else model_info is None
            DVCC->>GMI: Lookup litellm.model_cost
            GMI-->>DVCC: cost_info
        end
        DVCC-->>CC: cost (float)
    end
Loading

Last reviewed commit: 9506d2f

@greptile-apps greptile-apps Bot 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.

3 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Use Optional[ModelInfo] instead of Optional[dict] and restructure
cost_info narrowing so mypy can properly track non-None state.
@ghost
ghost changed the base branch from main to litellm_oss_staging_02_23_2026 February 24, 2026 04:43
@ghost
ghost merged commit 289e603 into BerriAI:litellm_oss_staging_02_23_2026 Feb 24, 2026
30 checks passed
Sameerlite added a commit that referenced this pull request Mar 3, 2026
* auth_with_role_name add region_name arg for cross-account sts

* update tests to include case with aws_region_name for _auth_with_aws_role

* Only pass region_name to STS client when aws_region_name is set

* Add optional aws_sts_endpoint to _auth_with_aws_role

* Parametrize ambient-credentials test for no opts, region_name, and aws_sts_endpoint

* consistently passing region and endpoint args into explicit credentials irsa

* fix env var leakage

* fix: bedrock openai-compatible imported-model should also have model arn encoded

* fix: custom pricing not applied for /v1/videos endpoint (#21907)

* fix: resolve mypy type errors for video pricing model_info parameter

Use Optional[ModelInfo] instead of Optional[dict] and restructure
cost_info narrowing so mypy can properly track non-None state.

---------

Co-authored-by: An Tang <ta@stripe.com>
Co-authored-by: Sameer Kankute <sameer@berri.ai>
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
…1923)

* auth_with_role_name add region_name arg for cross-account sts

* update tests to include case with aws_region_name for _auth_with_aws_role

* Only pass region_name to STS client when aws_region_name is set

* Add optional aws_sts_endpoint to _auth_with_aws_role

* Parametrize ambient-credentials test for no opts, region_name, and aws_sts_endpoint

* consistently passing region and endpoint args into explicit credentials irsa

* fix env var leakage

* fix: bedrock openai-compatible imported-model should also have model arn encoded

* fix: custom pricing not applied for /v1/videos endpoint (BerriAI#21907)

* fix: resolve mypy type errors for video pricing model_info parameter

Use Optional[ModelInfo] instead of Optional[dict] and restructure
cost_info narrowing so mypy can properly track non-None state.

---------

Co-authored-by: An Tang <ta@stripe.com>
Co-authored-by: Sameer Kankute <sameer@berri.ai>
This pull request was closed.
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.

[Bug]: Custom pricing for /v1/videos model is not applied, so user budget is not reduced

3 participants