Skip to content

Grok 4

xai/grok-4 — a llm model by xAI. Call it through the gateway’s standard OpenAI-compatible door using the catalog slug; the full parameter schema is reproduced in full below.

Catalog slugxai/grok-4
Kindllm
VendorxAI

Through the Sociaro SDK / OpenAI-compatible door

Section titled “Through the Sociaro SDK / OpenAI-compatible door”
from sociaro_ai import Sociaro
client = Sociaro(api_key="gw_live_...") # base_url defaults to https://api.sociaro.com
resp = client.chat.completions.create(
model="xai/grok-4", # always the catalog slug
messages=[{"role": "user", "content": "Hello"}],
# any parameter from the schema below is passed through unchanged
)
print(resp.choices[0].message.content)

TypeScript: client.chat.completions.create({ model: "xai/grok-4", messages: [...] }) — see the TypeScript SDK.

The complete, one-to-one API schema for this model, transcribed from the official source. Nothing omitted. Examples in the schema may use a representative model of the family — for this model use the slug xai/grok-4 as shown in How to call above.

Grok is reached through the gateway’s standard OpenAI-compatible chat door only: POST https://api.sociaro.com/v1/chat/completions, addressing the model by its catalog slug in the model field. There is no /xai gateway prefix and no separate Responses endpoint exposed to clients.

Gateway slugUpstreammodel valueCapabilities
xai/grok-4xAIxai/grok-4text, vision (image understanding), tools/function-calling, reasoning (always-on, not configurable), Live Search
xai/grok-code-fast-1xAIxai/grok-code-fast-1text, tools, reasoning, agentic coding (no vision)

Auth (all): Authorization: Bearer $SOCIARO_API_KEY header.


xAI reasoning models (both grok-4 and grok-code-fast-1 are reasoning models):

  • reasoning is always on and cannot be turned off for grok-4 and grok-code-fast-1. reasoning_effort is Only supported by grok-4.3 per the xAI source — for grok-4 / grok-code-fast-1 it is not a tuning knob. Possible values when it does apply: none (disables reasoning completely), low (default), medium, high.
  • Fields the xAI source marks “Not supported by reasoning models” → ignored/discarded for grok-4 and grok-code-fast-1: frequency_penalty, presence_penalty (also explicitly “Not supported by grok-3”), stop.
  • logit_bias is marked (Unsupported) at xAI globally.
  • logprobs / top_logprobs: “Not supported by models grok-4.20 and newer; silently ignored”. For grok-4 / grok-code-fast-1 they may work partially — verify on a live response.
  • Vision: grok-4 accepts image input (content as array with image_url); grok-code-fast-1 is text-only.
  • reasoning_content is returned in the assistant message for reasoning models (the reasoning trace).

1. Chat Completions — POST https://api.sociaro.com/v1/chat/completions (grok-4, grok-code-fast-1)

Section titled “1. Chat Completions — POST https://api.sociaro.com/v1/chat/completions (grok-4, grok-code-fast-1)”

The OpenAI-compatible chat door. This is the only contract for reaching Grok through the gateway: send to POST https://api.sociaro.com/v1/chat/completions with Authorization: Bearer $SOCIARO_API_KEY and set model to the catalog slug (xai/grok-4 or xai/grok-code-fast-1).

{
"model": "xai/grok-4",
"messages": [ { "role": "system|user|assistant|tool", "content": "..." } ],
"...optional params..."
}

Full request parameter table (Chat Completions)

Section titled “Full request parameter table (Chat Completions)”

Parameters are listed in the order/spelling of the OpenAI-compatible chat schema.

