mirror of
https://github.com/hanzo-go/sdk.git
synced 2026-11-20 20:13:42 +00:00
budget, policy, audit, search, kb and graph hang off the client as one word
each — the same word in the Go, Python and TypeScript SDKs, capitalized here
because that is Go's rule. They live in their own packages because they must:
the generated client already spells Answer, Page, Hit, Backend, Wrote,
Allowance, Charge, Policy, Audit, Graph and Link as projections of unrelated
operations, and a hand-written type cannot share a package with a generated one
of the same name.
A refusal is a value. Anything a gate can refuse answers call.Answer[T], whose
value is reachable only through Value(), which hands back a *Denied where a
budget or a policy said no, a *Held where a person was asked, and a *Fault where
nothing decided anything. One rule maps a status to an arm and no capability
varies it: 2xx is the value, a 202 whose body says held is a hold, 402 is a
denial whatever the code, a 403 carrying a refusal code is a denial, and
everything else is a fault. That last allow-list exists only because cloud
spells "no validated principal" as 403 forbidden; reading a bare forbidden as a
denial would tell an unauthenticated caller their budget said no.
IAM mints and the SDK never accepts a bearer. New exchanges the client's own
clientId and clientSecret for an access token — client_credentials under
client_secret_basic, scoped by the RFC 8707 resource — holds it to a minute
before expiry and mints again on a 401, once. NewClient(apiKey), NewConfig,
HANZO_API_KEY, Read and Result[T] are removed rather than deprecated: a
credential an SDK is handed is a credential nobody rotates, and two ways to do
one thing is the defect the contract exists to prevent.
Measured against api.hanzo.ai, not inferred. /v1/authz/check binds
{subject, verb, path}, which is not the {sub, obj, act} its own description
states, so the SDK sends what the handler reads. The two money routes declare an
address and no shape, so budget models them. /v1/audit accepts no requestId
filter though every row carries one, so audit.Filter.Request narrows
client-side. LLM.md carries the whole list.
examples/six walks the composition end to end: what the wallet holds decides
whether to ask, the wallet's own account names the org a policy question is
scoped to, a search states its degradation, a graph write answers a request id,
and that id finds the row the server wrote about it. examples/agent and
examples/tools stop calling operations that were renamed out from under them.
Co-authored-by: Hanzo Dev <[email protected]>
43 lines
1.5 KiB
Go
43 lines
1.5 KiB
Go
// models — the catalogue, with no credential at all.
|
|
//
|
|
// Operation: GET /v1/models (get_models). Four of the document's 2479
|
|
// operations carry `security: []`; the other 2475 inherit the root
|
|
// `security: [{bearer: []}]`. This is one of the four, and the document says
|
|
// why in its own description: the catalogue takes no principal, so the route
|
|
// reads Authorization only to annotate gated SKUs and never to admit.
|
|
//
|
|
// That makes it the one example a reader can run before they have anything —
|
|
// no key, no org, no signup — which is the point of it being here. It is also
|
|
// the honest end of the auth contract: a public route that answers 200 to
|
|
// everyone is not evidence a credential works. `hello` is that evidence.
|
|
//
|
|
// The document states this address and not its shape, so the generated method
|
|
// hands back the raw *http.Response and the reply is decoded here. That decode
|
|
// is local on purpose: it describes what the route answers today, and it
|
|
// disappears the moment cloud declares the handler's type and this client is
|
|
// regenerated.
|
|
//
|
|
// go run ./examples/models
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
|
|
hanzoai "github.com/hanzoai/go-sdk/v8"
|
|
)
|
|
|
|
func main() {
|
|
catalogue, resp, err := hanzoai.New(hanzoai.Options{}).AiAPI.GetModels(context.Background()).Execute()
|
|
if err != nil {
|
|
log.Fatalf("models: %v", err)
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
fmt.Printf("%s %d model(s)\n", resp.Status, len(catalogue.Data))
|
|
for _, m := range catalogue.Data[:min(len(catalogue.Data), 8)] {
|
|
fmt.Printf(" %-28s %s\n", m.GetId(), m.GetOwnedBy())
|
|
}
|
|
}
|