Skip to content

Commit 30dbcba

Browse files
author
jack
committed
Fix xAI API endpoint URL
- 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
1 parent ff54e6d commit 30dbcba

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# ["xai", "grok", "provider", "implementation", "complete"]
2+
Successfully added xAI provider support for Grok models to Goose:
3+
4+
**What was implemented:**
5+
1. Created new XaiProvider in `crates/goose/src/providers/xai.rs`
6+
2. Added support for all Grok models: grok-3, grok-3-fast, grok-3-mini, grok-3-mini-fast, grok-2-vision-1212, grok-2-image-1212, etc.
7+
3. Uses x.ai's OpenAI-compatible API at https://api.x.ai/v1/chat/completions
8+
4. Requires XAI_API_KEY environment variable
9+
5. Optional XAI_HOST configuration (defaults to https://api.x.ai)
10+
6. Updated provider factory and registry to include xAI
11+
7. Added xAI to GUI provider registry in ProviderRegistry.tsx
12+
8. Includes proper error handling for auth, rate limits, server errors
13+
14+
**How to use:**
15+
- CLI: Set XAI_API_KEY env var, then use `--provider xai --model grok-3`
16+
- GUI: Configure xAI provider in Settings with API key
17+
18+
**Key files modified:**
19+
- crates/goose/src/providers/xai.rs (new)
20+
- crates/goose/src/providers/mod.rs (added xai module)
21+
- crates/goose/src/providers/factory.rs (added XaiProvider to registry)
22+
- ui/desktop/src/components/settings/providers/ProviderRegistry.tsx (added xAI UI config)
23+
24+
**Branch:** feature/add-grok-models
25+
**Commit:** ff54e6d576
26+

crates/goose/src/providers/xai.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use serde_json::Value;
1212
use std::time::Duration;
1313
use url::Url;
1414

15-
pub const XAI_API_HOST: &str = "https://api.x.ai";
15+
pub const XAI_API_HOST: &str = "https://api.x.ai/v1";
1616
pub const XAI_DEFAULT_MODEL: &str = "grok-3";
1717
pub const XAI_KNOWN_MODELS: &[&str] = &[
1818
"grok-3",
@@ -75,7 +75,7 @@ impl XaiProvider {
7575
async fn post(&self, payload: Value) -> anyhow::Result<Value, ProviderError> {
7676
let base_url = Url::parse(&self.host)
7777
.map_err(|e| ProviderError::RequestFailed(format!("Invalid base URL: {e}")))?;
78-
let url = base_url.join("v1/chat/completions").map_err(|e| {
78+
let url = base_url.join("chat/completions").map_err(|e| {
7979
ProviderError::RequestFailed(format!("Failed to construct endpoint URL: {e}"))
8080
})?;
8181

ui/desktop/src/components/settings/providers/ProviderRegistry.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export const PROVIDER_REGISTRY: ProviderRegistry[] = [
111111
{
112112
name: 'XAI_HOST',
113113
is_secret: false,
114-
default: 'https://api.x.ai',
114+
default: 'https://api.x.ai/v1',
115115
},
116116
],
117117
},

0 commit comments

Comments
 (0)