litellm/litellm/types
ishaan-berri 14c0a2b3e2
feat(prometheus): emit per-token-type detail metrics (LIT-3220) (#28372) (#28378)
* feat(prometheus): emit per-token-type detail metrics (LIT-3220) (#28372)

Adds five sparse counter metrics that break out the token detail
fields providers already report in `usage.prompt_tokens_details` and
`usage.completion_tokens_details`:

  - litellm_input_cached_tokens_metric            (provider prompt-cache reads)
  - litellm_input_cache_creation_tokens_metric    (Anthropic prompt-cache writes)
  - litellm_input_audio_tokens_metric             (audio input tokens)
  - litellm_output_reasoning_tokens_metric        (reasoning tokens)
  - litellm_output_audio_tokens_metric            (audio output tokens)

These are additive — existing input/output/total counters are
unchanged, so no dashboards break. Each new counter is only
incremented when the underlying detail is populated and > 0, keeping
scrape output sparse for providers that don't report a given field.

Data is read from the canonical Usage dict that
`get_standard_logging_object_payload` already attaches at
`standard_logging_payload["metadata"]["usage_object"]`, so no new
plumbing through the logging pipeline is required.

Tests: 10 new unit tests covering registration, label-set parity,
all-types increment, zero/None/negative skip behaviour, and the
no-metadata/no-usage_object no-op paths.

Closes LIT-3220

Co-authored-by: shin-berri <shin-laptop@berri.ai>
Co-authored-by: yuneng-jiang <yuneng@berri.ai>
Co-authored-by: Krrish Dholakia <krrishdholakia@berri.ai>
Co-authored-by: Claude <noreply@anthropic.com>

* chore: remove proof folder image

---------

Co-authored-by: oss-agent-shin <ext-agent-shin@berri.ai>
Co-authored-by: shin-berri <shin-laptop@berri.ai>
Co-authored-by: yuneng-jiang <yuneng@berri.ai>
Co-authored-by: Krrish Dholakia <krrishdholakia@berri.ai>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Ishaan Jaffer <ishaanjaffer0324@gmail.com>
2026-05-23 12:17:42 -07:00
..
containers feat(containers): Azure routing, managed container IDs, delete response parsing (#25287) 2026-04-11 09:21:01 -07:00
google_genai fix(mypy): fix scattered 1-off type errors across 14 files 2026-03-13 00:08:57 +00:00
images merge: resolve conflicts between main and litellm_oss_staging_03_11_2026 2026-03-12 09:38:31 -03:00
integrations feat(prometheus): emit per-token-type detail metrics (LIT-3220) (#28372) (#28378) 2026-05-23 12:17:42 -07:00
interactions feat(interactions): migrate to Google Interactions API steps schema (May 2026) (#28153) 2026-05-20 13:32:12 -07:00
litellm_core_utils include server_tool_use in streaming usage (#16826) 2025-11-25 14:50:17 -08:00
llms CI: copy of #25177 (OCI GenAI: embeddings, streaming/reasoning fixes, model catalog) (#28223) 2026-05-23 12:15:41 -07:00
management_endpoints feat: routing groups ui 2026-05-04 18:09:14 -07:00
mcp_server feat(mcp): add delegate_auth_to_upstream flag for PKCE passthrough (#27834) 2026-05-13 12:06:13 -07:00
passthrough_endpoints refactor: define pass-through custom body state key in types module 2026-04-11 15:26:44 -07:00
prompts style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
proxy [Feat] Add endpoint for bulk key updates for team (#26468) 2026-05-09 19:32:16 +00:00
responses refactor: extract duplicated stdout/stderr → logs logic to shared helper 2026-03-18 22:05:27 -03:00
secret_managers style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00
videos style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
access_group.py allow editing of access group names 2026-02-13 17:03:41 -08:00
adapter.py feat(anthropic_adapter.py): support for translating anthropic params to openai format 2024-07-10 00:32:28 -07:00
agents.py Gemini managed agents support (#28270) 2026-05-19 16:02:03 -07:00
caching.py fix(caching): preserve prompt_tokens_details through embedding cache round-trip (#26653) 2026-04-28 08:25:11 -07:00
completion.py fix: correct CompletionRequest messages type to match OpenAI API spec (#12980) 2025-07-28 16:47:20 -07:00
compression.py Prompt Compression - add it to the proxy (#25729) 2026-04-20 15:08:00 -07:00
embedding.py Removed config dict type definition 2024-05-17 10:39:00 +08:00
files.py style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00
fine_tuning.py (feat) POST /fine_tuning/jobs support passing vertex specific hyper params (#7490) 2025-01-01 07:44:48 -08:00
guardrails.py feat(guardrails): add Microsoft Purview DLP guardrail (#24966) 2026-05-22 15:59:04 -07:00
mcp.py feat(mcp): add OBO MCP Auth (#27421) 2026-05-07 15:35:21 -07:00
memory_management.py feat(proxy): add /v1/memory CRUD endpoints (#26218) 2026-04-24 18:38:07 -07:00
policy_engine.py [Feat] New LiteLLM Policy engine - create policies to manage guardrails, conditions - permissions per Key, Team (#19612) 2026-01-22 19:49:53 -08:00
rag.py style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00
realtime.py address greptile review feedback (greploop iteration 2) 2026-03-12 18:53:22 +05:30
rerank.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
router.py Litellm oss staging (#28161) 2026-05-18 16:27:44 -07:00
scheduler.py Squashed commit of the following: (#9709) 2025-04-02 21:24:54 -07:00
search.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
services.py [Fix] CI/CD - mypy & check_code_and_doc_quality & mcp_testing (#17920) 2025-12-13 08:18:43 -08:00
tag_management.py style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00
tool_management.py Bug Fix: auto-inject prompt caching support for Gemini models (#21881) 2026-03-03 20:25:35 -08:00
utils.py feat: add guardrail violation span attributes and fix missing spans on pre-call blocks (#28364) 2026-05-21 15:49:42 -07:00
vector_store_files.py Vector store files Stable Release (#16643) 2025-11-15 13:00:33 -08:00
vector_stores.py style: run black formatter on entire codebase 2026-03-11 17:07:57 -03:00