feat(ai): add Kimi For Coding provider support

- Add kimi-coding provider using Anthropic Messages API
- API endpoint: https://api.kimi.com/coding/v1
- Environment variable: KIMI_API_KEY
- Models: kimi-k2-thinking (text), k2p5 (text + image)
- Add context overflow detection pattern for Kimi errors
- Add tests for all standard test suites
This commit is contained in:
Mario Zechner 2026-01-29 04:12:28 +01:00
parent d1e33599f6
commit 87ab5c5c3b
22 changed files with 262 additions and 1 deletions

View file

@ -630,6 +630,33 @@ async function loadModelsDevData(): Promise<Model<any>[]> {
}
}
// Process Kimi For Coding models
if (data["kimi-for-coding"]?.models) {
for (const [modelId, model] of Object.entries(data["kimi-for-coding"].models)) {
const m = model as ModelsDevModel;
if (m.tool_call !== true) continue;
models.push({
id: modelId,
name: m.name || modelId,
api: "anthropic-messages",
provider: "kimi-coding",
// Kimi For Coding's Anthropic-compatible API - SDK appends /v1/messages
baseUrl: "https://api.kimi.com/coding",
reasoning: m.reasoning === true,
input: m.modalities?.input?.includes("image") ? ["text", "image"] : ["text"],
cost: {
input: m.cost?.input || 0,
output: m.cost?.output || 0,
cacheRead: m.cost?.cache_read || 0,
cacheWrite: m.cost?.cache_write || 0,
},
contextWindow: m.limit?.context || 4096,
maxTokens: m.limit?.output || 4096,
});
}
}
console.log(`Loaded ${models.length} tool-capable models from models.dev`);
return models;
} catch (error) {
@ -1130,6 +1157,42 @@ async function generateModels() {
];
allModels.push(...vertexModels);
// Kimi For Coding models (Moonshot AI's Anthropic-compatible coding API)
// Static fallback in case models.dev doesn't have them yet
const KIMI_CODING_BASE_URL = "https://api.kimi.com/coding";
const kimiCodingModels: Model<"anthropic-messages">[] = [
{
id: "kimi-k2-thinking",
name: "Kimi K2 Thinking",
api: "anthropic-messages",
provider: "kimi-coding",
baseUrl: KIMI_CODING_BASE_URL,
reasoning: true,
input: ["text"],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: 262144,
maxTokens: 32768,
},
{
id: "k2p5",
name: "Kimi K2.5",
api: "anthropic-messages",
provider: "kimi-coding",
baseUrl: KIMI_CODING_BASE_URL,
reasoning: true,
input: ["text"],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: 262144,
maxTokens: 32768,
},
];
// Only add if not already present from models.dev
for (const model of kimiCodingModels) {
if (!allModels.some(m => m.provider === "kimi-coding" && m.id === model.id)) {
allModels.push(model);
}
}
const azureOpenAiModels: Model<Api>[] = allModels
.filter((model) => model.provider === "openai" && model.api === "openai-responses")
.map((model) => ({