Skip to content

Coverage

  • Create Response(Responses API)

  • Chat Completions

  • Prompt Cache Session Affinity (x-grok-conv-id, Chat Only)

  • Inference Parameters (reasoning/ reasoning_effort)

A. Responses / Create Response

Request Protocol

HTTPS

Parameter Name Type Required Description
Content-Type string Yes application/json
Authorization string Yes Bearer ${your_AK}

Request URL

Endpoint Interface Mode

POST https://genaiapi.cloudsway.net/v1/ai/{endpointPath}/responses

Converged Interface Mode

POST https://genaiapi.cloudsway.net/v1/responses

Request Body Parameters

Parameter Name Secondary Parameters Three-level parameters Type Required Description
input - - string | array Yes Input content;
model - - string Yes Model Name;
instructions - - string | null No System prompt; do not use together with previous_response_id
previous_response_id - - string | null No Continue writing the response from the previous round
max_output_tokens - - int | null No Token upper limit including output and inference
stream - - bool | null No SSE Streaming Output
temperature - - number | null No Sampling temperature, range 0–2; the original device may malfunction when set to 2
top_p - - number | null No Nuclear Sampling
reasoning - - object No Recommended writing style, including elements such as effort and summary
effort - string | null No low / medium / high / xhigh (varies by model)
summary - string | null No auto/ concise/ detailed (compatible field)
generate_summary - string | null No Compatibility field, recommended to use summary
include - - array | null No Additional output, e. g. reasoning. encrypted_content
prompt_cache_key - - string | null No Cache Routing Key
tools - - array | null No such as function, web search, etc. ;functionis transparently transmitted, web_search*will be stripped by the platform
type - string No Tool type, e. g. function
name - string No Function Name (function tool)
description - string No Function Description Glossary:
parameters - object No JSON Schema Parameter Definition
tool_choice - - string | object No Tool Selection Strategy
parallel_tool_calls - - bool | null No Whether to enable parallel tool calls
text - - object No Output Format Configuration
format - object No Output Format
type string No e.g. text / json_schema
schema object No JSON Schema (when type=json_schema)
user - - string | null No End User Identifier
top_logprobs - - int | null No 0–8; grok-4.20+ may be ignored

Request Example

Non-streaming (Endpoint interface mode)

curl -X POST "https://genaiapi.cloudsway.net/v1/ai/{endpointPath}/responses" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${your_AK}" \
  -d '{
    "model": "MaaS_Gr_4.6_20260812",
    "input": "Explain prompt caching in one paragraph.",
    "instructions": "You are Grok, a helpful AI assistant.",
    "max_output_tokens": 1024,
    "reasoning": {
      "effort": "medium",
      "summary": "detailed"
    },
    "store": true
  }'

Non-streaming (Integrated Interface Mode)

curl -X POST "https://genaiapi.cloudsway.net/v1/responses" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${your_AK}" \
  -d '{
    "model": "MaaS_Gr_4.6_20260812",
    "input": "Explain prompt caching in one paragraph.",
    "reasoning": { "effort": "high" }
  }'

streaming

curl -N -X POST "https://genaiapi.cloudsway.net/v1/ai/{endpointPath}/responses" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${your_AK}" \
  -d '{
    "model": "MaaS_Gr_4.6_20260812",
    "input": "Write a haiku about caching.",
    "stream": true,
    "reasoning": { "effort": "low" }
  }'

With Function Tool

curl -X POST "https://genaiapi.cloudsway.net/v1/ai/{endpointPath}/responses" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${your_AK}" \
  -d '{
    "model": "MaaS_Gr_4.6_20260812",
    "input": "What is the weather in Tokyo?",
    "tools": [
      {
        "type": "function",
        "name": "get_weather",
        "description": "Get current weather",
        "parameters": {
          "type": "object",
          "properties": {
            "location": { "type": "string" }
          },
          "required": ["location"]
        }
      }
    ],
    "tool_choice": "auto"
  }'

Response Example

non-streaming

{
  "id": "resp_abc123xyz",
  "object": "response",
  "created_at": 1755676800,
  "model": "MaaS_Gr_4.6_20260812",
  "status": "completed",
  "output": [
    {
      "type": "message",
      "id": "msg_001",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "Prompt caching stores KV pairs from unchanged prompt prefixes..."
        }
      ]
    }
  ],
  "usage": {
    "input_tokens": 128,
    "output_tokens": 64,
    "total_tokens": 192,
    "input_tokens_details": {
      "cached_tokens": 96
    }
  }
}

Streaming (SSE Fragment Example)

data: {"type":"response.created","response":{"id":"resp_abc123xyz","status":"in_progress"}}

data: {"type":"response.output_text.delta","delta":"Prompt caching"}

data: {"type":"response.completed","response":{"id":"resp_abc123xyz","status":"completed","usage":{"input_tokens":128,"output_tokens":64,"total_tokens":192,"input_tokens_details":{"cached_tokens":96}}}}

B. Chat Completions

Request Protocol

HTTPS

Header

Parameter Name Type Required Description
Content-Type string Yes application/json
Authorization string Yes Bearer ${your_AK}
x-grok-conv-id string No Prompt Cache session sticky ID; the platform extracts it from the HTTP header and transparently transmits it to the upstream (Chat Completions only)

