Skip to content

Conversation

@jackjackbits
Copy link
Contributor

@jackjackbits jackjackbits commented Jun 17, 2025

Add xAI Provider Support for Grok Models

Summary

This PR adds comprehensive support for xAI's Grok models to Goose, enabling users to interact with models like grok-3, grok-3-mini, and grok-3-fast through the xAI API. The implementation includes both CLI and GUI support with proper authentication, context limits, and visual branding.

Motivation

xAI's Grok models offer competitive performance with a large 131,072 token context window, making them valuable alternatives for users seeking high-capacity language models. This addition expands Goose's provider ecosystem and gives users more flexibility in choosing their preferred AI models.

Changes

Core Provider Implementation

  • New xAI Provider (crates/goose/src/providers/xai.rs)

    • Implements the Goose provider interface for xAI API
    • Proper authentication via XAI_API_KEY environment variable or config
    • Configurable host with default to https://api.x.ai/v1
    • Full streaming support for responses
  • Provider Integration

    • Added xAI to provider factory (crates/goose/src/providers/factory.rs)
    • Registered in provider module (crates/goose/src/providers/mod.rs)
    • Added to desktop app provider registry

Model Support

  • Context Limits (crates/goose/src/model.rs)

    • Added Grok models to MODEL_SPECIFIC_LIMITS with 131,072 token limit
    • Ensures proper context window display in both CLI and GUI
  • Supported Models

    • grok-3
    • grok-3-mini
    • grok-3-fast
    • grok-2-vision-1212
    • grok-vision
    • grok-2
    • grok
    • grok-1.5

GUI Integration

  • Provider Logo

    • Added custom xAI logo to provider selection modal
    • Implemented CSS invert filter to handle black logo on dark background
    • Adjusted logo size (w-8 h-8) to fit properly within circular container
  • Desktop App Support

    • Full integration with Settings → Providers interface
    • Seamless model selection and configuration

Documentation

  • Updated documentation/docs/getting-started/providers.md to include xAI
  • Added configuration details and API key requirements

Bug Fixes

  • Fixed API URL construction issue where base URL wasn't properly joined with endpoint path
  • Ensured trailing slash handling for proper URL formation
  • Fixed context limit display (was showing 0/32000, now correctly shows 0/131072)

Testing

  • ✅ Provider authentication and API calls working
  • ✅ Context limits display correctly in both CLI and GUI
  • ✅ Logo displays properly with correct sizing and visibility
  • ✅ All linting and formatting checks pass
  • ✅ Rust compilation with no warnings

Usage

CLI

# Set API key
export XAI_API_KEY=your-api-key

# Start a session
goose session --model grok-3

GUI

  1. Open Goose Desktop
  2. Go to Settings → Providers
  3. Click "Add Provider" and select xAI
  4. Enter your API key
  5. Select your preferred Grok model

Configuration File

# ~/.config/goose/config.yaml
XAI_API_KEY: your-api-key
provider: xai
model: grok-3

Screenshots

Screenshot 2025-06-18 at 00 15 31

Notes

  • The xAI logo required special handling due to being black text on transparent background
  • CSS filter inversion and size adjustment ensure proper visibility in dark mode
  • API endpoint confirmed working at https://api.x.ai/v1/chat/completions

Checklist

  • Code compiles without errors
  • All tests pass
  • Linting checks pass
  • Documentation updated
  • UI/UX tested in both light and dark modes
  • API integration tested with real API key

jack added 8 commits June 17, 2025 23:01
- Added XaiProvider in crates/goose/src/providers/xai.rs with support for all Grok models
- Supports grok-3, grok-3-fast, grok-3-mini, grok-3-mini-fast, grok-2-vision, grok-2-image, and legacy models
- Follows x.ai OpenAI-compatible API format (https://api.x.ai/v1/chat/completions)
- Requires XAI_API_KEY environment variable for authentication
- Optional XAI_HOST configuration (defaults to https://api.x.ai)
- Updated factory.rs to include xAI provider in the provider registry
- Added xAI to the GUI provider registry in ProviderRegistry.tsx
- Includes proper error handling for authentication, rate limits, and server errors
- All tests pass, code formatted and lints clean
- Changed XAI_API_HOST from 'https://api.x.ai' to 'https://api.x.ai/v1'
- Updated URL joining to append 'chat/completions' instead of 'v1/chat/completions'
- This creates the correct endpoint: https://api.x.ai/v1/chat/completions
- Updated UI provider registry with correct default host
- Tested with curl and confirmed API returns proper 400 auth error instead of 404
- Added 'grok' pattern to MODEL_SPECIFIC_LIMITS with 131_072 token limit
- This fixes the issue where CLI was showing 0/32000 tokens for Grok models
- All Grok models (grok-3, grok-3-mini, etc) now correctly show 0/131072 tokens
- Added debug logging to xAI provider for better troubleshooting
@jackjackbits
Copy link
Contributor Author

Screenshot

Here's the xAI provider with the custom logo in the Settings interface:

(Uploading screenshot...)

@FaresKi
Copy link

FaresKi commented Jun 17, 2025

looks good to me jack, i'd approve if i could 👍🏽

…se into jackjackbits-feature/add-grok-models

* 'feature/add-grok-models' of github.com:jackjackbits/goose:
  Add xAI to supported providers documentation
  Reduce xAI logo size to fit properly within circle
  Fix xAI logo visibility by applying CSS invert filter for black logo
  Add xAI logo to GUI provider selection
  Fix xAI API URL construction by ensuring base URL ends with slash
  Add Grok model context limits (131K tokens)
  Fix xAI API endpoint URL
  Add xAI provider support for Grok models
@michaelneale
Copy link
Collaborator

updated this to main and added .gitignore, hopefully didn't mess up the history (well hopefully goose didn't!), seemed to work for me

@salman1993
Copy link
Contributor

salman1993 commented Jun 18, 2025

it'd be good to add a test for xai provider, similar to the one here:

#[tokio::test]
async fn test_anthropic_provider() -> Result<()> {
test_provider(
"Anthropic",
&["ANTHROPIC_API_KEY"],
None,
anthropic::AnthropicProvider::default,
)
.await
}

@michaelneale
Copy link
Collaborator

also don't worry about the apparent "extra" changes (which are already on main) its a forever github bug with showing synced fork diffs (will see if can get rid of it, but they aren't actual changes as already on main upstream/origin!)

@michaelneale michaelneale changed the base branch from main to micn/main June 18, 2025 03:21
@michaelneale michaelneale changed the base branch from micn/main to main June 18, 2025 03:22
@michaelneale
Copy link
Collaborator

.. and cleaned up history again from github quirk

@block block deleted a comment from joanna2028 Jun 18, 2025
@realtamimuddin
Copy link

wow

@eminogrande
Copy link

Fantastic and this is all made with https://github.com/block/goose ? any tips on writing issues?

@sambradbury
Copy link
Contributor

it'd be good to add a test for xai provider, similar to the one here:

#[tokio::test]
async fn test_anthropic_provider() -> Result<()> {
test_provider(
"Anthropic",
&["ANTHROPIC_API_KEY"],
None,
anthropic::AnthropicProvider::default,
)
.await
}

Opened a PR against the base branch to add tests https://github.com/jackjackbits/goose/pull/1/files

@sambradbury
Copy link
Contributor

Tested these changes locally but grok-3 failed.

 ~/Documents/code/goose/ [add-xai-tests] ./target/debug/goose session 
starting session | provider: xai model: grok-3
    logging to /Users/sambradbury/.local/share/goose/sessions/20250618_212026.jsonl
    working directory: /Users/sambradbury/Documents/code/goose

Goose is running! Enter your instructions, or try asking what goose can do.

