mirror of
https://github.com/hanzoai/ai.git
synced 2026-11-20 14:13:23 +00:00
A call through the gateway bills the price of the arm that answered and the platform's fee on top, and nothing else: 5.5% on Hanzo's accounts, 1% on the org's own key, both the host's settings (object.Fee: hanzo, hanzo_byok). A vendor's fee is part of the cost: a call OpenRouter's credit bought cost its stated price plus 5.5%, and the platform's fee goes on that. - Enso answers bill their cost of record (X-Hanzo-Cogs and the buying vendor's fee) times the platform's fee; a maker's answer the same; a resold OpenRouter SKU its vendor price times both fees. An answer that states no cost bills the SKU's listed ceiling. A call billed below its cost writes loss_nano and a warning. - hanzo.cloud_usage gains reasoning, reasoning_tokens, served, vendor, arms and loss_nano: each Enso row names the arm that answered, its rate at the time and the tokens it was paid for, and each arm that failed first. - rates.go prices every Enso SKU at each depth: from (its cheapest arm), up to (its dearest, a long prompt included), and typical (its measured cost a token over the last day, or its last 50 calls), the arms read from the engine's admin catalog. /v1/models lists the typical rate with from, up_to, fee and window beside it; Prices, Price and Blend serve the rest. The board's ledger counts answers, failovers, OpenRouter-bought answers, fee and losses by model and vendor.
72 lines
2.5 KiB
Go
72 lines
2.5 KiB
Go
// Copyright 2023-2026 Hanzo AI Inc. All Rights Reserved.
|
||
//
|
||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||
// you may not use this file except in compliance with the License.
|
||
// You may obtain a copy of the License at
|
||
//
|
||
// http://www.apache.org/licenses/LICENSE-2.0
|
||
//
|
||
// Unless required by applicable law or agreed to in writing, software
|
||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
// See the License for the specific language governing permissions and
|
||
// limitations under the License.
|
||
|
||
package controllers
|
||
|
||
import "testing"
|
||
|
||
// TestPlatformFeeCents pins the two policies exactly:
|
||
// - byo=false (bought via Hanzo credits) → 0 surcharge, at every cost.
|
||
// - byo=true (customer-connected account) → ceil(cost × the host's BYOK fee, 1%),
|
||
// so a non-zero cost always bills at least 1 cent and never rounds down to a free
|
||
// call.
|
||
func TestPlatformFeeCents(t *testing.T) {
|
||
fees(t, map[string]string{"hanzo_byok": "1"})
|
||
cases := []struct {
|
||
name string
|
||
cost int64
|
||
byo bool
|
||
want int64
|
||
}{
|
||
// byo=false: never a surcharge, regardless of cost.
|
||
{"credits cost 0", 0, false, 0},
|
||
{"credits cost 1", 1, false, 0},
|
||
{"credits cost 100", 100, false, 0},
|
||
{"credits cost 10000", 10000, false, 0},
|
||
|
||
// byo=true: 1% rounded UP.
|
||
{"byo cost 0", 0, true, 0},
|
||
{"byo cost 1", 1, true, 1},
|
||
{"byo cost 99", 99, true, 1},
|
||
{"byo cost 100", 100, true, 1},
|
||
{"byo cost 101", 101, true, 2},
|
||
{"byo cost 150", 150, true, 2},
|
||
{"byo cost 10000", 10000, true, 100},
|
||
{"byo cost 12345", 12345, true, 124},
|
||
|
||
// A negative/garbage cost never produces a negative fee (defensive).
|
||
{"byo negative cost", -5, true, 0},
|
||
}
|
||
for _, tc := range cases {
|
||
t.Run(tc.name, func(t *testing.T) {
|
||
if got := platformFeeCents(tc.cost, tc.byo); got != tc.want {
|
||
t.Errorf("platformFeeCents(%d, %v) = %d, want %d", tc.cost, tc.byo, got, tc.want)
|
||
}
|
||
})
|
||
}
|
||
}
|
||
|
||
// The BYOK fee is the host's setting, read where the platform's fee is: at 2% the
|
||
// same call bills 2%, and a host that states none bills no fee at all.
|
||
func TestTheBYOKFeeIsTheHostsSetting(t *testing.T) {
|
||
fees(t, map[string]string{"hanzo_byok": "2"})
|
||
if got := platformFeeCents(10000, true); got != 200 {
|
||
t.Errorf("at 2%% the fee on 10000c = %d, want 200", got)
|
||
}
|
||
fees(t, map[string]string{})
|
||
if got := platformFeeCents(10000, true); got != 0 {
|
||
t.Errorf("with no fee stated the fee = %d, want 0", got)
|
||
}
|
||
}
|