You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(closes OPEN-11695): normalize LangChain provider/model and emit usageDetails so cost estimation stops returning $0
LangChain traces reported the raw class-name provider string (e.g.
"chat-google-generative-ai") and the Gemini Developer API "models/" model
prefix, neither recognized by the cost table -- so cost estimation silently
returned $0 with empty costDetails/usageDetails.
- Provider: prefer LangChain's standardized `ls_provider` metadata over the
noisier `_type`, resolving both through a dual-keyed map that now covers the
major LangChain chat providers (OpenAI, Azure, Anthropic, Google, Bedrock,
Cohere, Ollama, Mistral, Groq, DeepSeek, Perplexity, xAI). Unknown
identifiers fall through to the raw string (no regression, no wrong cost).
- Model: strip a leading "models/" prefix so Gemini names match the cost table.
- usageDetails: emit a per-category token map on the chat-completion step so the
backend prices per category and populates costDetails. Granular categories
from LangChain's usage_metadata are mapped to the cost table's keys
(cache_read -> cached_tokens, cache_creation -> cache_creation_tokens,
audio -> audio_input_tokens/audio_output_tokens) and subtracted from the
input/output base to keep the partition non-overlapping; reasoning stays
folded into output_tokens. ChatCompletionStep gains an optional usage_details
field, serialized only when set -- other integrations are unaffected.
Verified end-to-end against the live pipeline with the customer's inputs:
- no caching: provider=Google, model=gemini-3.5-flash, cost=0.2003475,
costDetails={input_tokens, output_tokens}.
- with 10000 cached input tokens: usageDetails={input_tokens:17131,
cached_tokens:10000, output_tokens:17739}, costDetails prices cached tokens at
the cheaper cached rate, cost=0.1868475 (< non-cached, reflecting the discount).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018t3JHc1kK6pPMdVBVwMbTs
0 commit comments