Skip to content

Commit d25837d

Browse files
committed
fix(xai): default Grok OAuth to chat
1 parent 84d5523 commit d25837d

8 files changed

Lines changed: 334 additions & 59 deletions

‎src/providers/fastwire.ts‎

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -143,34 +143,40 @@ function resolvePolicyAdapter(
143143
inbound: InboundWire,
144144
): { adapter: string; hardPinned: boolean; forwardCallerServiceTier?: boolean } {
145145
// Hard pins and configured overrides deliberately use the same exact-key semantics as
146-
// resolveWireProtocolOverride(). Registry defaults alone normalize ids at their boundary.
146+
// resolveWireProtocolOverride(). Registry route policy normalizes ids at its boundary.
147147
const hardPin = Object.hasOwn(authority.hardPins, modelId)
148148
? authority.hardPins[modelId]
149149
: undefined;
150150
if (typeof hardPin === "string") return { adapter: hardPin, hardPinned: true };
151151
if (authority.modelWireOverrideAllowed) {
152+
const registryDefault = MODEL_ADAPTER_OVERRIDE_ALLOWED.has(authority.providerAdapter)
153+
? registryDefaultForModel(
154+
authority.registryWireDefaults,
155+
modelId,
156+
inbound,
157+
authority.providerAuthMode,
158+
)
159+
: undefined;
152160
const configured = Object.hasOwn(authority.modelAdapters, modelId)
153161
? authority.modelAdapters[modelId]
154162
: undefined;
155163
if (typeof configured === "string" && MODEL_ADAPTER_OVERRIDE_ALLOWED.has(configured)) {
156-
return { adapter: configured, hardPinned: false };
164+
return {
165+
adapter: configured,
166+
hardPinned: false,
167+
...(registryDefault?.forwardCallerServiceTier === false
168+
? { forwardCallerServiceTier: false }
169+
: {}),
170+
};
157171
}
158-
if (MODEL_ADAPTER_OVERRIDE_ALLOWED.has(authority.providerAdapter)) {
159-
const registryDefault = registryDefaultForModel(
160-
authority.registryWireDefaults,
161-
modelId,
162-
inbound,
163-
authority.providerAuthMode,
164-
);
165-
if (registryDefault !== undefined) {
166-
return {
167-
adapter: registryDefault.adapter,
168-
hardPinned: false,
169-
...(registryDefault.forwardCallerServiceTier !== undefined
170-
? { forwardCallerServiceTier: registryDefault.forwardCallerServiceTier }
171-
: {}),
172-
};
173-
}
172+
if (registryDefault !== undefined) {
173+
return {
174+
adapter: registryDefault.adapter,
175+
hardPinned: false,
176+
...(registryDefault.forwardCallerServiceTier !== undefined
177+
? { forwardCallerServiceTier: registryDefault.forwardCallerServiceTier }
178+
: {}),
179+
};
174180
}
175181
}
176182
return { adapter: authority.providerAdapter, hardPinned: false };

‎src/providers/registry.ts‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,19 +1026,18 @@ export const PROVIDER_REGISTRY: readonly ProviderRegistryEntry[] = [
10261026
// grok-4.5; the reasoning ladder does not — 4.6 adds the documented xhigh rung.
10271027
models: ["grok-4.6", "grok-4.5", "grok-4.3", "grok-4.20-0309-reasoning", "grok-4.20-0309-non-reasoning", "grok-build-0.1", "grok-composer-2.5-fast"],
10281028
defaultModel: "grok-4.5",
1029-
// The current Grok CLI catalog declares both subscription models as native Responses
1030-
// backends. Keep API-key and translated Chat/Anthropic callers on their existing wire;
1031-
// Codex Responses traffic can relay xAI's SSE as it arrives instead of waiting for the
1032-
// Chat Completions compatibility stream to flush at the end of a reasoning turn.
1029+
// Keep Codex Responses callers on the compatibility Chat wire until xAI can replay
1030+
// opaque reasoning continuation and compaction state across later turns. The scoped
1031+
// declaration also keeps caller-owned service tiers off the OAuth subscription route.
10331032
modelWireDefaults: {
10341033
"grok-4.6": {
1035-
wire: "openai-responses",
1034+
wire: "openai-chat",
10361035
inbound: ["responses"],
10371036
authModes: ["oauth"],
10381037
forwardCallerServiceTier: false,
10391038
},
10401039
"grok-4.5": {
1041-
wire: "openai-responses",
1040+
wire: "openai-chat",
10421041
inbound: ["responses"],
10431042
authModes: ["oauth"],
10441043
forwardCallerServiceTier: false,

‎structure/04_transports-and-sidecars.md‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ different custom destination does not inherit its upstream assumptions. Object-f
8080
also narrow the decision by inbound protocol and authentication mode; an auth-scoped default must
8181
not leak from a subscription transport into an API-key or forwarded-credential route.
8282

83-
xAI keeps `openai-chat` as its provider-wide compatibility wire. The official Grok CLI catalog
84-
declares the Grok 4.5 and 4.6 subscription models as Responses backends, so only OAuth-backed native
85-
Responses traffic for those exact models selects `openai-responses`. API-key requests, translated
86-
Chat/Anthropic callers, other Grok models, and explicit model adapter overrides retain their
87-
existing wire. This lets Codex receive native xAI SSE deltas as they arrive without widening the
88-
credential or compatibility boundary. These OAuth subscription defaults drop caller-owned
89-
`service_tier`; they neither advertise nor inject Fast. The API-key transport remains governed by
90-
its separate capability declaration.
83+
xAI keeps `openai-chat` as both its provider-wide compatibility wire and the default for Grok 4.5
84+
and 4.6 subscription traffic. The official Grok CLI catalog declares those models as Responses
85+
backends, but the current gateway rejects opaque reasoning continuation and compaction state on
86+
later turns. Operators may still select `openai-responses` with an explicit model adapter override
87+
while that compatibility work continues. The OAuth route drops caller-owned `service_tier` even
88+
when an override selects Responses, and native Responses OAuth 401 replay remains available to
89+
explicit opt-ins. API-key requests, translated Chat/Anthropic callers, and other Grok models retain
90+
their existing wire and tier policy.
9191

9292
OpenCode Go documents `gpt-5.6-luna` on `/zen/go/v1/responses` while sibling models use its Chat or
9393
Anthropic endpoints. The built-in preset therefore selects `openai-responses` only for Luna and

‎tests/adapter-resolve.test.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ describe("registry per-model wire defaults", () => {
100100
});
101101
}
102102

103-
test("routes current xAI subscription models through Responses for native Codex traffic", () => {
103+
test("keeps current xAI subscription models on Chat by default", () => {
104104
for (const model of ["grok-4.6", "grok-4.5"]) {
105105
expect(resolveWireProtocolOverride("xai", model, xai("oauth"), "responses").adapter)
106-
.toBe("openai-responses");
106+
.toBe("openai-chat");
107107
}
108108
});
109109

@@ -118,10 +118,12 @@ describe("registry per-model wire defaults", () => {
118118
.toBe("openai-chat");
119119
});
120120

121-
test("an explicit xAI Chat override opts out of the subscription Responses default", () => {
122-
const provider = xai("oauth", { modelAdapters: { "grok-4.6": "openai-chat" } });
123-
expect(resolveWireProtocolOverride("xai", "grok-4.6", provider, "responses").adapter)
124-
.toBe("openai-chat");
121+
test("an explicit xAI Responses override opts into the native wire", () => {
122+
for (const model of ["grok-4.6", "grok-4.5"]) {
123+
const provider = xai("oauth", { modelAdapters: { [model]: "openai-responses" } });
124+
expect(resolveWireProtocolOverride("xai", model, provider, "responses").adapter)
125+
.toBe("openai-responses");
126+
}
125127
});
126128

127129
function deepseek(overrides: Partial<OcxProviderConfig> = {}): OcxProviderConfig {

‎tests/fastwire-policy.test.ts‎

Lines changed: 89 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -256,25 +256,95 @@ describe("resolveFastPolicy matrix", () => {
256256
expect(fastPolicyForModel(provider, MODEL, "fixture").capability).toBe(false);
257257
});
258258

259-
test("captured xAI registry defaults keep OAuth and key transports separate", () => {
260-
const oauthProvider = Object.freeze({
261-
adapter: "openai-chat",
262-
baseUrl: "https://api.x.ai/v1",
263-
authMode: "oauth" as const,
264-
});
265-
const keyProvider = Object.freeze({
266-
adapter: "openai-chat",
267-
baseUrl: "https://api.x.ai/v1",
268-
authMode: "key" as const,
269-
});
270-
271-
expect(fastPolicyForModel(oauthProvider, "grok-4.6", "xai")).toMatchObject({
272-
adapter: "openai-responses",
273-
eligibility: "unclassified",
274-
forwardCallerTier: false,
275-
});
276-
expect(fastPolicyForModel(keyProvider, "grok-4.6", "xai").adapter)
277-
.toBe("openai-chat");
259+
test("locks the five-row xAI and DeepSeek wire/tier regression matrix", () => {
260+
const rows = [
261+
{
262+
name: "xAI OAuth default",
263+
providerName: "xai",
264+
modelIds: ["grok-4.6", "grok-4.5"],
265+
provider: {
266+
adapter: "openai-chat",
267+
baseUrl: "https://api.x.ai/v1",
268+
authMode: "oauth" as const,
269+
},
270+
adapter: "openai-chat",
271+
forwardCallerTier: false,
272+
callerTier: undefined,
273+
settledCallerTier: undefined,
274+
},
275+
{
276+
name: "xAI OAuth Responses override",
277+
providerName: "xai",
278+
modelIds: ["grok-4.6", "grok-4.5"],
279+
provider: {
280+
adapter: "openai-chat",
281+
baseUrl: "https://api.x.ai/v1",
282+
authMode: "oauth" as const,
283+
modelAdapters: { "grok-4.6": "openai-responses", "grok-4.5": "openai-responses" },
284+
},
285+
adapter: "openai-responses",
286+
forwardCallerTier: false,
287+
callerTier: "flex",
288+
settledCallerTier: undefined,
289+
},
290+
{
291+
name: "xAI API-key default",
292+
providerName: "xai",
293+
modelIds: ["grok-4.6", "grok-4.5"],
294+
provider: {
295+
adapter: "openai-chat",
296+
baseUrl: "https://api.x.ai/v1",
297+
authMode: "key" as const,
298+
},
299+
adapter: "openai-chat",
300+
forwardCallerTier: false,
301+
callerTier: undefined,
302+
settledCallerTier: undefined,
303+
},
304+
{
305+
name: "xAI API-key Responses override",
306+
providerName: "xai",
307+
modelIds: ["grok-4.6", "grok-4.5"],
308+
provider: {
309+
adapter: "openai-chat",
310+
baseUrl: "https://api.x.ai/v1",
311+
authMode: "key" as const,
312+
modelAdapters: { "grok-4.6": "openai-responses", "grok-4.5": "openai-responses" },
313+
},
314+
adapter: "openai-responses",
315+
forwardCallerTier: true,
316+
callerTier: "flex",
317+
settledCallerTier: "flex",
318+
},
319+
{
320+
name: "DeepSeek V4 defaults",
321+
providerName: "deepseek",
322+
modelIds: ["deepseek-v4-flash", "deepseek-v4-pro"],
323+
provider: {
324+
adapter: "openai-chat",
325+
baseUrl: "https://api.deepseek.com",
326+
authMode: "key" as const,
327+
},
328+
adapter: "openai-responses",
329+
forwardCallerTier: false,
330+
callerTier: undefined,
331+
settledCallerTier: undefined,
332+
},
333+
] as const;
334+
335+
for (const row of rows) {
336+
for (const modelId of row.modelIds) {
337+
const policy = fastPolicyForModel(row.provider, modelId, row.providerName);
338+
expect(policy.adapter).toBe(row.adapter);
339+
expect(policy.forwardCallerTier).toBe(row.forwardCallerTier);
340+
expect(tierValueAfterDecision(decideTier(policy, undefined, undefined), undefined))
341+
.toBeUndefined();
342+
if (row.callerTier !== undefined) {
343+
expect(tierValueAfterDecision(decideTier(policy, undefined, row.callerTier), row.callerTier))
344+
.toBe(row.settledCallerTier);
345+
}
346+
}
347+
}
278348
});
279349

280350
test("prototype-named providers and models use only own wire-policy rows", () => {

0 commit comments

Comments
 (0)