ParameterTypeRequiredDefaultAllowed values / rangeDescription
frequency_penaltynumber | nullno0−2.0 … 2.0(Not supported by reasoning models) Positive values penalize tokens by existing frequency, reducing verbatim repetition.
logit_biasobject | nullnonullmap tokenID→bias (−100 … 100)(Unsupported at xAI) Bias added to logits before sampling; ±1 nudges, ±100 bans/forces a token.
logprobsboolean | nullnofalsetrue / falseReturn log-probabilities of output tokens. Not supported by grok-4.20 and newer (silently ignored).
max_completion_tokensinteger | nullnonull (generate up to context length)>0Upper bound on visible output tokens only (excludes reasoning / function-call tokens).
max_tokensinteger | nullnonull>0[DEPRECATED] Max tokens in the chat completion. Deprecated in favor of max_completion_tokens.
messagesarrayyesroles: system / user / assistant / tool; content = string or array of parts (text, image_url)List of messages making up the conversation. Different models support different message types (e.g. text, image).
modelstringyescatalog slug: xai/grok-4 or xai/grok-code-fast-1Catalog slug of the model to use.
ninteger | nullno1≥1How many completion choices to generate. Billed by total tokens across all choices; keep 1 to minimize cost.
parallel_tool_callsboolean | nullnotruetrue / falseIf false, the model performs at most one tool call.
presence_penaltynumber | nullno0−2.0 … 2.0(Not supported by grok-3 and reasoning models) Positive values penalize tokens already present, encouraging new topics.
prompt_cache_keystring | nullnonullstringStable cache key for best-effort sticky routing / prompt-cache hits across requests sharing a prompt prefix.
reasoning_effortstring | nullnolownone | low | medium | highHow hard a reasoning model thinks. Only supported by grok-4.3. none disables reasoning; low is the default; high uses the most reasoning tokens.
response_formatobjectno{"type":"text"}{"type":"text"} | {"type":"json_object"} | {"type":"json_schema","json_schema":{...}}Output format (text / JSON mode / Structured Outputs by schema).
search_parametersobjectnosee sub-fieldsLive Search parameters (realtime web/X search).
search_parameters.from_datestring | nullnonullISO-8601 YYYY-MM-DDDate from which to consider results.
search_parameters.max_search_resultsinteger | nullnonull>0Maximum number of search results to use.
search_parameters.modestring | nullnoonoff | on | autoRealtime-data mode: off = no search; on (default) = search all sources; auto = model decides whether/where to search.
search_parameters.return_citationsboolean | nullnotrue / falseWhether to return citations in the response.
search_parameters.sourcesarray | nullnoweb + Xlist of sourcesSources to search. If unspecified, the model searches web and X by default.
search_parameters.to_datestring | nullnonullISO-8601 YYYY-MM-DDDate up to which to consider results.
seedinteger | nullnonullintegerBest-effort deterministic sampling for identical seed+params. Determinism not guaranteed (monitor system_fingerprint).
service_tierstringnodefaultdefault | priorityProcessing tier; determines scheduling priority and billing.
stoparray | nullnonullup to 4 stop sequences(Not supported by reasoning models) Sequences where generation stops; stop text is not included in output.
streamboolean | nullnofalsetrue / falseStream partial deltas as SSE; terminated by data: [DONE].
stream_optionsobjectnosee sub-fieldStreaming options (only when stream: true).
stream_options.include_usagebooleanrequired (within the object)true / falseEmit an extra chunk with usage before data: [DONE]; other chunks return null in usage.
temperaturenumber | nullno10 … 2Sampling temperature; higher = more random, lower = more deterministic.
tool_choicestring | objectnoauto if tools present, else nonenone | auto | required | {"type":"function","function":{"name":"..."}}Controls tool selection by the model.
toolsarray | nullnonullJSON-schema; max 128 functionsTools the model may call. Currently only functions are supported.
top_logprobsinteger | nullnonull0 … 8Number of most-likely tokens to return per position (each with logprob). Requires logprobs: true. Not supported by grok-4.20+ (silently ignored).
top_pnumber | nullno10 … 1Nucleus sampling. Recommended to alter this or temperature, not both.
userstring | nullnonullstringUnique identifier for your end-user; helps xAI monitor and detect abuse.
web_search_optionsobjectnosee sub-fieldsOpenAI-compatibility web-search wrapper.
web_search_options.filtersobjectnoOnly included for compatibility.
web_search_options.search_context_sizestring | nullnostringIncluded for OpenAI-API compatibility; mapped to max_search.
web_search_options.user_locationobjectnoOnly included for compatibility.
content structure (vision — grok-4 only)
Section titled “content structure (vision — grok-4 only)”

Text prompt: "content": "text". Vision: content = array of parts:

