← back to Kimi Mcp

scripts/smoke.mjs

27 lines

#!/usr/bin/env node
// Round-trips the Moonshot API on the configured model to prove auth + model
// are good before wiring the MCP into Claude Code. Reads MOONSHOT_API_KEY from
// env (pass it in — this repo never stores the key).
const KEY = process.env.MOONSHOT_API_KEY;
const MODEL = process.env.KIMI_MODEL || 'kimi-k2.5';
if (!KEY) { console.error('MOONSHOT_API_KEY not set'); process.exit(2); }

const res = await fetch('https://api.moonshot.ai/v1/chat/completions', {
  method: 'POST',
  headers: { Authorization: `Bearer ${KEY}`, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    model: MODEL,
    temperature: 1,
    max_tokens: 64,
    messages: [{ role: 'user', content: 'Reply with exactly: KIMI_OK' }],
  }),
});
if (!res.ok) { console.error(`FAIL ${res.status}: ${await res.text()}`); process.exit(1); }
const data = await res.json();
const msg = data.choices?.[0]?.message || {};
const text = (msg.content || msg.reasoning_content || '').trim();
const u = data.usage || {};
const cost = (u.prompt_tokens || 0) * 5.5e-7 + (u.completion_tokens || 0) * 2.2e-6;
console.log(`model=${MODEL} reply="${text}" tokens=${u.prompt_tokens}/${u.completion_tokens} cost=~$${cost.toFixed(5)}`);
process.exit(text.includes('KIMI_OK') ? 0 : 1);