Skip to content

Expose Codex service tiers for Langfuse pricing#34

Open
wallacelim wants to merge 1 commit into
langfuse:mainfrom
wallacelim:feat/service-tier-pricing
Open

Expose Codex service tiers for Langfuse pricing#34
wallacelim wants to merge 1 commit into
langfuse:mainfrom
wallacelim:feat/service-tier-pricing

Conversation

@wallacelim

Copy link
Copy Markdown

Context

Codex service tiers can change model pricing, but the tracing plugin currently drops the active tier. As a result, Langfuse cannot distinguish Standard, Fast/Priority, Flex, or catalog-defined tiers when inferring cost.

Codex records tier changes in thread_settings_applied.service_tier. The first turn of a session may precede that event, so the plugin also needs a configuration fallback. Langfuse pricing-tier conditions operate on numeric usage details, while the raw tier remains useful as metadata.

What this changes

  • captures the per-turn Codex service tier without creating an empty synthetic turn for settings events
  • falls back to global/project Codex config.toml for an initial turn whose rollout omits the tier
  • supports an explicit service_tier / LANGFUSE_CODEX_SERVICE_TIER fallback override
  • records the raw tier as codex.service_tier generation metadata
  • emits a generic numeric selector for non-default tiers, e.g. codex_service_tier_priority = 1
  • documents how to use the selector in a Langfuse custom-model pricing condition

The plugin does not hard-code provider prices, credit conversions, or organization-specific discounts. Each Langfuse project remains responsible for its own model rate cards.

Example

A Fast-mode rollout that reports service_tier: "priority" emits:

{
  "metadata": {
    "codex.service_tier": "priority"
  },
  "usageDetails": {
    "codex_service_tier_priority": 1
  }
}

A custom model can select its higher-rate tier with a condition such as ^codex_service_tier_(fast|priority)$ > 0.

Scope and PR split

This PR is intentionally independent of:

Those correctness/reliability changes should remain separately reviewable. The generated bundle is included because this repository requires committed build output.

Validation

  • corepack pnpm@9.5.0 test — 38 passing
  • corepack pnpm@9.5.0 run lint — Prettier, TypeScript, and generated-bundle checks pass

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

2 participants