import { rawPost, rawGet, save, short, BASE } from "./lib.ts"; const out: Record = {}; const tiny = { model: "kimi-k2.6", messages: [{ role: "user", content: "hi" }], max_tokens: 5, thinking: { type: "disabled" } }; // (g) invalid key const bad = await rawPost("/chat/completions", tiny, {}, "sk-invalid-key-000000"); console.log("invalid key:", bad.status, JSON.stringify(bad.body), JSON.stringify(bad.headers)); out.invalidKey = bad; const badModels = await rawGet("/models", "sk-invalid-key-000000"); console.log("invalid key GET /models:", badModels.status, JSON.stringify(badModels.body)); out.invalidKeyModels = badModels; // no auth header const noAuth = await fetch(`${BASE}/chat/completions`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(tiny) }); console.log("no auth:", noAuth.status, (await noAuth.text()).slice(0, 300)); // (h) unknown model const unk = await rawPost("/chat/completions", { ...tiny, model: "kimi-k99" }); console.log("unknown model:", unk.status, JSON.stringify(unk.body)); out.unknownModel = unk; // retired slugs for (const m of ["kimi-k2.5", "kimi-k2-thinking", "moonshot-v1-8k", "kimi-latest", "kimi-k2-0905-preview"]) { const r = await rawPost("/chat/completions", { model: m, messages: [{ role: "user", content: "hi" }], max_tokens: 5 }); console.log(`retired ${m}:`, r.status, short(r.body, 200)); out[`retired:${m}`] = r; } // malformed body const mal = await fetch(`${BASE}/chat/completions`, { method: "POST", headers: { "content-type": "application/json", authorization: `Bearer ${process.env.KIMI_API_KEY}` }, body: "{\"model\":\"kimi-k2.6\",\"messages\":\"nope\"}" }); console.log("malformed messages:", mal.status, (await mal.text()).slice(0, 300)); // missing messages const miss = await rawPost("/chat/completions", { model: "kimi-k2.6" }); console.log("missing messages:", miss.status, JSON.stringify(miss.body)); out.missingMessages = miss; // (j) max output limits: oversize max_tokens per model for (const [model, mt] of [["kimi-k2.6", 40000], ["kimi-k2.6", 300000], ["kimi-k2.7-code", 300000], ["kimi-k2.7-code-highspeed", 300000], ["kimi-k3", 1048576], ["kimi-k3", 1048577], ["kimi-k3", 2000000]] as const) { const r = await rawPost("/chat/completions", { model, messages: [{ role: "user", content: "Reply: ok" }], max_tokens: mt }); console.log(`max_tokens=${mt} on ${model}:`, r.status, r.status === 200 ? `finish=${(r.body as any).choices[0].finish_reason} usage=${JSON.stringify((r.body as any).usage)}` : short(r.body, 300)); out[`maxTokens:${model}:${mt}`] = { status: r.status, body: r.status === 200 ? { usage: (r.body as any).usage } : r.body }; } // context overflow: ~300k tokens of text to k2.6 (262144 ctx) const big = "lorem ipsum dolor sit amet ".repeat(60000); // ~ 300k+ tokens const ov = await rawPost("/chat/completions", { model: "kimi-k2.6", messages: [{ role: "user", content: big + "\nReply ok." }], max_tokens: 5, thinking: { type: "disabled" } }); console.log("context overflow k2.6:", ov.status, short(ov.body, 300)); out.contextOverflow = ov; // tool_choice forced function with thinking enabled on k2.6 (docs: 400) const forced = await rawPost("/chat/completions", { model: "kimi-k2.6", messages: [{ role: "user", content: "Weather in Montreal?" }], tools: [{ type: "function", function: { name: "get_weather", parameters: { type: "object", properties: { city: { type: "string" } } } } }], tool_choice: { type: "function", function: { name: "get_weather" } }, thinking: { type: "disabled" }, max_tokens: 200 }); console.log("k2.6 forced tool + thinking disabled:", forced.status, short((forced.body as any)?.choices?.[0]?.message?.tool_calls ?? forced.body, 200)); out.forcedToolNoThinking = forced; // cache hit check: same >256-token prompt twice on k2.6 non-thinking const long = "You are a helpful assistant. " + "The quick brown fox jumps over the lazy dog. ".repeat(80); const c1 = await rawPost("/chat/completions", { model: "kimi-k2.6", messages: [{ role: "system", content: long }, { role: "user", content: "Reply: ok" }], max_tokens: 5, thinking: { type: "disabled" } }); await new Promise((r) => setTimeout(r, 1500)); const c2 = await rawPost("/chat/completions", { model: "kimi-k2.6", messages: [{ role: "system", content: long }, { role: "user", content: "Reply: ok" }], max_tokens: 5, thinking: { type: "disabled" } }); console.log("cache probe usage #1:", JSON.stringify((c1.body as any)?.usage), "#2:", JSON.stringify((c2.body as any)?.usage)); out.cache = { c1: (c1.body as any)?.usage, c2: (c2.body as any)?.usage, headers2: c2.headers }; // partial mode const partial = await rawPost("/chat/completions", { model: "kimi-k2.6", messages: [{ role: "user", content: "Name three colours." }, { role: "assistant", content: "Sure! The three colours are:", partial: true }], max_tokens: 60, thinking: { type: "disabled" } }); console.log("partial mode k2.6 non-thinking:", partial.status, short((partial.body as any)?.choices?.[0]?.message?.content ?? partial.body, 200)); out.partial = partial; save("05-errors-limits", out);