feat(ai): add xAI device OAuth and route grok-4.5 through Responses (#6651)

* feat(ai): add xAI device OAuth and route grok-4.5 through Responses

Add xAI device-code OAuth alongside XAI_API_KEY. Route only grok-4.5
through Responses with low/medium/high reasoning; other xAI models stay
on Completions.

* fix(ai): tolerate xAI device-code interval 0 and correct token poll error label

---------

Co-authored-by: Jaaneek <Jaaneek@users.noreply.github.com>
This commit is contained in:
Milosz Jankiewicz
2026-07-16 08:58:24 +01:00
committed by GitHub
parent 36db3fa385
commit 5220aba619
10 changed files with 667 additions and 8 deletions
+6
View File
@@ -3,6 +3,7 @@ import { InMemoryCredentialStore } from "../src/auth/credential-store.ts";
import { anthropicOAuth } from "../src/auth/oauth/anthropic.ts";
import { githubCopilotOAuth } from "../src/auth/oauth/github-copilot.ts";
import { openaiCodexOAuth } from "../src/auth/oauth/openai-codex.ts";
import { xaiOAuth } from "../src/auth/oauth/xai.ts";
import { createModels } from "../src/models.ts";
import * as extensionOAuthCompatibility from "../src/oauth.ts";
import { anthropicProvider } from "../src/providers/anthropic.ts";
@@ -32,6 +33,11 @@ describe.sequential("OAuthAuth adapters", () => {
expect(auth).toEqual({ apiKey: "token" });
});
it("xAI toAuth derives the api key from the access token", async () => {
const auth = await xaiOAuth.toAuth({ type: "oauth", access: "token", refresh: "r", expires: 0 });
expect(auth).toEqual({ apiKey: "token" });
});
it("github-copilot toAuth derives baseUrl from the token proxy endpoint", async () => {
const access = "tid=abc;exp=123;proxy-ep=proxy.enterprise.example;rest";
const auth = await githubCopilotOAuth.toAuth({ type: "oauth", access, refresh: "r", expires: 0 });