---
title: XAI: Grok 4 API | Text Generation | ModelsLab
description: xAI's Grok 4 LLM excels in reasoning with native tool use, multimodal vision, 256K context window, trained on 200k GPU Colossus cluster for SOTA.
url: https://modelslab.com/models/x-ai/x-ai-grok-4.md
canonical: https://modelslab.com/models/x-ai/x-ai-grok-4.md
type: product
component: Playground/LLM/Index
generated_at: 2026-04-15T00:20:02.721594Z
---

xAI: Grok 4
---

 [LLMs.txt](https://modelslab.com/models/open_router/x-ai-grok-4/llms.txt) [.md](https://modelslab.com/models/x-ai/x-ai-grok-4.md)

x-ai-grok-4 x-ai Closed Source Model $9.000000 / call

xAI: Grok 4
---

Choose a prompt below to get started or type your own message

 Explain quantum computing in simple terms

 Write a Python function to sort a list

 Create a marketing email for a SaaS product

 Compare REST vs GraphQL APIs

Send

### xAI: Grok 4

x-ai x-ai-grok-4

Copy model ID

PricingInput $3.00 / 1M tokens

Output $15.00 / 1M tokens

API EndpointsOpenAI Compatible

`https://modelslab.com/api/v7/llm/chat/completions`Endpoint

Anthropic Compatible

`https://modelslab.com/api/v7/llm/v1/messages`Messages

`https://modelslab.com/api/v7/llm/v1/messages/count_tokens`Count Tokens

`https://modelslab.com/api/v7/llm/v1/models`Models

Use with Claude Code

cURL Example

ParametersSystem MessageYou are a helpful AI assistant specialized in providing accurate and detailed responses.

Temperature0.7

Max Tokens1000

Top P0.9

Frequency Penalty0

Presence Penalty0

Model Info

Support

Related Models
---

Discover similar models you might be interested in

 [View all LLM Models](https://modelslab.com/models?feature=llmaster)

[MM](https://modelslab.com/models/open_router/minimax-minimax-m2.1)[Open Router](https://modelslab.com/models/open_router)

 [MiniMax: MiniMax M2.1

Closed Source Model](https://modelslab.com/models/open_router/minimax-minimax-m2.1)

[Q3](https://modelslab.com/models/together_ai/Qwen-Qwen3.5-35B-A3B)[Together AI](https://modelslab.com/models/together_ai)

 [Qwen3.5 35B A3b

Closed Source Model](https://modelslab.com/models/together_ai/Qwen-Qwen3.5-35B-A3B)

[OG](https://modelslab.com/models/open_router/openai-gpt-5.4-nano)[Open Router](https://modelslab.com/models/open_router)

 [OpenAI: GPT-5.4 Nano

Closed Source Model](https://modelslab.com/models/open_router/openai-gpt-5.4-nano)

[GG](https://modelslab.com/models/open_router/google-gemini-2.5-pro)[Open Router](https://modelslab.com/models/open_router)

 [Google: Gemini 2.5 Pro

Closed Source Model](https://modelslab.com/models/open_router/google-gemini-2.5-pro)

[ZG](https://modelslab.com/models/open_router/z-ai-glm-5.1)[Open Router](https://modelslab.com/models/open_router)

 [Z.ai: GLM 5.1

Closed Source Model](https://modelslab.com/models/open_router/z-ai-glm-5.1)

[NN](https://modelslab.com/models/open_router/nvidia-nemotron-3-nano-30b-a3b)[Open Router](https://modelslab.com/models/open_router)

 [NVIDIA: Nemotron 3 Nano 30B A3B

Closed Source Model](https://modelslab.com/models/open_router/nvidia-nemotron-3-nano-30b-a3b)

[IG](https://modelslab.com/models/open_router/ibm-granite-granite-4.0-h-micro)[Open Router](https://modelslab.com/models/open_router)

 [IBM: Granite 4.0 Micro

Closed Source Model](https://modelslab.com/models/open_router/ibm-granite-granite-4.0-h-micro)

[MM](https://modelslab.com/models/open_router/minimax-minimax-m1)[Open Router](https://modelslab.com/models/open_router)

 [MiniMax: MiniMax M1

Closed Source Model](https://modelslab.com/models/open_router/minimax-minimax-m1)

[AA](https://modelslab.com/models/together_ai/arize-ai-qwen-2-1.5b-instruct)[Together AI](https://modelslab.com/models/together_ai)

 [Arize AI Qwen 2 1.5B Instruct

Closed Source Model](https://modelslab.com/models/together_ai/arize-ai-qwen-2-1.5b-instruct)

[DV](https://modelslab.com/models/together_ai/deepseek-ai-DeepSeek-V3.1)[Together AI](https://modelslab.com/models/together_ai)

 [Deepseek V3.1

Closed Source Model](https://modelslab.com/models/together_ai/deepseek-ai-DeepSeek-V3.1)

[OO](https://modelslab.com/models/open_router/openai-o1-pro)[Open Router](https://modelslab.com/models/open_router)

 [OpenAI: o1-pro

Closed Source Model](https://modelslab.com/models/open_router/openai-o1-pro)

[OG](https://modelslab.com/models/open_router/openai-gpt-oss-20b)[Open Router](https://modelslab.com/models/open_router)

 [OpenAI: gpt-oss-20b

Closed Source Model](https://modelslab.com/models/open_router/openai-gpt-oss-20b)

[GG](https://modelslab.com/models/open_router/google-gemma-4-31b-it)[Open Router](https://modelslab.com/models/open_router)

 [Google: Gemma 4 31B

Closed Source Model](https://modelslab.com/models/open_router/google-gemma-4-31b-it)

[OG](https://modelslab.com/models/open_router/openai-gpt-oss-20b-free)[Open Router](https://modelslab.com/models/open_router)

 [OpenAI: gpt-oss-20b (free)

Closed Source Model](https://modelslab.com/models/open_router/openai-gpt-oss-20b-free)

[ZG](https://modelslab.com/models/open_router/z-ai-glm-4.5)[Open Router](https://modelslab.com/models/open_router)

 [Z.ai: GLM 4.5

Closed Source Model](https://modelslab.com/models/open_router/z-ai-glm-4.5)

[OG](https://modelslab.com/models/open_router/openai-gpt-5)[Open Router](https://modelslab.com/models/open_router)

 [OpenAI: GPT-5

Closed Source Model](https://modelslab.com/models/open_router/openai-gpt-5)

[QQ](https://modelslab.com/models/qwen/Qwen-QwQ-32B)[ModelsLab](https://modelslab.com/models/qwen)

 [Qwen QwQ-32B

Closed Source Model](https://modelslab.com/models/qwen/Qwen-QwQ-32B)

[II](https://modelslab.com/models/open_router/inflection-inflection-3-pi)[Open Router](https://modelslab.com/models/open_router)

 [Inflection: Inflection 3 Pi

Closed Source Model](https://modelslab.com/models/open_router/inflection-inflection-3-pi)

About XAI: Grok 4
---

Grok 4 is xAI's latest reasoning model with a 256k context window. It supports parallel tool calling, structured outputs, and both image and text inputs. Note that reasoning is not...

### Technical Specifications

Model IDx-ai-grok-4CategoryLLM ModelsTaskText GenerationPrice$9.000000 per million tokensAddedFebruary 20, 2026

### Key Features

- Chat completion and multi-turn conversation API
- Streaming response with token-by-token output
- Function calling and tool use support
- System prompts and role-based messaging
- JSON mode and structured output

### Quick Start

Integrate XAI: Grok 4 into your application with a single API call. Get your API key from the [pricing page](https://modelslab.com/pricing) to get started.

PythonJavaScriptcURLPHP

```
<code>import requests
import json

url = "https://modelslab.com/api/v7/llm/chat/completions"

headers = {
    "Content-Type": "application/json"
}

data = {
        "model_id": "x-ai-grok-4",
        "messages": [
            {
                "role": "user",
                "content": "Hello!"
            }
        ],
        "max_tokens": 1000,
        "key": "YOUR_API_KEY"
    }

try:
    response = requests.post(url, headers=headers, json=data)
    response.raise_for_status()  # Raises an HTTPError for bad responses (4XX or 5XX)
    result = response.json()
    print("API Response:")
    print(json.dumps(result, indent=2))
except requests.exceptions.HTTPError as http_err:
    print(f"HTTP error occurred: {http_err} - {response.text}")
except Exception as err:
    print(f"Other error occurred: {err}")</code>
```

View the [full API documentation](https://modelslab.com/models/x-ai/x-ai-grok-4/api) for SDKs, code examples in Python, JavaScript, and more.

### Pricing

XAI: Grok 4 API costs $9.000000 per million tokens. Pay only for what you use with no minimum commitments. [View pricing plans](https://modelslab.com/pricing)

### Use Cases

- AI chatbots and virtual assistants
- Code generation and developer tools
- Content writing and copywriting automation
- Data analysis, summarization, and extraction

[Learn more about XAI: Grok 4](https://modelslab.com/xai-grok-4) [Browse LLM Models](https://modelslab.com/models?feature=llmaster) [More from X Ai](https://modelslab.com/models/open_router) [View Pricing](https://modelslab.com/pricing)

XAI: Grok 4 FAQ
---

### What is XAI: Grok 4?

Grok 4 is xAI's latest reasoning model with a 256k context window. It supports parallel tool calling, structured outputs, and both image and text inputs. Note that reasoning is not...

### How do I use the XAI: Grok 4 API?

You can integrate XAI: Grok 4 into your application with a single API call. Sign up on ModelsLab to get your API key, then use the model ID "x-ai-grok-4" in your API requests. We provide SDKs for Python, JavaScript, and cURL examples in the API documentation.

### How much does XAI: Grok 4 cost?

XAI: Grok 4 costs $9.000000 per million tokens. ModelsLab uses pay-per-use pricing with no minimum commitments. A free tier is available to get started.

### What is the XAI: Grok 4 model ID?

The model ID for XAI: Grok 4 is "x-ai-grok-4". Use this ID in your API requests to specify this model.

### Does XAI: Grok 4 have a free tier?

Yes, ModelsLab offers a free tier that lets you try XAI: Grok 4 and other AI models. Sign up to get free API credits and start building immediately.

---

*This markdown version is optimized for AI agents and LLMs.*

**Links:**
- [Website](https://modelslab.com)
- [API Documentation](https://docs.modelslab.com)
- [Blog](https://modelslab.com/blog)

---
*Generated by ModelsLab - 2026-04-15*