mirror of
https://github.com/hanzoai/ai.git
synced 2026-11-20 14:13:23 +00:00
Owner, 2026-10-09/11: "in waterfall we should try all native anthropic api
keys, then fall to OR, then free models". anthropic/* SKUs were served by
OpenRouter alone.
A resale family may now name a native: the API of the vendor that makes some
of its SKUs. OpenRouter's is Anthropic's (ANTHROPIC_URL; unset, nothing
changes). dispatch asks it first and the family's own address only once no key
answered. The SKU, its catalog price and every gate in front of it are the
family's, unchanged.
- Paid only. A maker bills every call, so it is asked only by a request seated
on the paid lane, for a route the family lists and charges for. A free route,
the free pool, enso-free, zen-free, free and every unseated request never
reach it.
- Every key, in order. The pool is ANTHROPIC_API_KEY, _2, _3, then each line of
ANTHROPIC_API_KEYS (object.Accounts). 401, 403 and an account out of credit
bench the key ten minutes; 429 until Retry-After, never past a minute; 404,
408, 5xx and 529 ask the next key and bench nothing. Any other refusal is the
request's own, so no other key is asked and OpenRouter is: nothing that works
through OpenRouter stops working.
- What a key lists is what it is asked for. GET /v1/models per key at start and
every five minutes: anthropic/claude-haiku-4.5 is claude-haiku-4-5 or its
newest dated release, and a SKU with a :variant is the reseller's. The same
read benches a key the vendor refuses and brings back one it accepts again.
A key's standing is logged by NAME when it changes and counted once in
cloud_supply_refused{provider="anthropic"}.
- As itself. Nothing here picks another model. When neither the maker nor
OpenRouter serves it the caller is told 503 providers_exhausted, as before.
- Dialects. A /v1/messages body goes as it came, held to what the shared
account serves (shared). A chat, and so /v1/responses, is translated by
chatAsMessages and read back by claudeChat, always as a stream: system
prompt, images, PDFs, tools, tool choice, tool results, stop sequences, JSON
schema, the caller's cache breakpoints. Thinking, effort and sampling
parameters are sent only to a model whose listed capabilities take them.
What the Messages API has no word for goes to OpenRouter untouched. A request
with no cache_control is asked to cache its prompt, as on OpenRouter's path.
- Money. The answer bills the catalog price of its tokens; cached reads and
cache writes at the SKU's own rates, reported to the caller in
prompt_tokens_details. The maker states what the call cost at the vendor's
price as X-Hanzo-Cogs, as a family service does, and a resold SKU never bills
below that times its markup (an hour-long cache write).
- On the books. The usage row's origin is api.anthropic.com#<place of the
key>, its span carries gen_ai.hanzo.via = anthropic#<place>, the vendor as
gen_ai.provider.name and the vendor's id as gen_ai.response.model; each key
that refused first is a failover row. provider stays openrouter. Never a key.
Enso and Zen rungs are their family service's to order; no rung names a Claude
model today.
Co-authored-by: Hanzo Dev <[email protected]>
55 lines
2.0 KiB
Go
55 lines
2.0 KiB
Go
// Copyright 2026 Hanzo AI Inc. All Rights Reserved.
|
|
|
|
package controllers
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/hanzoai/ai/object"
|
|
)
|
|
|
|
// The paid lane is on for this package's tests, which exercise it, and every request
|
|
// they build is seated on it (visit, paidSeat); a test of the free lane closes it
|
|
// itself and opens it again when it ends, and a test of the lanes themselves
|
|
// (lane_test.go) seats each caller.
|
|
//
|
|
// The vendor accounts are the ones a test sets, never one the shell running the suite
|
|
// holds: a real key in the environment is one more account the pool walks, which a
|
|
// test vendor benches on its first refusal.
|
|
func TestMain(m *testing.M) {
|
|
FreeOnly = func() bool { return false }
|
|
for _, k := range object.OpenRouterKeys {
|
|
_ = os.Unsetenv(k)
|
|
}
|
|
for _, k := range append([]string{"ANTHROPIC_URL", object.AnthropicKeyList}, object.AnthropicKeys...) {
|
|
_ = os.Unsetenv(k)
|
|
}
|
|
os.Exit(m.Run())
|
|
}
|
|
|
|
// With the paid lane off, a call to any provider but a family's own service is one
|
|
// that spends, and is refused; with it on, none is.
|
|
func TestPayingIsEveryProviderButAFamilys(t *testing.T) {
|
|
ctx := paidSeat(context.Background())
|
|
FreeOnly = func() bool { return true }
|
|
t.Cleanup(func() { FreeOnly = func() bool { return false } })
|
|
for typ, want := range map[string]bool{"Zen": false, "Enso": false, "OpenAI": true, "OpenRouter": true, "": true} {
|
|
if got := paying(ctx, &object.Provider{Type: typ}); got != want {
|
|
t.Fatalf("paying(%q) = %v, want %v", typ, got, want)
|
|
}
|
|
}
|
|
// Our own speech service pays no vendor; an org's row that borrows its name does.
|
|
if paying(ctx, &object.Provider{Owner: "admin", Name: "speech", Type: "OpenAI"}) {
|
|
t.Fatal("the paid lane being off refused our own speech service")
|
|
}
|
|
if !paying(ctx, &object.Provider{Owner: "acme", Name: "speech", Type: "OpenAI"}) {
|
|
t.Fatal("an org's provider named speech was taken for ours")
|
|
}
|
|
FreeOnly = func() bool { return false }
|
|
if paying(ctx, &object.Provider{Type: "OpenAI"}) {
|
|
t.Fatal("a paid lane that is on refused a priced provider")
|
|
}
|
|
}
|