hanzo-kai reads /v1/models pricing as per-token prompt and completion strings plus per-million rates under keys that name the unit.

This commit is contained in:
2026-09-30 14:56:35 -07:00
parent cac19547ff
commit 4c0e40351c
4 changed files with 42 additions and 12 deletions
+3 -3
View File
@@ -108,7 +108,7 @@ def claim(name: str, value) -> str:
def cost(model: str, tokens: tuple[int, int]) -> float:
"""US dollars for input and output tokens at a model's catalogue price per million."""
return (tokens[0] * price[model]["input"] + tokens[1] * price[model]["output"]) / 1e6
return (tokens[0] * price[model]["input_per_million"] + tokens[1] * price[model]["output_per_million"]) / 1e6
def same(name: str, value, gold) -> bool:
@@ -156,9 +156,9 @@ print(
f"\nP(entailment) of {FIRST}'s {len(good)} right fields: lowest {min(good):.2f}, median {statistics.median(good):.2f}"
)
fields, checking = len(rows) * len(FIELDS), checked * price["kai"]["input"] / 1e6
fields, checking = len(rows) * len(FIELDS), checked * price["kai"]["input_per_million"] / 1e6
print(
f"\nKai read {checked} input tokens for {fields} checks: {checking:.6f} USD at {price['kai']['input']} per million"
f"\nKai read {checked} input tokens for {fields} checks: {checking:.6f} USD at {price['kai']['input_per_million']} per million"
)
print(f"an invoice goes to {SECOND} when any of its fields is under the line")
print("line invoices sent fields right Zen input Zen output cost, USD")
+1 -1
View File
@@ -2,4 +2,4 @@ from hanzo_kai import Kai
with Kai() as kai:
for model in kai.models.list():
print(model.id, model.owned_by, model.pricing.input, model.pricing.output)
print(model.id, model.owned_by, model.pricing.input_per_million, model.pricing.output_per_million)
+7 -3
View File
@@ -161,12 +161,16 @@ class Decision(Response):
class Pricing(BaseModel):
"""List prices in US dollars per million tokens."""
"""List prices in US dollars, per token and per million tokens."""
model_config = ConfigDict(extra="allow", frozen=True)
input: float | None = None
output: float | None = None
prompt: str | None = None
"""Per input token, as a decimal string (OpenRouter's key and unit)."""
completion: str | None = None
"""Per output token, as a decimal string."""
input_per_million: float | None = None
output_per_million: float | None = None
class Model(BaseModel):
+31 -5
View File
@@ -18,7 +18,12 @@ LISTING = {
"premium": True,
"context_window": 131072,
"outputs": ["text"],
"pricing": {"input": 0.96, "output": 1.92},
"pricing": {
"prompt": "0.00000096",
"completion": "0.00000192",
"input_per_million": 0.96,
"output_per_million": 1.92,
},
},
{
"id": "hanzo/kai",
@@ -27,7 +32,12 @@ LISTING = {
"owned_by": "hanzo",
"premium": False,
"outputs": ["decision"],
"pricing": {"input": 0.021, "output": 0},
"pricing": {
"prompt": "0.000000021",
"completion": "0",
"input_per_million": 0.021,
"output_per_million": 0,
},
},
{
"id": "kai",
@@ -36,9 +46,19 @@ LISTING = {
"owned_by": "hanzo",
"premium": False,
"outputs": ["decision"],
"pricing": {"input": 0.021, "output": 0},
"pricing": {
"prompt": "0.000000021",
"completion": "0",
"input_per_million": 0.021,
"output_per_million": 0,
},
},
{
"id": "no-outputs",
"object": "model",
"outputs": None,
"pricing": {"input_per_million": -1200000, "output_per_million": -1200000},
},
{"id": "no-outputs", "object": "model", "outputs": None, "pricing": {"input": -1200000, "output": -1200000}},
{"id": "no-field", "object": "model"},
"not a row",
],
@@ -54,7 +74,13 @@ def test_lists_the_decision_models(client: Build) -> None:
assert [model.id for model in found] == ["hanzo/kai", "kai"]
kai = found[1]
assert isinstance(kai, Model) and isinstance(kai.pricing, Pricing)
assert (kai.owned_by, kai.created, kai.pricing.input, kai.pricing.output) == ("hanzo", 1790629327, 0.021, 0)
assert (kai.owned_by, kai.created, kai.pricing.input_per_million, kai.pricing.output_per_million) == (
"hanzo",
1790629327,
0.021,
0,
)
assert (kai.pricing.prompt, kai.pricing.completion) == ("0.000000021", "0")
assert kai.model_extra == {"object": "model", "premium": False, "outputs": ["decision"]}