DEV Community

LONGAI
LONGAI

Posted on

A compatible endpoint is not a compatible bill: five shapes hidden behind one request format

An OpenAI-compatible endpoint answers the same request shape. It does not answer with the same bill. If you move between upstreams and keep one cost model, your forecast will be wrong in ways the response body never shows you.

The numbers below come from our own model catalog snapshot taken 2026-12-04 20:00 UTC+8: 95 listed models across nine channels (92 text, 3 image). Only structural counts are used — how many entries carry which billing field — not absolute prices.

1. Cache pricing is published asymmetrically

82 of the 95 entries carry a cache-read price. Only 30 carry a cache-write price. That gap is the first thing a compatibility test will not catch: a prompt-cache hit is cheap on one upstream, and on another the write that created the cache is itself billable while the read is folded into the input rate.

Practical consequence: a workload with a long shared system prompt looks 30–60% cheaper on paper, then lands 10% above forecast because the first request of every new prefix paid a write premium nobody modelled. Treat "cache-enabled" as three states — read priced, write priced, both — not a boolean.

2. Three of 95 do not bill per token at all

The request body is still a chat or generation call, but the invoice unit is the image. Any cost function that multiplies tokens by a rate will silently return zero for those entries, and zero is the most dangerous number in a billing report: it looks like a saving.

Our catalog separates billing_mode into token and image for exactly this reason. Your client should branch on it before it touches a rate table.

3. Long-context surcharge is a flag, not a constant

Every entry carries long_context_pricing_enabled. In the current snapshot it is off for all 95, but the field exists because upstreams switch it per model and per window. Code that hardcodes "no surcharge" works until the day a 200K-token request is billed at the long-context tier and nobody changed the client.

Read the flag, don't assume its value. The same applies to anyone running their own gateway: publish the flag even when it is false, so downstream consumers can distinguish "not applicable" from "not implemented".

4. Tiered pricing is a step function you have to model

The schema carries a per-model intervals list for step pricing. In this snapshot every list is empty — meaning flat pricing today, not flat pricing by design. A cost calculator built on a single input/output pair will be correct until the first tiered model is listed, and then wrong by the amount of the step, on every request, silently.

Shape Entries What breaks if you ignore it
Token billing 92 / 95 —
Image billing 3 / 95 cost computed as zero
Cache-read price published 82 / 95 savings overstated on 13 entries
Cache-write price published 30 / 95 first-hit premium missed entirely
Long-context flag enabled 0 / 95 tier switch unhandled when it flips
Tiered intervals present 0 / 95 step function missing from the calculator

5. Unit and rounding differ from the rate card

Our catalog stores input_price per single token; rate cards are written per thousand or per million. Multiply, and you get the displayed number. Do it in the wrong order with integer division and a 0.0000005-per-token rate becomes 0. This is not an upstream difference, it is the difference between a stored canonical value and a presentation layer — and it is where most reconciliations fail.

A cost function that survives the edges

One function that reads the shape instead of assuming it:

def cost_of(record, input_tokens, output_tokens, cached_tokens=0):
    pricing = record.get("pricing") or {}
    mode = pricing.get("billing_mode", "token")
    if mode != "token":
        # per-image or other non-token unit: caller must supply a unit count
        raise ValueError("non-token billing: %s" % mode)

    def rate(tokens):
        intervals = pricing.get("intervals") or []
        if not intervals:
            return pricing.get("input_price", 0) * tokens
        # step function: last interval whose threshold is <= tokens
        for it in sorted(intervals, key=lambda x: x.get("up_to", 0)):
            if tokens <= it.get("up_to", 0):
                return it.get("input_price", 0) * tokens
        return intervals[-1].get("input_price", 0) * tokens

    billable_in = max(input_tokens - cached_tokens, 0)
    total = rate(billable_in) + pricing.get("output_price", 0) * output_tokens
    if cached_tokens and pricing.get("cache_read_price"):
        total += pricing["cache_read_price"] * cached_tokens
    return total
Enter fullscreen mode Exit fullscreen mode

The important property is not the arithmetic, it is the branch: the function refuses to guess when the unit is not a token, and it degrades to flat pricing only when the interval list is genuinely empty.

Five checks you can run against any gateway

checks = [
    ("response_has_usage", lambda r: "usage" in r),
    ("usage_has_cached_field", lambda r: "cached_tokens" in (r.get("usage") or {})),
    ("model_list_exposes_billing_mode", lambda m: "billing_mode" in m),
    ("pricing_exposes_cache_write", lambda m: "cache_write_price" in m),
    ("pricing_exposes_intervals", lambda m: "intervals" in m),
]
Enter fullscreen mode Exit fullscreen mode

Four of these five are about disclosure, not about price. A gateway that answers every request correctly but hides its billing shape is not compatible in the way that matters to a finance team — you cannot reconcile a bill you cannot reconstruct.

What this means when you buy

The same input string is priced through different shapes on different upstreams. Before committing volume, ask for the billing shape per model, in the same structured form you would ask for a rate: unit, cache read, cache write, long-context flag, tier thresholds. If an upstream answers "it's OpenAI-compatible", that answer is about the request, not the invoice.

Per-model billing shapes and current rates: published rate table. Field definitions for the catalog records: model reference. The live catalog itself: model plaza. Health of each channel: status page.


Per-model billing shapes: https://ai.dijinlong.com/model-docs · Rate table: https://ai.dijinlong.com/pricing

Top comments (0)