> ## Documentation Index
> Fetch the complete documentation index at: https://docs.niuapi.vip/llms.txt
> Use this file to discover all available pages before exploring further.

# Grok系列图片视频生成

## **接口说明**

> 模型列表可在模型广场上查看

### `POST /v1/chat/completions`

> 通用接口，支持对话聊天、图像生成、图像编辑、视频生成、视频超分

```text theme={null}
curl https://niuapi.vip/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $智牛API Token" \
  -d '{
    "model": "grok-4",
    "messages": [{"role":"user","content":"你好"}]
  }'
```

支持的请求参数

生成图片的model名称应该为`grok-imagine-1.0`

生成视频的model名称应该为`grok-imagine-1.0-video`

| **字段**                | **类型**        | **说明**         | **可用参数**                                                                                           |
| :-------------------- | :------------ | :------------- | :------------------------------------------------------------------------------------------------- |
| `model`               | string        | 模型名称           | 见上方模型列表                                                                                            |
| `messages`            | array         | 消息列表           | 见下方消息格式                                                                                            |
| `stream`              | boolean       | 是否开启流式输出       | `true`, `false`                                                                                    |
| `reasoning_effort`    | string        | 推理强度           | `none`, `minimal`, `low`, `medium`, `high`, `xhigh`                                                |
| `temperature`         | number        | 采样温度           | `0` \~ `2`                                                                                         |
| `top_p`               | number        | nucleus 采样     | `0` \~ `1`                                                                                         |
| `tools`               | array         | 工具定义           | OpenAI function tools                                                                              |
| `tool_choice`         | string/object | 工具选择           | `auto`, `required`, `none` 或指定工具                                                                   |
| `parallel_tool_calls` | boolean       | 是否允许并行工具调用     | `true`, `false`                                                                                    |
| `video_config`        | object        | **视频模型专用配置对象** | 支持：`grok-imagine-1.0-video`                                                                        |
| └─`aspect_ratio`      | string        | 视频宽高比          | `16:9`, `9:16`, `1:1`, `2:3`, `3:2`, `1280x720`, `720x1280`, `1792x1024`, `1024x1792`, `1024x1024` |
| └─`video_length`      | integer       | 视频时长 (秒)       | `6` \~ `30`                                                                                        |
| └─`resolution_name`   | string        | 分辨率            | `480p`, `720p`                                                                                     |
| └─`preset`            | string        | 风格预设           | `fun`, `normal`, `spicy`, `custom`                                                                 |
| `image_config`        | object        | **图片模型专用配置对象** | 支持：`grok-imagine-1.0` / `grok-imagine-1.0-fast` / `grok-imagine-1.0-edit`                          |
| └─`n`                 | integer       | 生成数量           | `1` \~ `10`                                                                                        |
| └─`size`              | string        | 图片尺寸           | `1280x720`, `720x1280`, `1792x1024`, `1024x1792`, `1024x1024`                                      |
| └─`response_format`   | string        | 响应格式           | `url`, `b64_json`, `base64`                                                                        |

**消息格式 (messages)**：

| **字段**    | **类型**       | **说明**                                        |
| :-------- | :----------- | :-------------------------------------------- |
| `role`    | string       | 角色：`developer`, `system`, `user`, `assistant` |
| `content` | string/array | 消息内容，支持纯文本或多模态数组                              |

**多模态内容块类型 (content array)**：

| **type**      | **说明** | **示例**                                                            |
| :------------ | :----- | :---------------------------------------------------------------- |
| `text`        | 文本内容   | `{"type": "text", "text": "描述这张图片"}`                              |
| `image_url`   | 图片 URL | `{"type": "image_url", "image_url": {"url": "https://..."}}`      |
| `input_audio` | 音频     | `{"type": "input_audio", "input_audio": {"data": "https://..."}}` |
| `file`        | 文件     | `{"type": "file", "file": {"file_data": "https://..."}}`          |

**注意事项**：

* `image_url/input_audio/file` 仅支持 URL 或 Data URI（`data:<mime>;base64,...`），裸 base64 会报错。
* `reasoning_effort`：`none` 表示不输出思考，其他值都会输出思考内容。
* 工具调用为**提示词模拟 + 客户端执行回填**：模型通过 `<tool_call>{...}</tool_call>` 输出调用请求，服务端解析为 `tool_calls`；不执行工具。
* `grok-imagine-1.0-fast` 与瀑布流 imagine 生成链路一致，可直接通过 `/v1/chat/completions` 调用；其 `n/size/response_format` 由服务端 `[imagine_fast]` 统一控制。
* `grok-imagine-1.0-fast` 在 `/v1/chat/completions` 的流式输出仅返回最终成图，不返回中间预览图。
* `grok-imagine-1.0-fast` 流式 URL 出图会保持原始图片名（不追加 `-final` 后缀）。
* 当图片疑似被审查拦截导致无最终图时，若开启 `image.blocked_parallel_enabled`，服务端会按 `image.blocked_parallel_attempts` 自动并行补偿生成，并优先使用不同 token；若仍无满足 `image.final_min_bytes` 的最终图则返回失败。
* `grok-imagine-1.0-edit` 必须提供图片，多图默认取**最后 3 张**与最后一个文本。
* `grok-imagine-1.0-video` 支持文生视频与图生视频（通过 `image_url` 传参考图，**仅取第 1 张**）。
* 除上述外的其他参数将自动丢弃并忽略。
