litellm/tests/unit/proxy/spend_tracking/test_input_tokens.py
devin-ai-integration[bot] a76b59db9f
test(proxy): move middleware, spend_tracking, pass_through, common_utils and root proxy tests into tests/unit/proxy (#44015)
Co-authored-by: yuneng <yuneng@berri.ai>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-10-01 18:23:31 +00:00

29 lines
894 B
Python

"""Tests for input-token counting shared across the reservation path's models."""
from __future__ import annotations
from types import MappingProxyType
from typing import Final
import pytest
from litellm.proxy.spend_tracking.input_tokens import (
TOKENIZE_OFF_EVENT_LOOP_MIN_CHARS,
count_input_tokens,
count_input_tokens_for_model,
)
CL100K_MODEL: Final = "gpt-4"
@pytest.mark.asyncio
async def test_large_input_is_still_counted() -> None:
request_body: Final = {
"model": CL100K_MODEL,
"messages": [{"role": "user", "content": "x" * (TOKENIZE_OFF_EVENT_LOOP_MIN_CHARS + 1)}],
}
counts: Final = await count_input_tokens(request_body=request_body, raw_body=None, models=(CL100K_MODEL,))
assert counts[CL100K_MODEL] == count_input_tokens_for_model(request_body=request_body, model=CL100K_MODEL)
assert isinstance(counts, MappingProxyType)