|
| 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 | +--- |
0 commit comments