Dosu LogoDosu Logo
Ask
Join our Discord
langfuse/langfusePublic
Langfuse
Documentslangfuse/langfuse
Model Pricing Configuration
Model Pricing Configuration
Type
Topic
Status
Published
Created
Aug 3, 2026
Updated
Aug 3, 2026
Created by
Dosu Bot
Updated by
Dosu Bot

Model Pricing Configuration#

Overview#

Langfuse stores model pricing in PostgreSQL via Prisma using three related tables: Model, Price, and PricingTier . The system supports two pricing modes:

  • Flat pricing — legacy inputPrice/outputPrice/totalPrice decimal fields directly on the Model record.
  • Tiered pricing — condition-based PricingTier records linked to granular Price entries per usageType (added in November 2025).

Models with projectId = null are system-wide defaults; models scoped to a project via projectId override them for that project . Default models are shipped via Prisma migrations, not a seed file.

Database Schema#

Three Prisma models make up the pricing layer . The Model → PricingTier → Price hierarchy means every price is attached to a tier, even flat/legacy prices (which are backfilled into a default tier).

TableKey FieldsNotes
modelsmodelName, matchPattern, startDate, inputPrice, outputPrice, totalPrice, unit, tokenizerId, tokenizerConfigmatchPattern is a regex used to resolve model names at ingestion time. unit is one of TOKENS, CHARACTERS, MILLISECONDS, SECONDS, REQUESTS, or IMAGES.
pricing_tiersmodelId, name, isDefault, priority, conditions (JSONB)conditions stores an array of match rules. Unique on (modelId, priority) and (modelId, name).
pricesmodelId, pricingTierId, usageType, price (Decimal), projectIdUnique on (modelId, usageType, pricingTierId). projectId allows per-project price overrides.

All three tables cascade-delete on parent removal .

Usage Types#

The usageType field on Price is a free-form string matched exactly against keys in the ingested usage_details map. Supported values across providers include:

usageTypeDescription
inputStandard input tokens
outputStandard output tokens
totalTotal token cost (when not split)
input_cached_tokensCached input tokens (OpenAI)
input_cache_creationAnthropic cache creation (default TTL)
input_cache_creation_5mAnthropic 5-min TTL cache creation
input_cache_creation_1hAnthropic 1-hour TTL cache creation
input_cache_readBedrock cache read tokens
input_cache_writeBedrock cache write tokens
output_reasoning_tokensOpenAI o1/o3 reasoning tokens
accepted_prediction_tokensOpenAI accepted prediction tokens
rejected_prediction_tokensOpenAI rejected prediction tokens

⚠️ Exact-match gotcha: Cost calculation matches usageType by strict string equality against usage_details keys . If the provider SDK emits a raw key (e.g., cache_read_input_tokens) that doesn't match the pricing entry key (input_cached_tokens), that bucket is silently priced at zero. This caused a known undercount for GPT-5.6 Sol/Terra/Luna models .

Tiered Pricing Mechanism#

Each PricingTier holds a conditions JSONB array. Each condition has the shape :

{ usageDetailPattern: string, operator: "gt"|"gte"|"lt"|"lte"|"eq"|"neq", value: number, caseSensitive: boolean }

At cost calculation time, matchPricingTier() :

  1. Iterates non-default tiers in ascending priority order.
  2. For each tier, compiles usageDetailPattern as a regex, sums all matching usage_details keys, and evaluates the operator+threshold (AND logic across conditions).
  3. Returns the first matching tier; falls back to the isDefault = true tier if none match.

Each winning tier owns a set of Price records — one per usageType. calculateUsageCosts() then multiplies price × units for each key .

User override: if any provided_cost_details key is set on the observation, automatic cost calculation is bypassed entirely .

Management APIs and Entry Points#

Public REST API#

  • GET /api/public/models — list all models (system + project-scoped) with their pricing tiers.
  • POST /api/public/models — create a custom model with flat or tiered pricing.
  • GET /DELETE /api/public/models/[modelId] (source) — fetch or delete a specific model.

Internal tRPC Router#

web/src/server/api/routers/models.ts exposes upsert, getById, getAll, delete, and testMatch procedures. upsert deletes existing pricing tiers before writing new ones — i.e., tier updates are full replacements .

Default Model Definitions#

System-default models are added exclusively via Prisma migrations in packages/shared/prisma/migrations/. Notable migration milestones:

  • 20241024100928_add_prices_table — introduced the prices table.
  • 20251127105316_add_pricing_tiers — added pricing_tiers table; backfilled existing prices into default tiers.
  • 20250711105322_prices_add_project_id — enabled per-project custom pricing.
  • 20240913095558_models_add_openai_o1 — added o1 reasoning models (no tokenizer config because reasoning output cannot be locally tokenized).

Model Matching#

findModel() resolves an incoming model name string against matchPattern regexes. Results are cached in Redis and local memory to minimize DB round-trips during high-throughput ingestion.

Documents
Agent Sandbox Runtime
Annotation Form Components
API Key Management
Authentication Email Handling
Background Migration Timeout Configuration
Blob Storage Export
BullMQ Worker Lifecycle
Chat Prompt Configuration
ChatML Message Rendering
CJK Input and Unicode Handling
ClickHouse Backfill
ClickHouse Full-Text Search
ClickHouse Migrations
ClickHouse Query Design
ClickHouse Query Execution
ClickHouse Version Compatibility
Dashboard Chart Rendering
Dashboard Query Backend Architecture
Dashboard Widget Versioning
Data Masking
Database Upsert and Uniqueness Constraints
Dataset Item Processing Pipeline
Eval Job Execution
Eval Output Schema
Eval Template Versioning
Evaluation Queue Architecture
Evaluator Configuration and Status Management
Events Table Architecture
Events Table Query Routing
Experiments
Feature Flag System
Filter State Management
HTTP Proxy Configuration
Lambda MicroVM Sandbox
LangGraph Integration
LLM Model Configuration
LLM-as-a-Judge Evaluation
Lossless JSON Parsing
MCP Server Integration
MCP Tool Schema Design
Media Token Rendering
Mixpanel Worker Integration
Model Pricing Configuration
NextAuth OAuth Integration
Observation Data Loading
Observation Eval Scheduling
Onboarding State Management
OTel Attribute Serialization
OTel GenAI Message Ingestion
OTel Ingestion and Trace Hierarchy
OTel Token Usage Processing
Redis Client Management
Redis Retry Strategy
Redis Sentinel Integration
Score Configuration Management
Self-Hosted Deployment
Session Score Aggregation
Token Usage Enrichment
Token Usage Storage
Trace Heatmap Visualization
Trace-Level Token Aggregation
Usage Cost Calculation
V4 Data Pipeline Migration
Webhook Reliability