xAI

Grok 4

x-ai/grok-4
/v1/chat/completions/v1/messages/v1/responses/v1beta/models/*/v1/models/*

Grok 4是xAI的多模态大型语言模型,目前支持文本模态,视觉、图像生成等功能即将推出。

Input / output modalities
文本 to 文本
Reference input / output price
Input¥21Output¥105per 1M tokens
Context window
256K
Added to catalog
Jul 10, 2025

Providers and pricing

ProviderInput lengthInput /MOutput /MCached /MContextMax outputDetails
OpenRouter≤ 128K¥21¥105¥5.25256K256K
≥ 128K¥42¥210¥5.25

OpenRouter

Latency
55.52s
Throughput
59 tokens/s
Context
256K

Pricing

Input
¥21/M tokens
Output
¥105/M tokens
Cached
¥5.25/M tokens

Tiered pricing

Pricing varies by input token range.

0–128K Token

Input tier
¥21/M tokens
Output tier
¥105/M tokens
Cached tier
¥5.25/M tokens

128K–∞ Token

Input tier
¥42/M tokens
Output tier
¥210/M tokens
Cached tier
¥5.25/M tokens

Specifications

Context
256K
Max output
256K
Supported APIs
/v1/chat/completions/v1/messages/v1/responses/v1beta/models/*/v1/models/*

Grok 4 code examples and API guide

Modelmesh normalizes requests and responses across service providers behind one consistent API.

Modelmesh provides an OpenAI-compatible Completion API for more than 300 models and service providers. Call it directly, through the OpenAI SDK, or with supported third-party SDKs.

Modelmesh-specific request headers in these examples are optional. When supplied, your application can appear on the Modelmesh rankings.

Supported endpointsSelect an endpoint to switch the example below.
/v1/chat/completions
from openai import OpenAI API_KEY = "$SSY_API_KEY" client = OpenAI( base_url="https://router.shengsuanyun.com/api/v1", api_key=API_KEY, ) try: completion = client.chat.completions.create( model="x-ai/grok-4", messages=[{"role": "user", "content": "Which number is larger, 9.11 or 9.8?"}], temperature=0.6, top_p=0.7, stream=True, ) response_text = "" for chunk in completion: if chunk.choices and chunk.choices[0].delta.content is not None: content = chunk.choices[0].delta.content print(content, end="", flush=True) response_text += content except Exception as error: print(f"Request failed: {error}")
                
              

Related Models