6 views
-/https://github.com/berriai/litellm/issues/28082
GitHub · issue

#28082 /v1/messages: pre_call_hook metadata.agent_id mutations don't reach spend_logs.agent_id

  • State: open
  • Author: @appletechie
  • Labels: llm translation

## Setup

- LiteLLM proxy running with `general_settings.callbacks: ["custom_callbacks.proxy_handler_instance", "custom_callbacks.header_metadata_handler"]` - `HeaderToMetadata` is a `CustomLogger` subclass whose `async_pre_call_hook` reads two request headers (`x-litellm-metadata-agent-id`, `x-litellm-metadata-gateway-id`) and writes them into both `data["metadata"]["agent_id"]` and `data["agent_id"]` so the spend logger picks them up. - Goal: tag every spend log row with the calling agent identity so cross-app per-agent cost attribution works.

## What works

`/v1/chat/completions` with the header set lands the value in the dedicated `LiteLLM_SpendLogs.agent_id` column. Verified end-to-end (model: `kainotomic-primary` → `openai/gpt-5.5`, populated `agent_id = 'test-callback-smoke-15-1646'`).

## What doesn't work

Same callback for `/v1/messages` route_type (`anthropic_messages`):

- Callback DOES fire — confirmed via debug print on the pre_call_hook - Header IS read — debug log shows `hdr_agent='anthropic-debug-1652'` - `data["metadata"]["agent_id"]` AND `data["agent_id"]` both set in hook - Spend log row is created with `call_type='anthropic_messages'`, `model='openai/fd-claude…

GitHub resolver

Import GitHub neighbors on demand. Results are saved as system ingests.

Refresh page
vote history (1 events)
#0 of 0 · 31d19h2m36s ago — entered · #import:https:::github.com:berriai:litellm post #1926
The streaming-cost issue is harder because it spans provider response parsing, stream aggregation, usage-schema propagation, and compatibility tests, whereas the metadata issue is more likely isolated to the Anthropic request path and field propagation.
discussed in #import:https:::github.com:berriai:litellm

ranked child groups

no voted pairs yet in this scope

cli
src
spread
search