Request URL

Endpoint Interface Mode

POST https://genaiapi.cloudsway.net/v1/ai/{endpointPath}/chat/completions

Converged Interface Mode

POST https://genaiapi.cloudsway.net/v1/chat/completions

Request Body Parameters

Parameter Name Secondary Parameters Three-level parameters Level 4 Parameters Type Required Description
model - - - string Yes Model Name;
messages - - - array Yes Chat Messages (Text / Image)
role - - string Yes system / user / assistant / tool
content - - string | array Yes Text or multimodal content
type - string No Multimodal types, e. g. text/ image_url
text - string No Text snippet
image_url url string No Image URL
max_completion_tokens - - - int | null No Visible output token limit (excluding inference/tools); Grok retains this field
max_tokens - - - int | null No Deprecated, it is recommended to use max_completion_tokens
stream - - - bool | null No SSE Streaming
stream_options - - - object No Streaming Options
include_usage - - bool No Comes with usage before the end of the stream; defaults to true if not set
temperature - - - number | null No Sampling temperature 0–2
top_p - - - number | null No Nuclear Sampling
n - - - int | null No Number of generated items
user - - - string | null No End User Identifier
prompt_cache_key - - - string | null No Cache Sticky Routing
reasoning_effort - - - string | null No Inference Strength low/ medium/ high/ xhigh
tools - - - array | null No Function tools, maximum 128
type - - string No Fixed function
function name - string No function name
function description - string No Function Description
function parameters - object No JSON Schema
tool_choice - - - string | object No none / auto / required / specify function
parallel_tool_calls - - - bool | null No Whether to enable parallel tool calls
response_format - - - object No Output Format
type - - string No text / json_object / json_schema
json_schema - - object No JSON Schema Definition
frequency_penalty - - - number | null No -2 to 2; inference model not supported
presence_penalty - - - number | null No -2 to 2; grok-3 / inference model not supported
stop - - - array | null No Up to 4 stop strings; not supported by the inference model
deferred - - - bool | null No truereturns request_idfor asynchronous result retrieval (Grok extension)
reasoning_split - - - bool | null No Reasoning Decomposition (Grok Extension, LlmChatCompletionRequest)
tool_stream - - - bool | null No Tool Streaming (Grok Extension)

Request Example

Prompt Cache — Turn 1 (Cache Establishment, Endpoint Interface Mode)

curl -X POST "https://genaiapi.cloudsway.net/v1/ai/{endpointPath}/chat/completions" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${your_AK}" \
  -H "x-grok-conv-id: conv_abc123" \
  -d '{
    "model": "MaaS_Gr_4.6_20260812",
    "messages": [
      {"role": "system", "content": "You are Grok, a helpful and truthful AI assistant built by xAI."},
      {"role": "user", "content": "What is prompt caching?"},
      {"role": "assistant", "content": "Prompt caching stores KV pairs from unchanged prompt prefixes so they can be reused on subsequent requests. This makes responses faster and cheaper."}
    ]
  }'

Prompt Cache — Turn 2 (Cache HIT, prefix remains unchanged, new messages appended)

curl -X POST "https://genaiapi.cloudsway.net/v1/ai/{endpointPath}/chat/completions" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${your_AK}" \
  -H "x-grok-conv-id: conv_abc123" \
  -d '{
    "model": "MaaS_Gr_4.6_20260812",
    "messages": [
      {"role": "system", "content": "You are Grok, a helpful and truthful AI assistant built by xAI."},
      {"role": "user", "content": "What is prompt caching?"},
      {"role": "assistant", "content": "Prompt caching stores KV pairs from unchanged prompt prefixes so they can be reused on subsequent requests. This makes responses faster and cheaper."},
      {"role": "user", "content": "Show me a code example."}
    ]
  }'

Fusion Interface Mode + Inference + Streaming

curl -N -X POST "https://genaiapi.cloudsway.net/v1/chat/completions" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${your_AK}" \
  -d '{
    "model": "MaaS_Gr_4.6_20260812",
    "messages": [
      {"role": "user", "content": "Solve: 17 * 23"}
    ],
    "reasoning_effort": "high",
    "max_completion_tokens": 2048,
    "stream": true
  }'

Response Example

non-streaming

{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1755676800,
  "model": "MaaS_Gr_4.6_20260812",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Here is a simple Python example of prompt caching concepts:\n\n```python\n# Turn 1: establish prefix\nmessages = [system_msg, user_msg_1]\n# Turn 2: append new turn, prefix unchanged\nmessages.append(assistant_msg_1)\nmessages.append(user_msg_2)\n```"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 256,
    "completion_tokens": 128,
    "total_tokens": 384,
    "prompt_tokens_details": {
      "cached_tokens": 192
    }
  }
}

Streaming (SSE Fragment Example)

data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant","content":"Here"},"finish_reason":null}]}

data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":" is"},"finish_reason":null}]}

data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":{"prompt_tokens":256,"completion_tokens":128,"total_tokens":384,"prompt_tokens_details":{"cached_tokens":192}}}

data: [DONE]