"content": [
{ "type": "image_url", "image_url": { "url": "data:image/jpeg;base64,<...>", "detail": "high" } },
{ "type": "text", "text": "What is in this image?" }
]
  • image_url.detail: auto (default) | low | high.
    • auto: system picks resolution (default, balances speed/detail).
    • low: low-res, faster, fewer tokens, may miss fine detail.
    • high: high-res, slower, more tokens, attends to nuance.
  • image_url.url: data-URI or a public Internet URL.
  • Image input limits: max size 20 MiB; supported types jpg/jpeg, png; no limit on number of images; any text/image input order is accepted.
  • Conversations are stateless — prior turns must be replayed in messages to provide context.
{
"id": "...", "object": "chat.completion", "created": 0, "model": "...",
"choices": [ { "index": 0, "message": {...}, "logprobs": {...}, "finish_reason": "stop" } ],
"citations": [...],
"output_files": [...],
"service_tier": "default",
"system_fingerprint": "fp_...",
"usage": {...}
}
Response fieldTypeRequiredDescription
idstringyesUnique ID for the chat response.
objectstringyesAlways "chat.completion".
createdintegeryesCreation time (Unix timestamp).
modelstringyesModel ID used.
choices[]arrayyesResponse choices; length matches n (default 1).
choices[].indexintegeryesChoice index, starting at 0.
choices[].finish_reasonstring | nullstop (stop sequence reached), length (max token length / max_tokens reached), end_turn or null (in streaming when chunk is not the last).
choices[].logprobsobjectLog-probabilities object.
choices[].logprobs.contentarray | nullArray of log-probabilities of each output token returned.
choices[].message.rolestringyesAlways "assistant".
choices[].message.contentstring | nullThe text content of the message.
choices[].message.reasoning_contentstring | nullReasoning trace generated by the model (reasoning models).
choices[].message.refusalstring | nullReason if the model cannot generate; null when it can.
choices[].message.tool_callsarray | nullTool calls requested by the model for the user to perform.
citationsarray | nullAll external pages used by the model to answer (Live Search).
output_filesarray | nullFiles generated during the response (e.g. by the code-execution tool). Only populated when code_execution_files_output is included.
service_tier”default” | “priority”yesProcessing tier; determines scheduling priority and billing.
system_fingerprintstring | nullSystem fingerprint indicating xAI system config changes.
usage.prompt_tokensintegeryesTotal prompt tokens used.
usage.completion_tokensintegeryesTotal completion tokens used.
usage.total_tokensintegeryesSum of prompt + completion tokens.
usage.num_sources_usedintegeryesNumber of individual live-search sources used.
usage.prompt_tokens_detailsobjectyesPrompt-usage breakdown.
usage.prompt_tokens_details.text_tokensintegeryesTotal text prompt tokens (cached + non-cached).
usage.prompt_tokens_details.audio_tokensintegeryesAudio prompt tokens used.
usage.prompt_tokens_details.image_tokensintegeryesImage prompt tokens used.
usage.prompt_tokens_details.cached_tokensintegeryesTokens served from xAI cache (reused from prior requests).
usage.completion_tokens_detailsobjectyesCompletion-usage breakdown.
usage.completion_tokens_details.reasoning_tokensintegeryesTokens generated for reasoning.
usage.completion_tokens_details.audio_tokensintegeryesAudio output tokens generated by the model.
usage.completion_tokens_details.accepted_prediction_tokensintegeryesPredicted tokens that appeared in the completion.
usage.completion_tokens_details.rejected_prediction_tokensintegeryesPredicted tokens that did not appear in the completion.
usage.cost_in_usd_ticksintegeryesAccurate cost in USD ticks. TICKS_IN_USD_CENT = 100_000_000; i.e. 10,000,000,000 ticks = 1 dollar.
POST https://api.sociaro.com/v1/chat/completions
Authorization: Bearer $SOCIARO_API_KEY
Content-Type: application/json
{
"model": "xai/grok-4",
"messages": [
{ "role": "user", "content": "What is 101*3?" }
]
}

Full example (Live Search + tools + streaming + vision)

Section titled “Full example (Live Search + tools + streaming + vision)”
POST https://api.sociaro.com/v1/chat/completions
Authorization: Bearer $SOCIARO_API_KEY
{
"model": "xai/grok-4",
"messages": [
{ "role": "system", "content": "You are a helpful assistant." },
{ "role": "user", "content": [
{ "type": "image_url", "image_url": { "url": "https://example.com/x.png", "detail": "high" } },
{ "type": "text", "text": "Summarize today's AI news and describe this image." }
] }
],
"temperature": 0.7,
"top_p": 0.95,
"max_completion_tokens": 1024,
"n": 1,
"seed": 42,
"stream": true,
"stream_options": { "include_usage": true },
"response_format": { "type": "text" },
"tools": [
{ "type": "function", "function": { "name": "get_weather",
"parameters": { "type": "object", "properties": { "city": { "type": "string" } }, "required": ["city"] } } }
],
"tool_choice": "auto",
"parallel_tool_calls": true,
"search_parameters": {
"mode": "auto",
"return_citations": true,
"max_search_results": 10,
"from_date": "2026-06-01",
"to_date": "2026-06-17",
"sources": ["web", "x"]
},
"prompt_cache_key": "conv-abc-123",
"service_tier": "default",
"user": "user-1234"
}
{
"id": "a3d1008e-4544-40d4-d075-11527e794e4a",
"object": "chat.completion",
"created": 1752854522,
"model": "xai/grok-4",
"choices": [
{ "index": 0,
"message": { "role": "assistant", "content": "101 multiplied by 3 is 303.", "refusal": null },
"finish_reason": "stop" }
],
"usage": {
"prompt_tokens": 32, "completion_tokens": 9, "total_tokens": 135,
"prompt_tokens_details": { "text_tokens": 32, "audio_tokens": 0, "image_tokens": 0, "cached_tokens": 6 },
"completion_tokens_details": { "reasoning_tokens": 94, "audio_tokens": 0, "accepted_prediction_tokens": 0, "rejected_prediction_tokens": 0 },
"num_sources_used": 0
},
"system_fingerprint": "fp_3a7881249c"
}