#16187·langfuse

bug: @langfuse/openai emits unpriced input_cache_write_tokens for GPT-5.6

Author: kirill-markinCreated Aug 16, 2026Updated Sep 17, 2026
Labelsbugintegration-openaifeat-llm-cost-trackingstalelangfuse/langfusefeat-billingbillingMigrated

Describe the bug

When the OpenAI Responses API reports GPT-5.6 cache-write usage, the official @langfuse/openai wrapper persists it as input_cache_write_tokens, but the Langfuse GPT-5.6 pricing definitions do not contain a price for that usage key. As a result, the tokens are present in usageDetails while their cost is silently omitted from costDetails and totalCost.

The mismatch is internal to Langfuse:

  1. OpenAI returns usage.input_tokens_details.cache_write_tokens.
  2. parseUsageDetails prefixes Responses API input detail keys with input_, producing input_cache_write_tokens.
  3. The current gpt-5.6-sol pricing definition prices input_cache_creation and cache_write_tokens, but not input_cache_write_tokens.
  4. Usage-to-price matching therefore leaves this positive usage bucket unpriced.

Expected behavior: input_cache_write_tokens should be recognized as an alias of input_cache_creation and priced at the GPT-5.6 cache-write rate. OpenAI documents cache writes at 1.25x the uncached input rate. For GPT-5.6 Sol requests above 272K input tokens, this is $12.50 per million tokens.

Steps to reproduce

  1. Wrap the OpenAI Node SDK with observeOpenAI from @langfuse/[email protected].
  2. Send a Responses API request using gpt-5.6-sol that produces non-zero input_tokens_details.cache_write_tokens.
  3. Retrieve the generation through GET /api/public/v2/observations with the usage field group.
  4. Observe that usageDetails.input_cache_write_tokens is positive, but costDetails.input_cache_write_tokens is absent.

A sanitized production observation:

json
{
  "usagePricingTierName": "Large Context (>272K)",
  "usageDetails": {
    "input": 3,
    "input_cached_tokens": 0,
    "input_cache_write_tokens": 537807,
    "output": 71,
    "output_reasoning_tokens": 23,
    "total": 537904
  },
  "costDetails": {
    "input": 0.00003,
    "input_cached_tokens": 0,
    "output": 0.003195,
    "output_reasoning_tokens": 0.001035,
    "total": 0.00426
  }
}

The missing cache-write cost for this observation is:

537,807 * $12.50 / 1,000,000 = $6.7225875

The buckets are otherwise mutually exclusive and sum to total, so this is not a double-counting issue.

Langfuse Cloud or self-hosted?

Langfuse Cloud

If self-hosted, what version are you running?

Not applicable.

SDK and integration versions

  • @langfuse/openai: 5.10.0
  • @langfuse/client: 5.10.0
  • @langfuse/otel: 5.10.0
  • @langfuse/tracing: 5.10.0
  • openai: 7.4.0
  • OpenAI Responses API
  • Model: gpt-5.6-sol

All listed npm packages are on their current latest versions as of August 16, 2026. The same mismatch is also present on the current main branches of langfuse-js and langfuse.

Additional information

This is closely related to langfuse/langfuse#15139 and its fix langfuse/langfuse#15712, but that fix added input_cache_creation and cache_write_tokens without adding the key emitted by the official JS wrapper: input_cache_write_tokens.

The open alias-resolution PR #15471 would be the natural place to handle this centrally, but its current alias map includes input_cache_write and cache_write_tokens, not input_cache_write_tokens.

Suggested fix:

input_cache_write_tokens -> input_cache_creation

Please add a regression test that starts from an OpenAI Responses API usage object containing input_tokens_details.cache_write_tokens, passes it through the official JS wrapper normalization, and verifies that the resulting cache-write bucket receives the configured GPT-5.6 price.

In one sanitized daily aggregate, 12,892,178 large-context cache-write tokens received zero cost in Langfuse, omitting $161.152225 from totalCost.

Are you interested in contributing a fix for this bug?

No.