Skip to content

fix(langchain): record provider-reported costs - #2145

Open
jcd1991 wants to merge 1 commit into
langfuse:mainfrom
jcd1991:codex/langchain-provider-cost
Open

jcd1991 wants to merge 1 commit into
langfuse:mainfrom
jcd1991:codex/langchain-provider-cost

Conversation

@jcd1991

@jcd1991 jcd1991 commented Nov 22, 2026 •

Copy link
Copy Markdown

Summary

  • preserve numeric provider-reported LangChain costs as cost_details.total
  • remove the provider cost field from token usage details
  • support both LangChain llm_output["token_usage"] and message response_metadata["token_usage"]
  • intentionally record only the provider's total charge; upstream breakdown fields can represent a different bill, such as BYOK provider cost

Related: langfuse/langfuse#17508

Verification

  • uv run --frozen pytest -n auto --dist worksteal tests/unit -q — 1039 passed, 2 skipped
  • uv run --frozen ruff check . — passed
  • uv run --frozen ruff format --check . — passed
  • uv run --frozen mypy langfuse --no-error-summary — passed
  • git diff --check — passed

RetriggerView in GreptileConfidence Score: 4/5

The PR appears safe to merge, with a non-blocking gap in integer-charge test coverage.

Summary

Records numeric provider charges in cost_details.total for LangChain results.

  • LangChain generations record provider-reported charges separately from token counts.

Acknowledgment: jcd1991 explicitly intends to omit provider breakdown fields because they can describe a different bill, such as BYOK provider cost. This is not reported as an issue.

Reviews (1) · Last reviewed commit: "fix(langchain): record provider-reported..." · Reviewed by Greptile

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

Comment thread tests/unit/test_langchain.py Resolved
@jcd1991
jcd1991 force-pushed the codex/langchain-provider-cost branch from 08c2c93 to f44b3c9 Compare November 22, 2026 01:16

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant