Grok Image API
Use this skill to work with image endpoints that expose:
Prefer practical workflows: generate or edit an image, save the result locally, and then send or reuse the saved file.
Quick start
Prefer the bundled script:
- -
scripts/grok_image_api.py generate for text-to-image - INLINECODE3 for image editing
- INLINECODE4 to verify the endpoint is reachable
Default environment variables:
Workflow
- 1. Identify the task: generate or edit.
- Load credentials through environment variables.
- For generation, send JSON to
/v1/images/generations. - For editing, send multipart form data to
/v1/images/edits with image and optional mask. - Save the returned image locally. If the API returns a URL, download it locally by default.
- If the user is on QQ and wants the image delivered, reply with a
<qqimg> tag pointing to the local file or returned URL.
Generation
Example:
CODEBLOCK0
Use --size or --preset-size, --style, --model, --n, and --extra key=value when needed.
Editing
Example:
CODEBLOCK1
Add --mask /absolute/path/mask.png if the API supports masked edits.
Notes
- - Assume this service is not a full chat-completions endpoint.
- Do not call unrelated routes unless the user explicitly says they exist.
- Avoid echoing secrets back to the user.
- Prefer local saved files for messaging channels that can upload local images.
- Default output directory is a local
output/grok-images/ folder when --out is omitted.
References
Read references/api-notes.md when you need a compact reminder of request/response patterns, presets, and output behavior.
Grok 图像 API
使用此技能来处理图像端点,这些端点提供:
- - POST /v1/images/generations
- POST /v1/images/edits
优先采用实用工作流程:生成或编辑图像,将结果保存到本地,然后发送或重复使用已保存的文件。
快速开始
优先使用捆绑脚本:
- - scripts/grokimageapi.py generate 用于文本生成图像
- scripts/grokimageapi.py edit 用于图像编辑
- scripts/grokimageapi.py probe 用于验证端点是否可访问
默认环境变量:
- - IMAGEAPIBASEURL
- IMAGEAPI_KEY
工作流程
- 1. 确定任务:生成或编辑。
- 通过环境变量加载凭证。
- 对于生成任务,向 /v1/images/generations 发送 JSON。
- 对于编辑任务,向 /v1/images/edits 发送包含 image 和可选 mask 的多部分表单数据。
- 将返回的图像保存到本地。如果 API 返回 URL,默认情况下将其下载到本地。
- 如果用户在 QQ 上并希望接收图像,回复一个指向本地文件或返回 URL 的 标签。
生成
示例:
bash
IMAGEAPIBASE_URL=https://example.com/v1 \
IMAGEAPIKEY=... \
python3 scripts/grokimageapi.py generate \
--style anime \
--preset-size portrait \
--prompt 夜晚温馨的赛博朋克茶馆 \
--out /tmp/generated.png
需要时使用 --size 或 --preset-size、--style、--model、--n 和 --extra key=value。
编辑
示例:
bash
IMAGEAPIBASE_URL=https://example.com/v1 \
IMAGEAPIKEY=... \
python3 scripts/grokimageapi.py edit \
--image /absolute/path/input.png \
--style cute \
--prompt 将背景替换为日落海滩 \
--out /tmp/edited.png
如果 API 支持遮罩编辑,添加 --mask /absolute/path/mask.png。
注意事项
- - 假设此服务不是完整的聊天补全端点。
- 除非用户明确说明存在相关路由,否则不要调用不相关的路由。
- 避免向用户回显密钥信息。
- 对于可以上传本地图像的消息渠道,优先使用本地保存的文件。
- 当省略 --out 时,默认输出目录为本地 output/grok-images/ 文件夹。
参考资料
当需要快速回顾请求/响应模式、预设和输出行为时,请阅读 references/api-notes.md。