Skip to content

fix(llm): LiteLLM proxy responses record $0.00 cost when x-litellm-response-cost header is omitted #51958

Closed as not planned

Description

@BrunoSilva-neuro

Bug

When using OpenCode with a LiteLLM proxy (e.g. litellm/gpt-6-luna), some responses are recorded with $0.00 cost even though the proxy correctly billed the request.

Root cause

LiteLLM 1.98+ omits the x-litellm-response-cost response header when its value equals x-litellm-response-cost-original (a deduplication optimisation). However, OpenCode does not read any LiteLLM response headers at all — cost is estimated purely from token counts and a local price table.

For models without a price entry in the local config, this produces $0.00. For models with a price entry but where the header is absent, the local estimate may differ from the proxy's actual billing.

Steps to reproduce

  1. Configure OpenCode with a LiteLLM provider (e.g. a self-hosted proxy or prophet-router)
  2. Send two identical consecutive requests with the same model
  3. Check opencode stats — one or both may show $0.00 for that model

Observed vs expected

  • Observed: opencode stats shows $0.00 for LiteLLM-routed models
  • Expected: cost matches x-litellm-response-cost (or x-litellm-response-cost-original) from the proxy response headers

Evidence

Two manual curl calls to the proxy with identical payloads:

  • Request 1: x-litellm-response-cost: 0.000434 present
  • Request 2: x-litellm-response-cost absent, x-litellm-response-cost-original: 0.000434 present
  • Both billed: x-litellm-key-spend incremented on both

Activity

  1. github-actions commented on Sep 28, 2026

    @github-actions
    Contributor

    This issue doesn't fully meet our contributing guidelines.

    What needs to be fixed:

    • Please use the Bug Report template's required Description field (the current report uses a Bug heading instead) and add your OpenCode version and operating system/system details.

    Please edit this issue to address the above within 2 hours, or it will be automatically closed.


    This issue might be a duplicate of existing issues. Please check:

    • #43818: requests honoring provider-reported costs from gateways including LiteLLM.
    • #24113: reports zero costs for a custom LiteLLM proxy and notes that OpenCode does not read its cost response header.

    If you believe this was flagged incorrectly, please let a maintainer know.

  2. github-actions commented on Sep 29, 2026

    @github-actions
    Contributor

    This issue has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

    Feel free to open a new issue that follows our issue templates.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions