Files
zeekayandHanzo Dev 412d7b2a11 feat: the six capabilities, and a credential the client mints itself
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]>
2026-09-10 14:51:06 -07:00

48 lines
1.7 KiB
Go

// hello — prove the key works.
//
// Operation: GET /v1/account/keys (get_account_keys), the caller's own API keys.
//
// This flow's whole job is to FAIL on a bad key, so the route is chosen by
// probing api.hanzo.ai rather than by reading the document. Three
// identity-shaped routes are disqualified for answering 200 to a caller
// carrying no credential at all — GET /v1/ai/account (type="anonymous-user"),
// GET /v1/iam/whoami and GET /v1/iam/account (both 200 {"status":"error"}) —
// and a hello built on any of them prints a cheerful identity for a key that
// would be refused everywhere else.
//
// /v1/keys answers 403 {"code":"forbidden","error":"sign in to manage API
// keys"} with no key and with a bogus one, while the nonsense sibling
// /v1/keys-zzq9 answers 404, so the 403 is this route refusing rather than a
// wildcard route swallowing the address.
//
// This replaces bot_authMe (GET /v1/bot/auth/me), which no longer resolves:
// cloud relays all of /v1/bot through one app.All("/v1/bot/*"), so the document
// carries /v1/bot/{wildcard1} and no operation at that address.
//
// HANZO_CLIENT_ID=... HANZO_CLIENT_SECRET=... go run ./examples/hello
package main
import (
"context"
"fmt"
"log"
hanzoai "github.com/hanzoai/go-sdk/v8"
)
func main() {
client := hanzoai.New(hanzoai.Options{})
listing, _, err := client.AccountAPI.GetAccountKeys(context.Background()).Execute()
if err != nil {
log.Fatalf("keys: %v", err)
}
keys := listing.Keys
fmt.Printf("the key is accepted; this org holds %d key(s)\n", len(keys))
for _, key := range keys {
// Prefix is the recognizable head of a key, never enough to use one.
fmt.Printf(" %-12s %s\n", key.GetType(), key.GetPrefix())
}
}