Skip to content

Omit zero cost_details on generations - #54

Merged
bezbac merged 3 commits into
langfuse:mainfrom
aizerin:fix/omit-zero-cost-details
Oct 20, 2026
Merged

bezbac merged 3 commits into
langfuse:mainfrom
aizerin:fix/omit-zero-cost-details

Conversation

@aizerin

@aizerin aizerin commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Summary

When OpenCode uses a custom or proxy provider (such as LiteLLM) without per-model cost configuration in opencode.json, OpenCode reports cost: 0 on completed assistant messages / generation steps.

Currently, traceGeneration() unconditionally sets:

"langfuse.observation.cost_details": JSON.stringify({ total: input.cost })

which exports {"total": 0} as provided_cost_details on the opencode.generation span.

In Langfuse's ingestion pipeline (IngestionService.calculateUsageCosts), any non-empty provided_cost_details takes precedence over model-based price calculation (if (providedCostKeys.length) return ...), causing total_cost to remain 0 even when a matching model definition with pricing tiers exists in Langfuse.

This change only sets langfuse.observation.cost_details when input.cost > 0, allowing Langfuse to compute generation costs from its configured model prices when OpenCode reports 0.

Verification

  • Added an integration test in test/integration/v1.test.ts covering both step-started and fallback generation spans with cost: 0
  • Ran pnpm run format, pnpm run build, pnpm run lint, pnpm run knip, and pnpm run test:integration

@CLAassistant

CLAassistant commented Oct 19, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@bezbac

bezbac commented Oct 20, 2026

Copy link
Copy Markdown
Member

Hi @aizerin, thanks for your contribution!

@bezbac
bezbac merged commit 532577a into langfuse:main Oct 20, 2026
3 checks passed
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.

3 participants