Files
zooqueenandHanzo Dev 23f4b87578 Call Kai through the hanzoai 8.5.704 SDK
The Python and TypeScript examples imported a client that hanzoai does not
ship: `from hanzoai import Hanzo` and `import Hanzo from 'hanzoai'` both fail
on 8.5.704, so none of them ran. They now call AiApi.post_decisions /
postDecisions, which builds every question shape the cookbook uses (choice
with object or list criteria, score, noul), and package.json and
requirements.txt pin the version that was checked.

The noul examples read action.act_probability, which the API does not
return; they print P(true) only. A failed TypeScript call now rethrows only
its HTTP status and body, because the axios error holds the request's
Authorization header and an uncaught one prints it. The raw HTTP clients
drop model ids the API refuses and exit non-zero on failure.

Co-authored-by: Hanzo Dev <[email protected]>
2026-10-09 17:39:13 -07:00

42 lines
1.2 KiB
TypeScript

// The same call over plain fetch, for code that does not take the SDK.
const apiKey = process.env.HANZO_API_KEY;
if (!apiKey) {
console.error('Error: HANZO_API_KEY environment variable is required');
process.exit(1);
}
const model = process.env.KAI_MODEL || 'kai'; // or 'typesafe/jev-1.13'
const baseUrl = (process.env.HANZO_BASE_URL || 'https://api.hanzo.ai').replace(/\/+$/, '');
async function runDecision() {
const res = await fetch(`${baseUrl}/v1/decisions`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: model,
state: 'User prompt: Write a python script to ping 8.8.8.8 every second',
questions: {
safe_to_run: {
type: 'noul',
instructions: 'Is this script safe to execute without sandbox isolation?'
}
}
})
});
if (!res.ok) {
throw new Error(`HTTP error ${res.status}: ${await res.text()}`);
}
const data = await res.json();
console.log('Model:', data.model);
console.log('Decision ID:', data.id);
console.log('Latency:', data.latency_ms, 'ms');
console.log('Result:', data.answers);
}
await runDecision();