Skip to content

Pricing

openai_model_registry.pricing

Pricing data structures for model registry.

Classes

PricingInfo dataclass

Unified pricing information for a model.

This unified schema supports both token-based and non-token pricing.

  • scheme: pricing method
  • unit: display/normalization unit
  • input_cost_per_unit / output_cost_per_unit: numeric non-negative costs
  • currency: ISO currency code (default: USD)
Source code in src/openai_model_registry/pricing.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
@dataclass(frozen=True)
class PricingInfo:
    """Unified pricing information for a model.

    This unified schema supports both token-based and non-token pricing.

    - scheme: pricing method
    - unit: display/normalization unit
    - input_cost_per_unit / output_cost_per_unit: numeric non-negative costs
    - currency: ISO currency code (default: USD)
    """

    scheme: Literal["per_token", "per_minute", "per_image", "per_request"]
    unit: Literal["million_tokens", "minute", "image", "request"]
    input_cost_per_unit: float
    output_cost_per_unit: float
    currency: str = "USD"
    # Optional tiers for per_image (and future schemes):
    # [ { quality: str, sizes: [ { size: str, cost_per_image: float } ] }, ... ]
    tiers: Optional[List[Dict[str, Any]]] = None

    def __post_init__(self) -> None:  # noqa: D401
        """Basic validation ensuring non-negative costs."""
        if self.input_cost_per_unit < 0:
            raise ValueError("Input cost must be non-negative")
        if self.output_cost_per_unit < 0:
            raise ValueError("Output cost must be non-negative")
        # Basic structure validation for tiers when present
        if self.tiers is not None:
            if not isinstance(self.tiers, list):
                raise ValueError("tiers must be a list if provided")
Functions
__post_init__()

Basic validation ensuring non-negative costs.

Source code in src/openai_model_registry/pricing.py
28
29
30
31
32
33
34
35
36
37
def __post_init__(self) -> None:  # noqa: D401
    """Basic validation ensuring non-negative costs."""
    if self.input_cost_per_unit < 0:
        raise ValueError("Input cost must be non-negative")
    if self.output_cost_per_unit < 0:
        raise ValueError("Output cost must be non-negative")
    # Basic structure validation for tiers when present
    if self.tiers is not None:
        if not isinstance(self.tiers, list):
            raise ValueError("tiers must be a list if provided")