Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

fix(providers): Moonshot-only kimi-k3 stays on api.moonshot.ai

Rach Pradhan682945110228
diff --git a/src/pricing.zig b/src/pricing.zig
index fc0f4356..af8c4b67 100644
--- a/src/pricing.zig
+++ b/src/pricing.zig
@@ -287,6 +287,10 @@ pub const model_table = [_]ModelInfo{
.{ .provider = "kimi", .name = "kimi-for-coding", .context = 262_144, .protocol = .kimi, .supports_reasoning = true },
.{ .provider = "kimi", .name = "kimi-for-coding-highspeed", .context = 262_144, .protocol = .kimi, .supports_reasoning = true },
.{ .provider = "moonshot", .name = "kimi-latest", .context = 131_072 },
+ // Moonshot platform K3 (api.moonshot.ai, model id `kimi-k3`). Distinct from
+ // Kimi Code's native `k3` row: `--model kimi-k3` with only MOONSHOT_API_KEY
+ // must not rewrite onto the coding-plan login.
+ .{ .provider = "moonshot", .name = "kimi-k3", .context = 1_048_576, .supports_reasoning = true, .support_efforts = &.{ "low", "high", "max" }, .default_effort = "max" },
.{ .provider = "xai", .name = "grok-4.6", .context = 500_000, .supports_reasoning = true },
.{ .provider = "xai", .name = "grok-4.3", .context = 1_000_000 },
.{ .provider = "xai", .name = "grok-build", .context = 256_000 },
@@ -490,10 +494,16 @@ pub fn familyAliasEquals(provider_id: []const u8, name: []const u8, query: []con
/// `keys` is main.zig's Keys (anytype to keep provider wiring out of this
/// module) — anything with `get(provider_id) ?[]const u8`.
pub fn resolveModelName(keys: anytype, query: []const u8) ?[]const u8 {
+ // #377: `kimi-k3` is Kimi Code's family spelling of `k3`. Moonshot's
+ // platform id is also `kimi-k3`. A keyed kimi login keeps the rewrite; a
+ // moonshot-only key keeps the Moonshot row (exact match below).
+ const kimi_keyed = keys.get("kimi") != null;
+ const moonshot_keyed = keys.get("moonshot") != null;
+ if (kimi_keyed or !moonshot_keyed) {
+ if (familyAliasEquals("kimi", "k3", query)) return "k3";
+ }
for (models()) |m| if (std.mem.eql(u8, m.name, query)) return m.name;
for (models()) |m| if (modelAliasEquals(m.name, query)) return m.name;
- // #377: family-prefixed spelling of a provider's own row (`kimi-k3` → kimi's
- // `k3`) — resolves even when no gateway catalog supplies the prefixed name.
for (models()) |m| if (familyAliasEquals(m.provider, m.name, query)) return m.name;
var qbuf: [128]u8 = undefined;
const qnorm = normalizeModelAlias(&qbuf, query);
diff --git a/src/pricing_tests.zig b/src/pricing_tests.zig
index 7448672b..6b159c8e 100644
--- a/src/pricing_tests.zig
+++ b/src/pricing_tests.zig
@@ -51,6 +51,12 @@ test "resolveModelName (#377): family-prefixed spelling resolves to the provider
try std.testing.expect(pricing.familyAliasEquals("kimi", "k3", "kimi_k3"));
try std.testing.expect(!pricing.familyAliasEquals("kimi", "k3", "kimi-k30"));
try std.testing.expect(!pricing.familyAliasEquals("codex", "k3", "kimi-k3"));
+ var moon_values: [provider_mod.provider_specs.len]?[]const u8 = @splat(null);
+ for (provider_mod.provider_specs, 0..) |spec, i| {
+ if (std.mem.eql(u8, spec.id, "moonshot")) moon_values[i] = "k";
+ }
+ const moonshot_only = provider_mod.Keys{ .values = moon_values };
+ try std.testing.expectEqualStrings("kimi-k3", pricing.resolveModelName(moonshot_only, "kimi-k3").?);
}
test "resolveModelName: 5.6 sol prefers Codex gpt-5.6-sol over a gateway slug" {
diff --git a/src/provider.zig b/src/provider.zig
index c72630d4..fe114b3f 100644
--- a/src/provider.zig
+++ b/src/provider.zig
@@ -385,6 +385,15 @@ pub const Keys = struct {
// `kimi-k3` while kimi itself serves `k3`; the flat-rate login must win
// over the gateway for the same model, so the query is rewritten to the
// provider's native spelling. Phase 2: the gateway, exact, as fallback.
+ // Moonshot's platform id is also `kimi-k3`; when the kimi login is
+ // present it still wins. When only MOONSHOT_API_KEY is set, phase 0
+ // seats the moonshot row instead of falling through to the gateway.
+ if (keys.get("kimi")) |kimi_key| {
+ if (pricing.familyAliasEquals("kimi", "k3", model)) {
+ const spec = specFor("kimi") orelse return error.MissingKey;
+ return keys.build(spec, kimi_key, "k3");
+ }
+ }
for ([_]u8{ 0, 1, 2 }) |phase| {
for (0..specCount()) |i| {
const spec = specAt(i).?;
diff --git a/src/router_catalog_tests.zig b/src/router_catalog_tests.zig
index 8b21c217..3fb54768 100644
--- a/src/router_catalog_tests.zig
+++ b/src/router_catalog_tests.zig
@@ -336,14 +336,28 @@ test "providerFor (#377): family-prefixed spelling routes to the direct provider
try std.testing.expectEqualStrings("k3", p.model);
// Exact catalog names keep absolute priority over the family alias.
try std.testing.expectEqualStrings("gpt-5.6-sol", (try all.providerFor("gpt-5.6-sol")).model);
- // Without the kimi credential the prefixed spelling behaves exactly as
- // before: uncatalogued in the compiled table, so the gateway fallback.
+ // Without the kimi credential, Moonshot's platform id `kimi-k3` is an
+ // exact catalog row — not the gateway.
var values: [provider.provider_specs.len]?[]const u8 = @splat("k");
for (provider.provider_specs, 0..) |spec, i| {
if (std.mem.eql(u8, spec.id, "kimi")) values[i] = null;
}
const no_kimi = Keys{ .values = values };
- try std.testing.expectEqualStrings("codegraff", (try no_kimi.providerFor("kimi-k3")).id);
+ const moon = try no_kimi.providerFor("kimi-k3");
+ try std.testing.expectEqualStrings("moonshot", moon.id);
+ try std.testing.expectEqualStrings("kimi-k3", moon.model);
+}
+
+test "providerFor: moonshot-only kimi-k3 stays on api.moonshot.ai" {
+ const Keys = provider.Keys;
+ var values: [provider.provider_specs.len]?[]const u8 = @splat(null);
+ for (provider.provider_specs, 0..) |spec, i| {
+ if (std.mem.eql(u8, spec.id, "moonshot")) values[i] = "k";
+ }
+ const moonshot_only = Keys{ .values = values };
+ const p = try moonshot_only.providerFor("kimi-k3");
+ try std.testing.expectEqualStrings("moonshot", p.id);
+ try std.testing.expectEqualStrings("kimi-k3", p.model);
}
test "xAI defaults to the Responses wire; GRAFF_XAI_WIRE=chat opts out (#502)" {