Skip to content

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

Python

Add grok-4.7 as the xAI default.

justrach588963a52094
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ea55813d..c8e83cf1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,7 @@ current is part of cutting a release.
- Task workspace housekeeping: `graff worktree update` merges the remote base; `gc` drops dead session trees and clean trees whose GitHub PR is MERGED (dirty trees stay). Desktop: Update from main, Clear unused trees. Asking to free space unfolds `workspace` so `action=gc` is callable this turn.
- xAI Responses WS chains `previous_response_id` on the held socket (store:false in-memory cache) and `generate:false` prewarms a fresh socket. A stalled first handshake or 426 latches HTTPS SSE for the session; chrome shows a dim `using HTTPS SSE` notice. `GRAFF_XAI_WS_CHAIN=0` opts out.
- HTTPS SSE prefers HTTP/2 (`justrach/http-zig`): connection reuse, ALPN `h2`, first-failure HTTP/1.1 latch. `GRAFF_HTTP2=0` forces 1.1.
+- grok-4.7 is the xAI default (500k, same dual-band $2/$6 and 200k high band as 4.6; efforts still low|medium|high|xhigh).
## v0.0.302.3
diff --git a/src/effort_route.zig b/src/effort_route.zig
index 7d7db268..42b3a397 100644
--- a/src/effort_route.zig
+++ b/src/effort_route.zig
@@ -141,7 +141,10 @@ test "flash and Gemini map default medium to low; grok and glm-5.3 stay medium"
try std.testing.expectEqualStrings("high", wireEffort("grok-4.6", "ultra"));
try std.testing.expectEqualStrings("high", wireEffort("grok-4.6", "max"));
try std.testing.expectEqualStrings("xhigh", wireEffort("grok-4.6", "xhigh"));
+ try std.testing.expectEqualStrings("xhigh", wireEffort("grok-4.7", "xhigh"));
+ try std.testing.expectEqualStrings("high", wireEffort("grok-4.7", "ultra"));
try std.testing.expect(hidesMax("xai", "grok-4.6"));
+ try std.testing.expect(hidesMax("xai", "grok-4.7"));
try std.testing.expect(!hidesMax("codex", "gpt-5.6-sol"));
try std.testing.expect(!allows("xai", "grok-4.6", "max"));
try std.testing.expect(allows("xai", "grok-4.6", "high"));
diff --git a/src/oauth.zig b/src/oauth.zig
index 70c81489..255667a5 100644
--- a/src/oauth.zig
+++ b/src/oauth.zig
@@ -446,7 +446,7 @@ pub fn xaiLogin(io: Io, gpa: Allocator, arena: Allocator, home: []const u8) !voi
const refresh = strFieldObj(resp, "refresh_token") orelse "";
const expires_in: i64 = if (resp.get("expires_in")) |ei| (if (ei == .integer) ei.integer else 3600) else 3600;
try writeXaiAuth(io, arena, home, a.string, refresh, @divTrunc(unixMs(io), 1000) + expires_in);
- try out.print("✓ logged into Grok (xAI) — wrote {s}. /model xai grok-4.6\n", .{xaiAuthPath(arena, home)});
+ try out.print("✓ logged into Grok (xAI) — wrote {s}. /model xai grok-4.7\n", .{xaiAuthPath(arena, home)});
try out.writeAll(" note: xAI gates its OpenAI-compatible API per account — if a Grok turn 403s, your account isn't allowlisted for api.x.ai yet.\n");
try out.flush();
return;
diff --git a/src/pricing.zig b/src/pricing.zig
index d834a0b2..ae04b152 100644
--- a/src/pricing.zig
+++ b/src/pricing.zig
@@ -50,6 +50,7 @@ pub const price_table = [_]ModelPrice{
.{ .name = "kimi-k2.6", .in = 0.95, .out = 4, .cache = 0.1 },
.{ .name = "kimi-k2-thinking", .in = 0.6, .out = 2.5, .cache = 0.06 },
.{ .name = "kimi-k2.5", .in = 0.6, .out = 3, .cache = 0.06 },
+ .{ .name = "grok-4.7", .in = 2, .out = 6, .cache = 0.5, .high_at = 200_000, .high_in = 4, .high_out = 12, .high_cache = 1 },
.{ .name = "grok-4.6", .in = 2, .out = 6, .cache = 0.5, .high_at = 200_000, .high_in = 4, .high_out = 12, .high_cache = 1 },
.{ .name = "muse-spark-1.2", .in = 1.25, .out = 4.25, .cache = 0.125 },
.{ .name = "muse-spark-1.2-contributor", .in = 0.1, .out = 0.2, .cache = 0.01 },
@@ -287,6 +288,7 @@ pub const model_table = [_]ModelInfo{
.{ .provider = "codegraff", .name = "gpt-5.6", .context = 1_050_000 },
.{ .provider = "codegraff", .name = "gpt-5.5", .context = 400_000 },
.{ .provider = "codegraff", .name = "kimi-k2.6", .context = 262_144 },
+ .{ .provider = "codegraff", .name = "grok-4.7", .context = 500_000 },
.{ .provider = "codegraff", .name = "grok-4.6", .context = 500_000 },
.{ .provider = "codegraff", .name = "grok-build", .context = 256_000 },
.{ .provider = "codegraff", .name = "glm-5.2", .context = 204_800 },
@@ -307,6 +309,7 @@ pub const model_table = [_]ModelInfo{
// 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.7", .context = 500_000, .supports_reasoning = true },
.{ .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 },
diff --git a/src/pricing_tests.zig b/src/pricing_tests.zig
index 0af28b4e..0048ce17 100644
--- a/src/pricing_tests.zig
+++ b/src/pricing_tests.zig
@@ -126,12 +126,21 @@ test "grok-4.6 prices: low band under 200k, high band for the whole request at
try std.testing.expectApproxEqAbs(@as(f64, 0.25), pricing.usdFor(old, 200_000, 0, 0), 1e-12);
}
-test "xAI default model is grok-4.6 and is catalogued" {
+test "xAI default model is grok-4.7 and is catalogued" {
const spec = provider_mod.specFor("xai") orelse return error.MissingXaiSpec;
- try std.testing.expectEqualStrings("grok-4.6", spec.default_model);
+ try std.testing.expectEqualStrings("grok-4.7", spec.default_model);
+ try std.testing.expect(pricing.providerModelInTable("xai", "grok-4.7"));
try std.testing.expect(pricing.providerModelInTable("xai", "grok-4.6"));
}
+test "grok-4.7 window and dual-band prices match 4.6" {
+ try std.testing.expectEqual(@as(u64, 500_000), pricing.contextFor("xai", "grok-4.7"));
+ const p = pricing.priceFor("grok-4.7") orelse return error.MissingGrok47Price;
+ try std.testing.expectEqual(@as(u64, 200_000), p.high_at);
+ try std.testing.expectApproxEqAbs(@as(f64, 0.024), pricing.usdFor(p, 10_000, 2_000, 500), 1e-12);
+ try std.testing.expectApproxEqAbs(@as(f64, 0.812), pricing.usdFor(p, 200_000, 0, 1_000), 1e-12);
+}
+
test "contextFor known model and default fallback" {
try std.testing.expectEqual(@as(u64, 1_048_576), pricing.contextFor("kimi", "k3"));
try std.testing.expectEqual(@as(u64, pricing.default_context), pricing.contextFor("nope", "unknown-xyz"));
diff --git a/src/provider.zig b/src/provider.zig
index 695d4e7e..8fb2cbbb 100644
--- a/src/provider.zig
+++ b/src/provider.zig
@@ -102,7 +102,7 @@ pub const provider_specs = [_]ProviderSpec{
.{ .id = "moonshot", .display_name = "Moonshot", .kind = .openai, .auth = .bearer, .url = "https://api.moonshot.ai/v1/chat/completions", .env_key = "MOONSHOT_API_KEY", .default_model = "kimi-latest" },
// `graff login xai` is a real device-code OAuth flow (oauth.zig), so xAI's
// login is a SuperGrok plan while XAI_API_KEY is metered api.x.ai access.
- .{ .id = "xai", .display_name = "xAI", .kind = .openai, .auth = .bearer, .url = "https://api.x.ai/v1/chat/completions", .env_key = "XAI_API_KEY", .default_model = "grok-4.6", .login = .xai_device, .sub_login = true, .catalog = .openai, .models_url = "https://api.x.ai/v1/models" },
+ .{ .id = "xai", .display_name = "xAI", .kind = .openai, .auth = .bearer, .url = "https://api.x.ai/v1/chat/completions", .env_key = "XAI_API_KEY", .default_model = "grok-4.7", .login = .xai_device, .sub_login = true, .catalog = .openai, .models_url = "https://api.x.ai/v1/models" },
.{ .id = "zai", .display_name = "Z.AI", .kind = .openai, .auth = .bearer, .url = "https://api.z.ai/api/paas/v4/chat/completions", .env_key = "ZAI_API_KEY", .default_model = "glm-5.3", .login = .zai_cli, .sub_login = true, .catalog = .openai, .models_url = "https://api.z.ai/api/paas/v4/models", .takes_effort = true },
// OpenAI-compatible Chat Completions with reasoning_effort support.
.{ .id = "meta", .display_name = "Meta", .kind = .openai, .auth = .bearer, .url = "https://api.meta.ai/v1/chat/completions", .env_key = "META_API_KEY", .default_model = "muse-spark-1.2-contributor", .catalog = .openai, .models_url = "https://api.meta.ai/v1/models", .takes_effort = true },