mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-15 23:31:29 +00:00
fix(together_ai): route image cost calculation to output_cost_per_image so Seedream spend is tracked
This commit is contained in:
parent
ea64cd5d15
commit
7985e7c3a1
3 changed files with 63 additions and 0 deletions
|
|
@ -1137,6 +1137,15 @@ class CostCalculatorUtils:
|
|||
model=model,
|
||||
image_response=completion_response,
|
||||
)
|
||||
elif custom_llm_provider == litellm.LlmProviders.TOGETHER_AI.value:
|
||||
from litellm.llms.together_ai.image_generation.cost_calculator import (
|
||||
cost_calculator as together_ai_image_cost_calculator,
|
||||
)
|
||||
|
||||
return together_ai_image_cost_calculator(
|
||||
model=model,
|
||||
image_response=completion_response,
|
||||
)
|
||||
elif custom_llm_provider == litellm.LlmProviders.COMETAPI.value:
|
||||
from litellm.llms.cometapi.image_generation.cost_calculator import (
|
||||
cost_calculator as cometapi_image_cost_calculator,
|
||||
|
|
|
|||
12
litellm/llms/together_ai/image_generation/cost_calculator.py
Normal file
12
litellm/llms/together_ai/image_generation/cost_calculator.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import litellm
|
||||
from litellm.types.utils import ImageResponse
|
||||
|
||||
|
||||
def cost_calculator(model: str, image_response: ImageResponse) -> float:
|
||||
model_info = litellm.get_model_info(
|
||||
model=model,
|
||||
custom_llm_provider=litellm.LlmProviders.TOGETHER_AI.value,
|
||||
)
|
||||
output_cost_per_image = model_info.get("output_cost_per_image") or 0.0
|
||||
num_images = len(image_response.data) if image_response.data else 0
|
||||
return output_cost_per_image * num_images
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
import os
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
sys.path.insert(0, os.path.abspath("../../../../.."))
|
||||
|
||||
os.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True"
|
||||
|
||||
import litellm
|
||||
|
||||
litellm.model_cost = litellm.get_model_cost_map(url="")
|
||||
from litellm.llms.together_ai.image_generation.cost_calculator import cost_calculator
|
||||
from litellm.types.utils import ImageObject, ImageResponse
|
||||
|
||||
|
||||
def test_seedream_pricing_registered():
|
||||
info = litellm.get_model_info(
|
||||
model="ByteDance-Seed/Seedream-4.0",
|
||||
custom_llm_provider=litellm.LlmProviders.TOGETHER_AI.value,
|
||||
)
|
||||
assert info["output_cost_per_image"] == 0.03
|
||||
assert info["mode"] == "image_generation"
|
||||
|
||||
|
||||
def test_cost_calculator_scales_with_image_count():
|
||||
image_response = ImageResponse(
|
||||
data=[ImageObject(url="https://x/1.png"), ImageObject(url="https://x/2.png")]
|
||||
)
|
||||
cost = cost_calculator(model="ByteDance-Seed/Seedream-4.0", image_response=image_response)
|
||||
assert cost == pytest.approx(0.06)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("call_type", ["image_generation", "image_edit"])
|
||||
def test_completion_cost_routes_together_ai_image_calls(call_type):
|
||||
image_response = ImageResponse(data=[ImageObject(url="https://x/1.png")])
|
||||
cost = litellm.completion_cost(
|
||||
completion_response=image_response,
|
||||
model="together_ai/ByteDance-Seed/Seedream-4.0",
|
||||
call_type=call_type,
|
||||
)
|
||||
assert cost == pytest.approx(0.03)
|
||||
Loading…
Add table
Reference in a new issue