xAI offers 58 models through Lava’s AI Gateway, supporting Chat Completions, Chat Completions (Native). Authentication uses Authorization: Bearer or x-api-key. See the xAI API docs for provider-specific parameters.
Supports both managed API keys (from Lava) and BYOK mode.
Quick Start
const response = await fetch('https://api.lavapayments.com/v1/forward?u=https%3A%2F%2Fapi.x.ai%2Fv1%2Fchat%2Fcompletions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${forwardToken}`,
},
body: JSON.stringify({
model: 'grok-4-1-fast-reasoning',
messages: [{ role: "user", content: "Hello!" }],
}),
});
Chat Completions
Target URL: https://api.x.ai/v1/chat/completions
| |
|---|
| Auth Header | Authorization: Bearer |
| Content Type | application/json |
| Streaming | Yes (set stream: true in request body) |
| Model | Input / 1M tokens | Output / 1M tokens |
|---|
| grok-3-fast-beta | $5.00 | $25.00 |
| grok-3-fast | $5.00 | $25.00 |
| grok-3-fast-latest | $5.00 | $25.00 |
| grok-4-0709 | $3.00 | $15.00 |
| grok-4-latest | $3.00 | $15.00 |
| grok-4 | $3.00 | $15.00 |
| grok-3-beta | $3.00 | $15.00 |
| grok-3 | $3.00 | $15.00 |
| grok-3-latest | $3.00 | $15.00 |
| grok-2-vision | $2.00 | $10.00 |
| grok-2-vision-latest | $2.00 | $10.00 |
| grok-2-vision-1212 | $2.00 | $10.00 |
| grok-3-mini-fast-beta | $0.60 | $4.00 |
| grok-3-mini-fast | $0.60 | $4.00 |
| grok-3-mini-fast-latest | $0.60 | $4.00 |
| grok-3-mini-beta | $0.30 | $0.50 |
| grok-3-mini | $0.30 | $0.50 |
| grok-3-mini-latest | $0.30 | $0.50 |
| grok-4-1-fast-reasoning | $0.20 | $0.50 |
| grok-4-1-fast-reasoning-latest | $0.20 | $0.50 |
| grok-4-1-fast-non-reasoning | $0.20 | $0.50 |
| grok-4-1-fast-non-reasoning-latest | $0.20 | $0.50 |
| grok-code-fast-1 | $0.20 | $1.50 |
| grok-4-fast-non-reasoning | $0.20 | $0.50 |
| grok-4-fast-non-reasoning-latest | $0.20 | $0.50 |
| grok-4-fast-reasoning | $0.20 | $0.50 |
| grok-4-fast-reasoning-latest | $0.20 | $0.50 |
| grok-code-fast | $0.20 | $1.50 |
| grok-code-fast-1-0825 | $0.20 | $1.50 |
Chat Completions (Native)
Target URL: https://api.x.ai/v1/messages
| |
|---|
| Auth Header | x-api-key |
| Content Type | application/json |
| Streaming | Yes (set stream: true in request body) |
| Model | Input / 1M tokens | Output / 1M tokens |
|---|
| grok-3-fast-beta | $5.00 | $25.00 |
| grok-3-fast | $5.00 | $25.00 |
| grok-3-fast-latest | $5.00 | $25.00 |
| grok-4-0709 | $3.00 | $15.00 |
| grok-4-latest | $3.00 | $15.00 |
| grok-4 | $3.00 | $15.00 |
| grok-3-beta | $3.00 | $15.00 |
| grok-3 | $3.00 | $15.00 |
| grok-3-latest | $3.00 | $15.00 |
| grok-2-vision | $2.00 | $10.00 |
| grok-2-vision-latest | $2.00 | $10.00 |
| grok-2-vision-1212 | $2.00 | $10.00 |
| grok-3-mini-fast-beta | $0.60 | $4.00 |
| grok-3-mini-fast | $0.60 | $4.00 |
| grok-3-mini-fast-latest | $0.60 | $4.00 |
| grok-3-mini-beta | $0.30 | $0.50 |
| grok-3-mini | $0.30 | $0.50 |
| grok-3-mini-latest | $0.30 | $0.50 |
| grok-4-1-fast-reasoning | $0.20 | $0.50 |
| grok-4-1-fast-reasoning-latest | $0.20 | $0.50 |
| grok-4-1-fast-non-reasoning | $0.20 | $0.50 |
| grok-4-1-fast-non-reasoning-latest | $0.20 | $0.50 |
| grok-code-fast-1 | $0.20 | $1.50 |
| grok-4-fast-non-reasoning | $0.20 | $0.50 |
| grok-4-fast-non-reasoning-latest | $0.20 | $0.50 |
| grok-4-fast-reasoning | $0.20 | $0.50 |
| grok-4-fast-reasoning-latest | $0.20 | $0.50 |
| grok-code-fast | $0.20 | $1.50 |
| grok-code-fast-1-0825 | $0.20 | $1.50 |
Next Steps