Files
js-sdk/examples/chat/index.ts
zeekay 936695864f Regenerate against the current cloud spec
The lock sat at 574d1f1d while the product had moved on, so the team
surface stopped at rooms: no messages path, no way to open a room. An app
written against this client had to reach past it with its own fetch, which
is the duplication a generated client exists to prevent.

Three examples and the smoke test named classes the document no longer
emits. Chat and models fold into AiApi at unchanged routes; the KV
provisioning plane moved to /v1/provisioning. None of that was caused by
this regeneration โ€” the suite has been red since those tags folded, which
is what let the drift sit unread.
2026-09-01 02:30:53 -07:00

38 lines
1.3 KiB
TypeScript

// chat โ€” one completion.
//
// POST /v1/chat/completions (post_chat_completions), the OpenAI-compatible
// route. The document states the route and not its shape, so the body rides on
// axios's `data` and the reply is read through a local type. When the schemas
// land both become generated and this file loses its casts.
//
// A model id is a string, so the wrong one type-checks perfectly and fails on
// the wire. `zen5` is served today; GET /v1/models is the only authority on the
// rest, which is what the quickstart in the README prints.
import { AiApi } from 'hanzoai';
import { config, fail } from '../client';
const model = process.env.HANZO_MODEL ?? 'zen5';
type Completion = {
model?: string;
choices?: Array<{ message?: { role?: string; content?: string } }>;
usage?: { total_tokens?: number };
};
async function main() {
const chat = new AiApi(config());
const { data } = await chat.postChatCompletions({
data: {
model,
messages: [{ role: 'user', content: 'Say hello in exactly five words.' }],
},
});
const reply = data as unknown as Completion;
console.log(reply.choices?.[0]?.message?.content ?? '(no content)');
console.log(` ${reply.model ?? model} ยท ${reply.usage?.total_tokens ?? '?'} tokens`);
}
main().catch(fail);