MaaS_Gr
请求协议
http
Header
| 参数名 | 类型 | 必填 | 描述 |
|---|---|---|---|
Content-Type |
string | 是 | 固定为 application/json |
Authorization |
string | 是 | Bearer {your_api_key} |
请求 URL
POST https://{新平台域名}/v1/ai/{endpointPath}/happyhorse/v1/video-synthesis
请求 Body 参数
| 属性名 | 类型 | 必需/可选 | 描述 |
|---|---|---|---|
deferred |
boolean 或 null |
可选(默认 false) |
若设为 true,请求返回 request_id,随后可通过 GET /v1/chat/deferred-completion/{request_id} 获取延迟响应。 |
frequency_penalty |
number 或 null |
可选(默认 0,范围 -2\~2) |
基于 tokens 已有频率的惩罚值。正值降低重复相同行的概率。(推理模型不支持) |
logit_bias |
object 或 null |
可选 | (reasoning models不支持)将 token ID 映射到 -100\~100 偏置值的 JSON 对象。 |
logprobs |
boolean 或 null |
可选(默认 false) |
是否返回输出 tokens 的对数概率。 |
max_completion_tokens |
integer 或 null |
可选 | 生成补全的最大 token 数(仅作用于可见输出 token,不包含推理或函数调用 token)。 |
max_tokens |
integer 或 null |
可选(已弃用) | 已弃用,推荐使用 max_completion_tokens。 |
messages |
array |
必需 | 对话消息列表。每条消息包含 role(system/user/assistant/tool/function)和 content(可为字符串或内容部件数组,支持文本、图片 URL、文件 ID 等)。 |
model |
string |
必需 | 使用的模型名称。 |
n |
integer 或 null |
可选(默认 1,最小 1) |
为每条输入消息生成的补全选择数量。 |
parallel_tool_calls |
boolean 或 null |
可选(默认 true) |
若为 false,模型最多执行一个工具调用。 |
presence_penalty |
number 或 null |
可选(默认 0,范围 -2\~2) |
基于新 token 是否已出现过的惩罚值。正值鼓励模型讨论新话题。(grok-3 及推理模型不支持) |
reasoning_effort |
string 或 null |
可选 | 限制推理模型思考的强度。可选 low(使用较少推理 token)或 high(使用更多推理 token)。不支持 grok-4。 |
response_format |
object 或 null |
可选 | 结构化输出格式。可指定 text、json_object 或带有 json_schema 的详细结构。 |
search_parameters |
object 或 null |
可选 | 控制实时数据检索的参数。包含 mode(off/on/auto)、sources(x、web、news、rss)、日期范围、引用返回等。 |
seed |
integer 或 null |
可选 | 确定性采样种子(尽力保证相同参数返回相同结果,非绝对)。 |
stop |
array 或 null |
可选 | 最多 4 个停止序列,遇到即停止生成。(推理模型不支持) |
stream |
boolean 或 null |
可选(默认 false) |
是否启用流式响应。启用后以 SSE 格式发送增量消息。 |
stream_options |
object 或 null |
可选 | 流式选项。包含 include_usage(在结束前额外发送一个包含用量的块)。 |
temperature |
number 或 null |
可选(默认 1,范围 0\~2) |
采样温度。较高值使输出更随机,较低值更确定。 |
tool_choice |
string 或 object 或 null |
可选 | 控制模型如何选择工具。"none" / "auto" / "required" 或指定具体函数名。 |
tools |
array 或 null |
可选 | 模型可调用的工具列表(目前支持 function 类型)。最多 128 个函数,每个函数包含名称、描述、参数 JSON schema。 |
top_logprobs |
integer 或 null |
可选(范围 0\~8) | 在每个 token 位置返回最可能的前 K 个 token 及其对数概率。需同时设置 logprobs=true。 |
top_p |
number 或 null |
可选(默认 1,范围 0\~1,不包含 0) |
核采样概率质量。通常与 temperature 二选一调整。 |
user |
string 或 null |
可选 | 代表终端用户的唯一标识符,用于监控和滥用检测。 |
web_search_options |
object 或 null |
可选 | 仅为 OpenAI 兼容性保留的字段,包含 filters、search_context_size 和 user_location。 |
调用示例
/chat/completions
/chat/completions 非流式请求
curl --location --request POST
'https://{新平台域名}/v1/ai/{endpointPath}/chat/completions' \
--header 'Authorization: Bearer {api key}' \
--header 'Content-Type: application/json' \
--data-raw '{
"model": "grok-4.3",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
],
"thinking": {"type": "enabled"},
"reasoning_effort": "high",
"stream": false
}'
/chat/completions 流式请求
curl --location --request POST
'https://{新平台域名}/v1/ai/{endpointPath}/chat/completions' \
--header 'Authorization: Bearer {api key}' \
--header 'Content-Type: application/json' \
--data-raw '{
"model": "grok-4.3",
"stream": true,
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
],
"thinking": {"type": "enabled"},
"reasoning_effort": "high",
"stream": false
}'
统一域名访问 /v1/chat/completions
Curl 请求
curl --location 'https://genaiapi.cloudsway.net/v1/chat/completions' \
--header 'Authorization: Bearer YOUR_ACCESS_KEY' \
--header 'Content-Type: application/json' \
--data '{
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "hi"
}
]
}
],
"model":"MaaS_Gr_4.3_20260501",
"stream": false,
"stream_options":{"include_usage":true}
}'
Python 请求
import requests
import json
# 请替换为您的有效 Access Key
YOUR_ACCESS_KEY = "YOUR_ACCESS_KEY"
url = "https://genaiapi.cloudsway.net/v1/chat/completions"
headers = {
"Authorization": f"Bearer {YOUR_ACCESS_KEY}",
"Content-Type": "application/json"
}
payload = {
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "hi"
}
]
}
],
"model": "MaaS_Gr_4.3_20260501",
"stream": False,
"stream_options": {"include_usage": True}
}
try:
response = requests.post(url, headers=headers, json=payload)
response.raise_for_status() # 如果状态码不是 2xx,则抛出异常
print(response.json()) # 打印响应的 JSON 内容
except requests.exceptions.RequestException as e:
print(f"请求失败: {e}")
返回示例
{
"id": "a6ce483d-99b6-9910-a25a-69ff67e41e45",
"choices": [
{
"index": 0,
"logprobs": null,
"message": {
"role": "assistant",
"content": "Hi! How can I help you today?",
"refusal": null,
"annotations": null,
"images": null,
"reasoning_content": "The user said \"hi\". This is a simple greeting. As an AI, I should respond in a friendly, engaging way.\n",
"function_call": null,
"tool_calls": null,
"reasoning_details": null
},
"finish_reason": "stop",
"native_finish_reason": null
}
],
"logprobs": null,
"created": 1779095005,
"model": "MaaS_Gr_4.3_20260501",
"object": "chat.completion",
"system_fingerprint": "fp_f06c287374635121",
"service_tier": null,
"usage": {
"prompt_tokens": 131,
"completion_tokens": 126,
"total_tokens": 257,
"completion_tokens_details": {
"accepted_prediction_tokens": 0,
"audio_tokens": 0,
"image_tokens": 0,
"reasoning_tokens": 117,
"rejected_prediction_tokens": 0
},
"prompt_tokens_details": {
"audio_tokens": 0,
"cached_tokens": 128
},
"cache_creation_input_tokens": null,
"cache_creation": null,
"gemini_cache_tokens_details": null
}
}