mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-28 00:00:38 +00:00
* fix(vertex_ai): apply regional endpoint uplift on image generation cost path completion_cost had vertex_location but never passed it to the image generation cost router, so a regional_endpoint_uplift_multiplier on a Vertex image row would be ignored. No image row carries the multiplier yet, so nothing is misbilled today. Pass the location through to the Vertex image calculator for both the token-based price and the per-image fallback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(vertex_ai): cover regional image cost through the proxy logging path Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(images): hand image_edit's vertex_location to its cost resolver * test(integration): audit Vertex image regional uplift billing * test(integration): require every spend row after a proxy restart * test(integration): reject extra spend rows after a proxy restart --------- Co-authored-by: Nate Armstrong <narmstrong@Nates-MacBook-Pro.local> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
78 lines
2.6 KiB
Python
78 lines
2.6 KiB
Python
import json
|
|
from datetime import datetime
|
|
from typing import Final
|
|
|
|
import httpx
|
|
import pytest
|
|
import respx
|
|
|
|
import litellm
|
|
from litellm.litellm_core_utils.litellm_logging import Logging
|
|
from litellm.types.utils import CallTypes
|
|
|
|
|
|
def test_image_generation_keeps_an_internal_prefixed_kwarg_out_of_the_provider_request(
|
|
respx_mock: respx.MockRouter,
|
|
) -> None:
|
|
api_base: Final = "http://localhost:12346/v1"
|
|
mock_route: Final = respx_mock.post(url__regex=rf"{api_base}/images/generations.*").mock(
|
|
return_value=httpx.Response(status_code=200, json={"created": 1712697600, "data": [{"b64_json": "aW1n"}]})
|
|
)
|
|
|
|
litellm.image_generation(
|
|
model="openai/gpt-image-1",
|
|
prompt="a red circle",
|
|
api_base=api_base,
|
|
api_key="fake_openai_api_key",
|
|
_litellm_undeclared_sentinel="internal",
|
|
)
|
|
|
|
assert mock_route.called
|
|
sent: Final = json.loads(respx_mock.calls[0].request.content)
|
|
assert "_litellm_undeclared_sentinel" not in sent, sent
|
|
assert sent["prompt"] == "a red circle"
|
|
|
|
|
|
def test_image_edit_prices_a_vertex_deployment_at_its_configured_location(
|
|
respx_mock: respx.MockRouter, monkeypatch: pytest.MonkeyPatch
|
|
) -> None:
|
|
api_base: Final = "http://localhost:12347/generateContent"
|
|
respx_mock.post(api_base).mock(
|
|
return_value=httpx.Response(
|
|
status_code=200,
|
|
json={"candidates": [{"content": {"parts": [{"inlineData": {"mimeType": "image/png", "data": "aW1n"}}]}}]},
|
|
)
|
|
)
|
|
monkeypatch.setitem(
|
|
litellm.model_cost,
|
|
"vertex_ai/gemini-fake-regional-edit-model",
|
|
{
|
|
"litellm_provider": "vertex_ai-language-models",
|
|
"mode": "image_generation",
|
|
"output_cost_per_image": 0.04,
|
|
"regional_endpoint_uplift_multiplier": 1.1,
|
|
},
|
|
)
|
|
|
|
def cost_at(location: str) -> float:
|
|
logging_obj: Final = Logging(
|
|
model="gemini-fake-regional-edit-model",
|
|
messages=[],
|
|
stream=False,
|
|
call_type=CallTypes.image_edit.value,
|
|
start_time=datetime.now(),
|
|
litellm_call_id=f"vertex-edit-{location}",
|
|
function_id="f",
|
|
)
|
|
response: Final = litellm.image_edit(
|
|
model="vertex_ai/gemini-fake-regional-edit-model",
|
|
image=b"\x89PNG\r\n\x1a\nfakepng",
|
|
prompt="make the circle blue",
|
|
api_base=api_base,
|
|
vertex_location=location,
|
|
litellm_logging_obj=logging_obj,
|
|
)
|
|
return logging_obj._response_cost_calculator(result=response)
|
|
|
|
assert cost_at("global") == pytest.approx(0.04)
|
|
assert cost_at("us-central1") == pytest.approx(0.044)
|