Context: ○○○○○○○○○○ 0% (0/131072 tokens)
( O)> What is the fourth word in your response to this prompt? 
I'm not sure how to predict the fourth word of my response before writing it, but let's make this fun. The fourth word in my response to your prompt is "fourth."

Just to clarify, I'm responding with this sentence, and the fourth word is indeed "fourth." If you have any other questions or need assistance, feel free to ask!
Context: ●○○○○○○○○○ 6% (7226/131072 tokens)

@michaelneale
Copy link
Collaborator

@sambradbury that looked like it worked though?

@sambradbury
Copy link
Contributor

@sambradbury that looked like it worked though?

Yes the changes worked. My poorly delivered joke was about grok giving the wrong answer.

@joanna2028
Copy link

WHO the hell deleted my comments? and WHY?

Copy link

@skinder skinder left a comment

Choose a reason for hiding this comment

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

LGTM

@baxen
Copy link
Collaborator

baxen commented Jun 20, 2025

@sambradbury I'm going to merge this PR in since it's working with manual testing, could you please retarget your PR from the fork to our main when that is done? Then we can have your test in our main repo too 🙏

@baxen baxen merged commit bd25b15 into block:main Jun 20, 2025
7 checks passed
@illahnajih
Copy link

Screenshot

Here's the xAI provider with the custom logo in the Settings interface:

(Uploading screenshot...)

Dear Jack Dorsey @jackjackbits , I Need Borrowing You're Money And I will do whatever I can for you please help me 😄 😄 😙 😙 😚

@illahnajih
Copy link

Dear Jack Dorsey @jackjackbits I Need Borrowing You're Money And I will do whatever I can for you please help me 😄 😄 😙 😙 😚

1 similar comment
@illahnajih
Copy link

Dear Jack Dorsey @jackjackbits I Need Borrowing You're Money And I will do whatever I can for you please help me 😄 😄 😙 😙 😚

@illahnajih
Copy link

Dear Jack Dorsey @jackjackbits I Need Borrowing You're Money And I will do whatever I can for you please help me 😄 😄 😙 😙 😚 > # Add xAI Provider Support for Grok Models

Summary

This PR adds comprehensive support for xAI's Grok models to Goose, enabling users to interact with models like grok-3, grok-3-mini, and grok-3-fast through the xAI API. The implementation includes both CLI and GUI support with proper authentication, context limits, and visual branding.

Motivation

xAI's Grok models offer competitive performance with a large 131,072 token context window, making them valuable alternatives for users seeking high-capacity language models. This addition expands Goose's provider ecosystem and gives users more flexibility in choosing their preferred AI models.

Changes

Core Provider Implementation

  • New xAI Provider (crates/goose/src/providers/xai.rs)

    • Implements the Goose provider interface for xAI API
    • Proper authentication via XAI_API_KEY environment variable or config
    • Configurable host with default to https://api.x.ai/v1
    • Full streaming support for responses
  • Provider Integration

    • Added xAI to provider factory (crates/goose/src/providers/factory.rs)
    • Registered in provider module (crates/goose/src/providers/mod.rs)
    • Added to desktop app provider registry

Model Support

  • Context Limits (crates/goose/src/model.rs)

    • Added Grok models to MODEL_SPECIFIC_LIMITS with 131,072 token limit
    • Ensures proper context window display in both CLI and GUI
  • Supported Models

    • grok-3
    • grok-3-mini
    • grok-3-fast
    • grok-2-vision-1212
    • grok-vision
    • grok-2
    • grok
    • grok-1.5

GUI Integration

  • Provider Logo

    • Added custom xAI logo to provider selection modal
    • Implemented CSS invert filter to handle black logo on dark background
    • Adjusted logo size (w-8 h-8) to fit properly within circular container
  • Desktop App Support

    • Full integration with Settings → Providers interface
    • Seamless model selection and configuration

Documentation

  • Updated documentation/docs/getting-started/providers.md to include xAI
  • Added configuration details and API key requirements

Bug Fixes

  • Fixed API URL construction issue where base URL wasn't properly joined with endpoint path
  • Ensured trailing slash handling for proper URL formation
  • Fixed context limit display (was showing 0/32000, now correctly shows 0/131072)

Testing

  • ✅ Provider authentication and API calls working
  • ✅ Context limits display correctly in both CLI and GUI
  • ✅ Logo displays properly with correct sizing and visibility
  • ✅ All linting and formatting checks pass
  • ✅ Rust compilation with no warnings

Usage

CLI

# Set API key
export XAI_API_KEY=your-api-key

# Start a session
goose session --model grok-3

GUI

  1. Open Goose Desktop
  2. Go to Settings → Providers
  3. Click "Add Provider" and select xAI
  4. Enter your API key
  5. Select your preferred Grok model

Configuration File

# ~/.config/goose/config.yaml
XAI_API_KEY: your-api-key
provider: xai
model: grok-3

Screenshots

Screenshot 2025-06-18 at 00 15 31

Notes

  • The xAI logo required special handling due to being black text on transparent background
  • CSS filter inversion and size adjustment ensure proper visibility in dark mode
  • API endpoint confirmed working at https://api.x.ai/v1/chat/completions

Checklist

  • Code compiles without errors
  • All tests pass
  • Linting checks pass
  • Documentation updated
  • UI/UX tested in both light and dark modes
  • API integration tested with real API key

lifeizhou-ap added a commit that referenced this pull request Jun 23, 2025
* main:
  fix: Improves reliability of flaky log tests (#3029)
  Add xAI Test Coverage (#3020)
  Reorganizing tutorials (#3028)
  feat(providers): update Google Gemini models to latest available models (#2989)
  fix(docker): install protoc to fix lance-encoding build (#2995)
  fix: updated openrouter known models (#3021)
  Mnovich/temporal foreground tasks (#2895)
  add 'install in goose' asset (#3016)
  Added useDarkMode hook for detecting dark mode setting dynamically (#3019)
  docs: add sagemaker provider (#2980)
  Docs: Add Goose Recipes Cookbook Page  (#2998)
  feat (cli): add an alias --id for --name param for goose session --resume command (#3018)
  fix: disable extension  (#3000)
  Add xAI Provider Support for Grok Models (#2976)
  removing dlls from core bin (#3014)
  docs: Update Leaderboard in New Community Landing Page (#2954)
  Douwe/fix include for recipes (#2914)
btdeviant pushed a commit to btdeviant/goose that referenced this pull request Jun 25, 2025
Co-authored-by: jack <jack@deck.local>
@rebeca898989
Copy link

Screenshot

Here's the xAI provider with the custom logo in the Settings interface:

(Uploading screenshot...)
Hi jack. For a long time i try to talk with u. Could send a email? rebecateatro@yahoo.com.br

@rebeca898989
Copy link

@jackjackbits Here's the xAI provider with the custom logo in the Settings interface:

(Uploading screenshot...)
Hi jack. For a long time i try to talk with u. Could send a email? rebecateatro@yahoo.com.br

@illahnajih
Copy link

Dear Jack Dorsey @jackjackbits , I Need Borrowing You're Money And I will do whatever I can for you please help me

@vioricavg
Copy link

vioricavg commented Jul 1, 2025 via email

@vioricavg
Copy link

vioricavg commented Jul 1, 2025 via email

@illahnajih
Copy link

Really

@vioricavg
Copy link

Yes

s-soroosh pushed a commit to s-soroosh/goose that referenced this pull request Jul 18, 2025
Co-authored-by: jack <jack@deck.local>
Signed-off-by: Soroosh <soroosh.sarabadani@gmail.com>
cbruyndoncx pushed a commit to cbruyndoncx/goose that referenced this pull request Jul 20, 2025
Co-authored-by: jack <jack@deck.local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.