litellm icon indicating copy to clipboard operation
litellm copied to clipboard

[Bug]: Native Vertex Live transcription loses duration-based cost without usageMetadata

Open emerzon opened this issue 3 days ago • 1 comments

Description

A successful native /vertex_ai/live transcription can finish without a usageMetadata message. Vanilla LiteLLM then dispatches a generic logging payload, but no typed usage or duration-based price is carried forward for that session. A time-priced transcription can therefore be under-attributed even though the proxy forwarded the PCM audio.

Expected behavior is to derive usage and cost from the forwarded audio duration when a time rate is available, and retain an explicit unavailable-usage state otherwise. The proxy should keep its existing logging dispatch.

Config

Enable spend logs on a proxy with access to Vertex AI. Connect to the native Vertex Live pass-through route and use gemini-3.5-transcribe-live. To rule out alias lookup, send the full model resource in setup.model, using the project and location that serve the deployment:

projects/PROJECT/locations/LOCATION/publishers/google/models/gemini-3.5-transcribe-live

LiteLLM Version

Vanilla upstream main at 4072d5babc. Reproduced with Python 3.12, dependencies from upstream's lockfile, and the original native extension from the unit-test CI artifact for that commit. The next main change, db3c58afa7, only touched PR guidance files.

Steps to Repro

Run from an installed checkout of the pinned upstream commit with Python 3.12 and its proxy/test dependencies. Save the following as repro.py and run python repro.py.

import asyncio
from datetime import datetime, timezone
from unittest.mock import MagicMock

import httpx
from litellm.proxy.pass_through_endpoints.success_handler import PassThroughEndpointLogging

async def capture(**kwargs):
    record = kwargs["standard_logging_response_object"]
    if isinstance(record, dict):
        print("Dispatched:", type(record).__name__, sorted(record))
    else:
        print("Dispatched:", type(record).__name__, f"total_tokens={record.usage.total_tokens}")

async def main():
    logger = PassThroughEndpointLogging(log_dispatch=capture)
    now = datetime.now(timezone.utc)
    transcript = {"serverContent": {"inputTranscription": {"text": "hello"}}}
    usage = {"usageMetadata": {"promptTokenCount": 10, "totalTokenCount": 10}}
    handshake = httpx.Response(101, request=httpx.Request(
        "GET", "https://example.invalid/vertex_ai/live"
    ))
    for frames in ([transcript], [transcript, usage]):
        print("Provider sent usageMetadata:", len(frames) == 2)
        await logger.pass_through_async_success_handler(
            httpx_response=handshake,
            response_body=frames,
            logging_obj=MagicMock(model_call_details={}),
            url_route="/vertex_ai/live",
            result="",
            start_time=now,
            end_time=now,
            cache_hit=False,
            request_body={},
            passthrough_logging_payload={},
            custom_llm_provider="vertex_ai",
            model="gemini-3.5-transcribe-live",
        )

asyncio.run(main())

Observed on vanilla upstream at the pinned commit, excluding LiteLLM's startup banner:

Provider sent usageMetadata: False
Dispatched: dict ['response']
Provider sent usageMetadata: True
Dispatched: ModelResponse total_tokens=10

The no-usage case does dispatch a generic {'response': ...} payload. This corrects the earlier claim that no logging dispatch or spend row occurs. The usage-bearing control dispatches a typed ModelResponse; without provider usage, the typed usage and any duration-derived cost are absent at this boundary. This isolated script does not establish whether the generic payload becomes a database row. A separate live downstream test priced a transcription session from forwarded PCM duration. Upstream fallback dispatch. Issue #41589 is alias lookup when usage exists; PR #38563 is the distinct /v1/realtime bridge.

Which part of LiteLLM is this about?

Spend tracking: spend logs, cost attribution, usage reports

emerzon avatar Dec 03 '26 02:12 emerzon

Hi, I would like to take this on. Please assign it to me if that works. The gap looks to be in the native Vertex Live pass-through: when a transcription session ends without a usageMetadata message, the generic logging payload is dispatched but no typed usage is built, so the duration-based cost is lost. I will reproduce the no-usageMetadata session first with a mocked provider, then derive usage and cost from the forwarded audio duration when a time rate is available, keeping the existing logging dispatch and an explicit unavailable-usage state otherwise. I will cover the fix with a unit test for the no-usageMetadata session and the existing spend logging tests.

techaurah avatar Dec 03 '26 07:12 techaurah