Skip to content

fix(pricing): price Venice models from live metadata - #49932

Open
rdguidry wants to merge 1 commit into
NousResearch:mainfrom
rdguidry:codex/venice-langfuse-pricing
Open

fix(pricing): price Venice models from live metadata#49932
rdguidry wants to merge 1 commit into
NousResearch:mainfrom
rdguidry:codex/venice-langfuse-pricing

Conversation

@rdguidry

@rdguidry rdguidry commented Jun 21, 2026

Copy link
Copy Markdown

Summary

  • Recognize direct api.venice.ai custom-provider calls as Venice billing routes.
  • Parse Venice's nested model_spec.pricing.{input,output,cache_input}.usd values from GET /models and convert USD-per-million-token rates into Hermes' per-token metadata format.
  • Pass a Venice credential into both Langfuse pricing paths so authenticated live model metadata can be used.
  • Keep credential selection host-scoped: Venice keys are never forwarded to arbitrary custom endpoints.
  • Guard the generic pricing parser against missing aliases and nested non-scalar values.

Why

Hermes profiles can configure Venice through the generic custom provider with https://api.venice.ai/api/v1. Current routing classifies that as an unknown custom endpoint, and Venice publishes pricing in nested objects that the generic parser cannot consume. As a result, direct Venice usage is unpriced in Langfuse; some nested payloads can also trigger parser exceptions.

The earlier version of this PR included a generic Langfuse costDetails.total change. That cross-provider work is intentionally removed here because #64797 now owns that concern. This revision is limited to Venice routing, metadata parsing, credential scoping, and regression coverage.

User impact

Direct Venice calls can use the provider's live model prices for token-cost accounting, including cache-read pricing. Custom non-Venice endpoints receive no inferred Venice or OpenAI credential.

Validation

  • uv run --extra dev --frozen pytest -q tests/agent/test_usage_pricing.py tests/hermes_cli/test_api_key_providers.py tests/plugins/test_langfuse_plugin.py — 272 passed
  • uv run --extra dev --frozen ruff check agent/model_metadata.py agent/usage_pricing.py plugins/observability/langfuse/__init__.py tests/agent/test_usage_pricing.py tests/hermes_cli/test_api_key_providers.py tests/plugins/test_langfuse_plugin.py
  • git diff --check

@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/plugins Plugin system and bundled plugins labels Jun 21, 2026

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for tracing direct Venice calls through the pricing and Langfuse paths. Current main still lacks the Venice route: agent/usage_pricing.py:675 classifies direct api.venice.ai custom calls as unknown, while models.dev currently has a venice/kimi-k2-7-code pricing entry.

Problems

  • The added cost_details["total"] calculations at plugins/observability/langfuse/__init__.py:594 and proposed line 1014 sum token buckets only. Canonical pricing also adds PricingEntry.request_cost at agent/usage_pricing.py:966-967, so the transmitted total can be lower than Hermes' canonical estimate.

Suggested changes

  • Populate total from canonical estimate_usage_cost(...).amount_usd in both paths, while retaining the bucket breakdown.
  • Add request-cost coverage for both Langfuse usage paths.

This is an automated hermes-sweeper review.

@@ -590,6 +590,8 @@ def _usage_and_cost(response: Any, *, provider: str, api_mode: str, model: str,
cost_details["cache_read_input_tokens"] = float(Decimal(canonical.cache_read_tokens) * entry.cache_read_cost_per_million / _ONE_M)
if entry.cache_write_cost_per_million is not None and canonical.cache_write_tokens:
cost_details["cache_creation_input_tokens"] = float(Decimal(canonical.cache_write_tokens) * entry.cache_write_cost_per_million / _ONE_M)
if cost_details:
cost_details["total"] = float(sum(Decimal(str(v)) for v in cost_details.values()))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

estimate_usage_cost() also includes PricingEntry.request_cost (agent/usage_pricing.py:966-967), but this token-bucket sum does not. Please use the already-computed canonical cost.amount_usd for total (and apply the same fix to the sanitized-usage path) so Langfuse totals cannot understate request-priced routes.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 14, 2026
@minnickna

Copy link
Copy Markdown

Thanks for identifying that Langfuse needs an explicit costDetails.total when Hermes exports per-bucket costs.

I reproduced the generic failure on current main with Anthropic cache-read/cache-write buckets: Langfuse stores every component but leaves the generation total undefined, so trace/session aggregates stay at zero. The sweeper's request-cost note is also important: summing buckets can undercount PricingEntry.request_cost, while estimate_usage_cost(...).amount_usd is the canonical total.

Because that contract fix is cross-provider and independent of this PR's Venice pricing work, and this head branch does not allow maintainer edits, I am preparing a narrowly scoped current-main PR that changes only the Langfuse plugin and its tests. It will use the canonical estimate in both active paths, include cache + request-cost regression coverage, and explicitly credit/cross-link this PR and @rdguidry. The Venice route and pricing scope remain entirely here.

@teknium1 teknium1 added the area/usage-cost Token accounting, usage reporting, billing, cost tracking label Jul 19, 2026
@rdguidry
rdguidry force-pushed the codex/venice-langfuse-pricing branch from 7af999e to cb34a17 Compare July 29, 2026 18:35
@rdguidry rdguidry changed the title [codex] Price Venice usage in Langfuse traces fix(pricing): price Venice models from live metadata Jul 29, 2026
@rdguidry
rdguidry marked this pull request as ready for review July 29, 2026 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/usage-cost Token accounting, usage reporting, billing, cost tracking comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants