Skip to content

Commit 77ad852

Browse files
authored
feat: added xai provider in ui and docs (#1236)
## Add xAI Provider Support Added support for the xAI provider, which powers the Grok family of models. This integration enables users to access Grok models through Bifrost with full OpenAI compatibility. ## Changes - Added xAI provider documentation with detailed operation support - Updated provider overview table to include xAI capabilities - Added xAI to the model provider enum in OpenAPI schema - Added UI support with model placeholders and provider icon - Added xAI to known providers list for logging ## Type of change - [x] Feature - [x] Documentation ## Affected areas - [x] Providers/Integrations - [x] UI (Next.js) - [x] Docs ## How to test 1. Configure an xAI API key in your environment 2. Make requests to supported endpoints with xAI models: ```sh # Chat completion example curl -X POST http://localhost:8000/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{ "model": "xai/grok-3-mini", "messages": [{"role": "user", "content": "Hello, how are you?"}] }' # Test vision capabilities with Grok vision models curl -X POST http://localhost:8000/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{ "model": "xai/grok-2-vision-1212", "messages": [{ "role": "user", "content": [ {"type": "text", "text": "What is in this image?"}, {"type": "image_url", "image_url": {"url": "https://example.com/image.jpg"}} ] }] }' ``` ## Breaking changes - [x] No ## Related issues Implements provider support requested in issue tracker ## Checklist - [x] I added/updated tests where appropriate - [x] I updated documentation where needed - [x] I verified builds succeed (Go and UI)
2 parents 2c0cbf1 + af35195 commit 77ad852

File tree

8 files changed

+169
-3
lines changed

8 files changed

+169
-3
lines changed

docs/docs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@
107107
"providers/supported-providers/parasail",
108108
"providers/supported-providers/perplexity",
109109
"providers/supported-providers/sgl",
110-
"providers/supported-providers/vertex"
110+
"providers/supported-providers/vertex",
111+
"providers/supported-providers/xai"
111112
]
112113
},
113114
"providers/reasoning",

docs/openapi/schemas/inference/common.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ ModelProvider:
2222
- elevenlabs
2323
- huggingface
2424
- nebius
25+
- xai
2526

2627
Fallback:
2728
type: object

docs/providers/supported-providers/overview.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ The following table summarizes which operations are supported by each provider v
3535
| Perplexity (`perplexity/<model>`) ||||||||||||||||
3636
| SGL (`sgl/<model>`) ||||||||||||||||
3737
| Vertex AI (`vertex/<model>`) ||||||||||||||||
38+
| xAI (`xai/<model>`) ||||||||||||||||
3839

3940

4041
- 🟡 Not supported by the downstream provider, but internally implemented by Bifrost as a fallback.
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
---
2+
title: "xAI"
3+
description: "xAI API conversion guide - OpenAI-compatible format, Grok models, vision support, reasoning, and parameter handling"
4+
icon: "x"
5+
---
6+
7+
## Overview
8+
9+
xAI is an **OpenAI-compatible provider** powering the Grok family of models. Bifrost delegates to the OpenAI implementation with standard parameter filtering. Key features:
10+
- **Full OpenAI compatibility** - Chat, text completion, and responses
11+
- **Vision support** - Image URLs and base64 encoding for multimodal models
12+
- **Streaming support** - Server-Sent Events with delta-based updates
13+
- **Reasoning support** - Extended thinking for Grok reasoning models
14+
- **Tool calling** - Complete function definition and execution
15+
- **Parameter filtering** - Removes unsupported OpenAI-specific fields
16+
17+
### Supported Operations
18+
19+
| Operation | Non-Streaming | Streaming | Endpoint |
20+
|-----------|---------------|-----------|----------|
21+
| Chat Completions ||| `/v1/chat/completions` |
22+
| Responses API ||| `/v1/responses` |
23+
| Text Completions ||| `/v1/completions` |
24+
| List Models || - | `/v1/models` |
25+
| Embeddings ||| - |
26+
| Speech (TTS) ||| - |
27+
| Transcriptions (STT) ||| - |
28+
| Files ||| - |
29+
| Batch ||| - |
30+
31+
<Note>
32+
**Unsupported Operations** (❌): Embeddings, Speech, Transcriptions, Files, and Batch are not supported by the upstream xAI API. These return `UnsupportedOperationError`.
33+
</Note>
34+
35+
---
36+
37+
# 1. Chat Completions
38+
39+
## Request Parameters
40+
41+
xAI supports all standard OpenAI chat completion parameters. For full parameter reference and behavior, see [OpenAI Chat Completions](/providers/supported-providers/openai#1-chat-completions).
42+
43+
### Filtered Parameters
44+
45+
Removed for xAI compatibility:
46+
- `prompt_cache_key` - Not supported
47+
- `verbosity` - Anthropic-specific
48+
- `store` - Not supported
49+
- `service_tier` - Not supported
50+
51+
### Reasoning Support
52+
53+
xAI's `grok-3-mini` model supports extended reasoning via the standard `reasoning_effort` field:
54+
55+
```json
56+
{
57+
"model": "xai/grok-3-mini",
58+
"messages": [...],
59+
"reasoning_effort": "high"
60+
}
61+
```
62+
63+
<Warning>
64+
**Model-Specific Feature**: The `reasoning_effort` parameter is only supported by `grok-3-mini`. Other Grok-3 and Grok-4 models will return an error if this parameter is specified.
65+
</Warning>
66+
67+
Bifrost converts from the internal `Reasoning` structure to xAI's `reasoning_effort` string format.
68+
69+
### Vision Support
70+
71+
xAI vision models support both image URLs and base64-encoded images:
72+
73+
```json
74+
{
75+
"model": "xai/grok-2-vision-1212",
76+
"messages": [{
77+
"role": "user",
78+
"content": [
79+
{"type": "text", "text": "What is in this image?"},
80+
{"type": "image_url", "image_url": {"url": "https://..."}}
81+
]
82+
}]
83+
}
84+
```
85+
86+
**Supported Image Formats:**
87+
- ✅ Image URLs
88+
- ✅ Base64-encoded images
89+
- ✅ Multiple images per message
90+
91+
xAI supports all standard OpenAI message types, tools, responses, and streaming formats. For details on message handling, tool conversion, responses, and streaming, refer to [OpenAI Chat Completions](/providers/supported-providers/openai#1-chat-completions).
92+
93+
---
94+
95+
# 2. Responses API
96+
97+
xAI's Responses API is forwarded directly to `/v1/responses`:
98+
99+
```
100+
ResponsesRequest → /v1/responses → ResponsesResponse
101+
```
102+
103+
Same parameter support and message handling as Chat Completions. Full streaming support available.
104+
105+
---
106+
107+
# 3. Text Completions
108+
109+
xAI supports legacy text completion format:
110+
111+
| Parameter | Mapping |
112+
|-----------|---------|
113+
| `prompt` | Direct pass-through |
114+
| `max_tokens` | max_tokens |
115+
| `temperature`, `top_p` | Direct pass-through |
116+
| `stop` | Stop sequences |
117+
| `frequency_penalty`, `presence_penalty` | Penalty parameters |
118+
119+
Streaming support available via `stream: true`.
120+
121+
---
122+
123+
# 4. List Models
124+
125+
Lists available xAI models with their capabilities and context lengths.
126+
127+
---
128+
129+
## Unsupported Features
130+
131+
| Feature | Reason |
132+
|---------|--------|
133+
| Embedding | Not offered by xAI API |
134+
| Speech/TTS | Not offered by xAI API |
135+
| Transcription/STT | Not offered by xAI API |
136+
| Batch Operations | Not offered by xAI API |
137+
| File Management | Not offered by xAI API |
138+
139+
---

transports/changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
- fix: added missing logs filter checks in ui for live updates
2-
- fix: ensure request ID is consistently set in context before PreHooks are executed
2+
- fix: ensure request ID is consistently set in context before PreHooks are executed
3+
- docs: updated docs for xai provider

ui/lib/constants/config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ export const ModelPlaceholders = {
4747
ollama: "e.g. llama3.1, llama2",
4848
openai: "e.g. gpt-4, gpt-4o, gpt-4o-mini, gpt-3.5-turbo",
4949
vertex: "e.g. gemini-1.5-pro, text-bison, chat-bison",
50-
nebius: "e.g. openai/gpt-oss-120b, google/gemma-2-9b-it-fast, Qwen/Qwen2.5-VL-72B-Instruct"
50+
nebius: "e.g. openai/gpt-oss-120b, google/gemma-2-9b-it-fast, Qwen/Qwen2.5-VL-72B-Instruct",
51+
xai: "e.g. grok-4-0709, grok-3-mini, grok-3, grok-2-vision-1212",
5152
};
5253

5354
export const isKeyRequiredByProvider: Record<ProviderName, boolean> = {
@@ -69,6 +70,7 @@ export const isKeyRequiredByProvider: Record<ProviderName, boolean> = {
6970
vertex: true,
7071
perplexity: true,
7172
nebius: true,
73+
xai: true,
7274
};
7375

7476
export const DefaultNetworkConfig = {

ui/lib/constants/icons.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,25 @@ export const ProviderIcons = {
605605
nebius: ({ size = "md", className = "" }: IconProps) => {
606606
return <img src="/images/nebius.jpeg" alt="Nebius" className={className} />;
607607
},
608+
xai: ({ size = "md", className = "" }: IconProps) => {
609+
const resolvedSize = resolveSize(size);
610+
611+
return (
612+
<svg
613+
fill="currentColor"
614+
fillRule="evenodd"
615+
height={resolvedSize}
616+
style={{ flex: "none", lineHeight: "1" }}
617+
viewBox="0 0 24 24"
618+
width={resolvedSize}
619+
xmlns="http://www.w3.org/2000/svg"
620+
className={className}
621+
>
622+
<title>Grok</title>
623+
<path d="M6.469 8.776L16.512 23h-4.464L2.005 8.776H6.47zm-.004 7.9l2.233 3.164L6.467 23H2l4.465-6.324zM22 2.582V23h-3.659V7.764L22 2.582zM22 1l-9.952 14.095-2.233-3.163L17.533 1H22z"></path>
624+
</svg>
625+
);
626+
},
608627
} as const;
609628

610629
// Helper component to render provider icons

ui/lib/constants/logs.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const KnownProvidersNames = [
1818
"sgl",
1919
"vertex",
2020
"nebius",
21+
"xai",
2122
] as const;
2223

2324
// Local Provider type derived from KNOWN_PROVIDERS constant
@@ -61,6 +62,7 @@ export const ProviderLabels: Record<ProviderName, string> = {
6162
openrouter: "OpenRouter",
6263
huggingface: "HuggingFace",
6364
nebius: "Nebius Token Factory",
65+
xai: "xAI",
6466
} as const;
6567

6668
// Helper function to get provider label, supporting custom providers

0 commit comments

Comments
 (0)