Skip to content

feat: add xAI Grok provider support#9832

Closed
avibrahms wants to merge 7 commits intoopenclaw:mainfrom
avibrahms:feat/grok-provider
Closed

feat: add xAI Grok provider support#9832
avibrahms wants to merge 7 commits intoopenclaw:mainfrom
avibrahms:feat/grok-provider

Conversation

@avibrahms
Copy link

@avibrahms avibrahms commented Feb 5, 2026

Overview

This PR adds first-class support for xAI’s Grok models (Grok 2) to OpenClaw. It enables users to select Grok as their LLM provider during the onboarding process (claw onboard) and configures it automatically using an API key.

Changes

  • Provider Core: Added xai-api-key to the authentication choices and xaiApiKey to onboarding options.
  • Model Definitions: Added Grok model constants and a buildXaiModelDefinition helper (defaults to grok-2-latest).
  • Configuration Logic: Implemented applyXaiConfig and applyXaiProviderConfig to manage model aliases, base URLs (api.x.ai/v1), and credential integration.
  • Auth Handler: Created a new applyAuthChoiceXAI handler to manage API key collection and validation.
  • Onboarding Wiring: Registered the xAI handler in the main applyAuthChoice dispatcher.

Verification

  • Ran pnpm build successfully to ensure no type regressions.
  • Verified that the implementation follows the established patterns used for other providers like DeepSeek and Anthropic.

Greptile Overview

Greptile Summary

This PR adds onboarding and configuration support for xAI (Grok) and DeepSeek:

  • Introduces new auth choices and onboarding option fields for supplying provider API keys.
  • Adds model/provider defaults (base URLs, default model IDs/refs, and provider entries under cfg.models.providers).
  • Adds new auth-choice handlers that persist credentials into auth profiles and apply provider config.

The implementation largely follows existing provider patterns, but there are a couple of xAI wiring issues that will prevent users from selecting/configuring xAI correctly in interactive and non-interactive onboarding (called out in review comments).

Confidence Score: 3/5

  • This PR needs fixes before merge due to broken xAI onboarding selection/configuration paths.
  • Provider config additions look consistent with existing patterns, but xAI cannot be selected in interactive onboarding (missing option entry) and the xAI handler silently no-ops when the key is absent, breaking non-interactive onboarding for that auth choice. These are user-facing functional issues that should be addressed before merging.
  • src/commands/auth-choice-options.ts, src/commands/auth-choice.apply.xai.ts

(4/5) You can add custom instructions or style guidelines for the agent here!

- Add DeepSeek to authentication choice types and options
- Create DeepSeek authentication handler following existing patterns
- Implement provider configuration and model definitions
- Wire DeepSeek handler into onboarding flow
- Add setDeepSeekApiKey credential function

Resolves openclaw#7309
Import DEEPSEEK_DEFAULT_MODEL_REF from onboard-auth.models.ts
instead of duplicating it in credentials file to avoid drift.

Addresses feedback from Greptile code review bot.
Implemented xAI Grok as a first-class LLM provider:
- Added 'xai-api-key' to AuthChoice and OnboardOptions
- Defined xAI provider group and choice options
- Added Grok model definitions (grok-2-latest)
- Created applyAuthChoiceXAI handler for API key authentication
- Integrated xAI into the onboarding flow configuration logic
@openclaw-barnacle openclaw-barnacle bot added cli CLI command changes commands Command implementations labels Feb 5, 2026
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +10 to +13
if (authChoice === "xai-api-key") {
const key = params.opts?.xaiApiKey;
if (typeof key !== "string" || key.trim() === "") {
return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-interactive xAI path breaks

applyAuthChoiceXAI returns null when authChoice === "xai-api-key" but opts.xaiApiKey is missing/blank. In the dispatcher (src/commands/auth-choice.apply.ts:60-67), null means “no handler matched”, so onboarding will silently fall through and keep the old config even though the user selected xAI. This will definitely break claw onboard --non-interactive --authChoice xai-api-key unless --xaiApiKey is always provided.

Fix: if authChoice matches, don’t return null—either (a) prompt for the key in interactive mode like other API-key flows, or (b) throw/return an error result in non-interactive mode when the key is missing.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/commands/auth-choice.apply.xai.ts
Line: 10:13

Comment:
**Non-interactive xAI path breaks**

`applyAuthChoiceXAI` returns `null` when `authChoice === "xai-api-key"` but `opts.xaiApiKey` is missing/blank. In the dispatcher (`src/commands/auth-choice.apply.ts:60-67`), `null` means “no handler matched”, so onboarding will silently fall through and keep the old config even though the user selected xAI. This will definitely break `claw onboard --non-interactive --authChoice xai-api-key` unless `--xaiApiKey` is always provided.

Fix: if `authChoice` matches, don’t return `null`—either (a) prompt for the key in interactive mode like other API-key flows, or (b) throw/return an error result in non-interactive mode when the key is missing.

How can I resolve this? If you propose a fix, please make it concise.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 5, 2026

Additional Comments (1)

src/commands/auth-choice-options.ts
Missing xAI choice option

AUTH_CHOICE_GROUP_DEFS includes choices: ["xai-api-key"] (src/commands/auth-choice-options.ts:42-47), but buildAuthChoiceOptions never pushes an option with value: "xai-api-key". As a result, the xAI group will render with an empty options array (it gets filtered out in buildAuthChoiceGroups), so users won’t be able to select Grok during interactive onboarding.

Add an options.push({ value: "xai-api-key", ... }) entry (similar to the DeepSeek one at src/commands/auth-choice-options.ts:235).

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/commands/auth-choice-options.ts
Line: 153:156

Comment:
**Missing xAI choice option**

`AUTH_CHOICE_GROUP_DEFS` includes `choices: ["xai-api-key"]` (`src/commands/auth-choice-options.ts:42-47`), but `buildAuthChoiceOptions` never pushes an option with `value: "xai-api-key"`. As a result, the xAI group will render with an empty `options` array (it gets filtered out in `buildAuthChoiceGroups`), so users won’t be able to select Grok during interactive onboarding.

Add an `options.push({ value: "xai-api-key", ... })` entry (similar to the DeepSeek one at `src/commands/auth-choice-options.ts:235`).

How can I resolve this? If you propose a fix, please make it concise.

@grp06 grp06 self-assigned this Feb 5, 2026
@openclaw-barnacle openclaw-barnacle bot added the agents Agent runtime and tooling label Feb 5, 2026
@grp06
Copy link
Member

grp06 commented Feb 5, 2026

I narrowed this down to xAI-only and opened a replacement PR: #9885.

Rationale:

  • Drops unrelated tagline + package.json gate changes
  • Drops DeepSeek entirely
  • Leaves only xAI (Grok) onboarding + provider config + tests

If you’d prefer to keep #9832 instead of switching PRs, the head branch can be rewritten to just commit 1310e9c (xAI-only) via a force-push.

@grp06
Copy link
Member

grp06 commented Feb 5, 2026

Superseded by #9885 (xAI-only). Closing this PR to avoid duplicate review.

@grp06 grp06 closed this Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling cli CLI command changes commands Command implementations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants