kie.ai API Wrapper
Unified access to multiple AI models through kie.ai's API. Generate images, videos, and music at 30-80% lower cost than official APIs.
Features
- - 🎨 Image Generation: Nano Banana Pro (Gemini 3 Pro), Flux, 4o-image
- 📤 Google Drive Upload: Optional automatic upload to Drive folder
- 📊 Usage Tracking: Local task history and cost estimation
- 💾 Local Storage: All files saved to
images/ before optional upload - 🎬 Video Generation (coming soon): Veo 3.1, Runway Gen-4 Aleph
- 🎵 Music Generation (coming soon): Suno V4/V4.5
Quick Start
CODEBLOCK0
Installation
Prerequisites
- 1. kie.ai API Key:
- Sign up at https://kie.ai
- Get API key from dashboard
- Add to
~/.openclaw/openclaw.json:
CODEBLOCK1
- 2. (Optional) Maton API Key for Google Drive uploads:
- Sign up at https://maton.ai
- Get API key from https://maton.ai/settings
- Set up Google Drive connection at https://ctrl.maton.ai
- Add to config:
CODEBLOCK2
Setup
CODEBLOCK3
Configuration
Google Drive Upload (Optional)
CODEBLOCK4
Get your folder ID from the Google Drive URL:
CODEBLOCK5
Commands
generate-image
Generate images with various models.
CODEBLOCK6
Examples:
CODEBLOCK7
balance
Check credit usage and remaining balance.
CODEBLOCK8
Shows:
- - Link to web UI for actual balance
- Local task history
- Estimated credit consumption
- USD equivalent
status
Show active/pending tasks.
CODEBLOCK9
models
List available models and pricing.
CODEBLOCK10
config
View/configure Google Drive upload settings.
CODEBLOCK11
Pricing
Approximate costs (kie.ai vs official):
| Model | kie.ai | Official | Savings |
|---|
| Nano Banana Pro | ~18-24 credits ($0.09-$0.12) | $0.15 | 20-40% |
| Veo 3.1 |
Variable | N/A | — |
| Flux Kontext | ~50 credits ($0.25) | $0.30 | ~17% |
| Suno V4 | Variable | $0.10/track | Comparable |
Credit pricing: ~$0.005 per credit (1,000 credits = $5)
Check exact costs at: https://docs.kie.ai/pricing
File Storage
Generated files are saved to the images/ directory (gitignored):
CODEBLOCK12
Format: INLINECODE3
Retention:
- - Local: Forever (or until you delete)
- kie.ai CDN: 14 days
- Google Drive: Forever (if uploaded)
Task State
Tasks are tracked in:
CODEBLOCK13
Used for:
- - Resume interrupted tasks
- Usage tracking
- Preventing duplicate submissions
Available Models
Image Generation
- -
nano-banana-pro - Gemini 3 Pro Image (1K/2K/4K) - INLINECODE5 - Gemini 2.5 Flash Image (cheaper)
- INLINECODE6 - Flux by Black Forest Labs
- INLINECODE7 - OpenAI GPT-4o Image
Video Generation (coming soon)
- -
veo-3.1 - Google Veo 3.1 (cinematic) - INLINECODE9 - Veo 3.1 Fast (cheaper)
- INLINECODE10 - Runway Gen-4 Aleph
Music Generation (coming soon)
- -
suno-v4 - Suno V4 (up to 8min) - INLINECODE12 - Suno V4.5 Plus
See https://docs.kie.ai for full list.
Troubleshooting
"KIEAPIKEY not set"
Add to ~/.openclaw/openclaw.json:
CODEBLOCK14
"Credits insufficient"
Top up at: https://kie.ai/billing
"MATONAPIKEY not set" (Drive upload)
- 1. Sign up at https://maton.ai
- Add
MATON_API_KEY to openclaw.json - Create Google Drive connection at https://ctrl.maton.ai
"Drive upload failed"
- 1. Check MATONAPIKEY is set
- Verify Google Drive connection is active at https://ctrl.maton.ai
- Ensure folder_id in config.json is correct
- Try generating without
--upload-drive first
Integration with OpenClaw
Use via exec or directly in OpenClaw agent conversations:
CODEBLOCK15
Security
Environment Variables
| Variable | Required | Purpose |
|---|
| INLINECODE16 | Yes | Authenticates all requests to INLINECODE17 |
| INLINECODE18 |
No | Authenticates Google Drive uploads via
gateway.maton.ai |
External Endpoints
| Endpoint | Method | Data Sent | Used By |
|---|
| INLINECODE20 | POST | prompt, model, resolution, aspect ratio | INLINECODE21 |
| INLINECODE22 |
GET | task ID |
generate-image.py,
watch_task.py |
|
https://api.kie.ai/api/v1/chat/credit | GET | — (auth header only) |
balance.py |
|
https://gateway.maton.ai/google-drive/upload/... | POST | image file bytes, filename |
upload-drive.py (optional) |
Data Leaving This Machine
- - Prompt text is sent to
api.kie.ai to generate images. - Generated image files are sent to
gateway.maton.ai only when --upload-drive is explicitly passed. - API keys are transmitted as
Authorization: Bearer headers and are never logged or written to disk by this skill. - No telemetry, analytics, or usage data is collected by this skill itself.
Trust Statement
This skill sends data to two third-party services: kie.ai for AI generation and maton.ai as an OAuth gateway for Google Drive. Review their respective privacy policies before use. Drive upload is strictly opt-in via --upload-drive.
Autonomous Invocation
This skill can be invoked autonomously by an OpenClaw agent when asked to generate images. It does not execute autonomously on its own — it must be called explicitly. To prevent autonomous invocation, remove the skill symlink from your OpenClaw workspace.
Links
- - kie.ai Dashboard: https://kie.ai
- Documentation: https://docs.kie.ai
- Pricing: https://docs.kie.ai/pricing
- Logs/Balance: https://kie.ai/logs
- Billing: https://kie.ai/billing
- Maton (for Drive): https://maton.ai
- GitHub Repo: https://github.com/jon-xo/kie-ai-skill
License
MIT
Support
Issues: https://github.com/jon-xo/kie-ai-skill/issues
kie.ai API 封装
通过kie.ai的API统一访问多种AI模型。以比官方API低30-80%的成本生成图像、视频和音乐。
功能特性
- - 🎨 图像生成:Nano Banana Pro (Gemini 3 Pro)、Flux、4o-image
- 📤 Google Drive上传:可选自动上传至Drive文件夹
- 📊 用量追踪:本地任务历史与成本估算
- 💾 本地存储:所有文件在上传前保存至images/目录
- 🎬 视频生成 (即将推出):Veo 3.1、Runway Gen-4 Aleph
- 🎵 音乐生成 (即将推出):Suno V4/V4.5
快速开始
bash
生成图像
./kie-ai.sh generate-image 宁静的日式花园,夕阳西下
自定义选项
./kie-ai.sh generate-image 赛博朋克城市 --resolution 2K --aspect 16:9
上传至Google Drive
./kie-ai.sh generate-image 太空星云 --upload-drive
查看用量
./kie-ai.sh balance
安装
前置条件
- 1. kie.ai API密钥:
- 在 https://kie.ai 注册
- 从控制台获取API密钥
- 添加至 ~/.openclaw/openclaw.json:
json
env: {
vars: {
KIE
APIKEY: 在此输入您的密钥
}
}
- 2. (可选)Maton API密钥用于Google Drive上传:
- 在 https://maton.ai 注册
- 从 https://maton.ai/settings 获取API密钥
- 在 https://ctrl.maton.ai 设置Google Drive连接
- 添加至配置:
json
MATON
APIKEY: 在此输入您的Maton密钥
设置
bash
克隆至 ~/src
cd ~/src
git clone https://github.com/jon-xo/kie-ai-skill.git
cd kie-ai-skill
赋予执行权限
chmod +x kie-ai.sh lib/*.py
为OpenClaw创建符号链接
ln -s ~/src/kie-ai-skill ~/.openclaw/workspace/skills/kie-ai-skill
测试
./kie-ai.sh generate-image 测试图像
配置
Google Drive上传(可选)
bash
查看/编辑配置
./kie-ai.sh config
编辑 config.json
{
drive: {
enabled: true,
folder_id: 您的Google Drive文件夹ID
}
}
从Google Drive URL获取文件夹ID:
https://drive.google.com/drive/folders/1abc...xyz
^^^^ 这部分
命令
generate-image
使用多种模型生成图像。
bash
./kie-ai.sh generate-image <提示词> [选项]
选项:
--model <名称> 模型:nano-banana-pro(默认)、google/nano-banana、flux-kontext、4o-image
--resolution <分辨率> 分辨率:1K(默认)、2K、4K
--aspect <比例> 宽高比:1:1(默认)、16:9、9:16、4:3等
--upload-drive 生成后上传至Google Drive(需要配置)
示例:
bash
基础生成
./kie-ai.sh generate-image 木桌上的红苹果
高分辨率
./kie-ai.sh generate-image 山景 --resolution 4K
宽屏
./kie-ai.sh generate-image 电影场景 --resolution 2K --aspect 16:9
16位像素艺术
./kie-ai.sh generate-image 赛博朋克龙虾,16位像素艺术,无文字 --aspect 16:9
生成并上传
./kie-ai.sh generate-image 抽象艺术 --upload-drive
balance
查看积分使用情况和剩余余额。
bash
./kie-ai.sh balance
显示:
- - 实际余额的网页UI链接
- 本地任务历史
- 预估积分消耗
- 等值美元
status
显示活动/待处理任务。
bash
./kie-ai.sh status
models
列出可用模型和定价。
bash
./kie-ai.sh models
config
查看/配置Google Drive上传设置。
bash
./kie-ai.sh config
定价
大致费用(kie.ai vs 官方):
| 模型 | kie.ai | 官方 | 节省 |
|---|
| Nano Banana Pro | ~18-24积分($0.09-$0.12) | $0.15 | 20-40% |
| Veo 3.1 |
可变 | 不适用 | — |
| Flux Kontext | ~50积分($0.25) | $0.30 | ~17% |
| Suno V4 | 可变 | $0.10/曲 | 相当 |
积分定价: ~$0.005/积分(1,000积分 = $5)
查看精确费用:https://docs.kie.ai/pricing
文件存储
生成的文件保存至images/目录(已被git忽略):
~/src/kie-ai-skill/images/
2026-02-11-12-05-01-1.png
2026-02-11-12-09-56-1.png
...
格式:YYYY-MM-DD-HH-MM-SS-{索引}.png
保留期限:
- - 本地:永久(或直至您删除)
- kie.ai CDN:14天
- Google Drive:永久(如果上传)
任务状态
任务追踪于:
~/src/kie-ai-skill/.task-state.json
用于:
可用模型
图像生成
- - nano-banana-pro - Gemini 3 Pro图像(1K/2K/4K)
- google/nano-banana - Gemini 2.5 Flash图像(更便宜)
- flux-kontext - Black Forest Labs的Flux
- 4o-image - OpenAI GPT-4o图像
视频生成 (即将推出)
- - veo-3.1 - Google Veo 3.1(电影级)
- veo-3.1-fast - Veo 3.1快速版(更便宜)
- runway-aleph - Runway Gen-4 Aleph
音乐生成 (即将推出)
- - suno-v4 - Suno V4(最长8分钟)
- suno-v4.5 - Suno V4.5 Plus
查看完整列表:https://docs.kie.ai
故障排除
KIEAPIKEY未设置
添加至 ~/.openclaw/openclaw.json:
json
env: {
vars: {
KIEAPIKEY: 在此输入您的密钥
}
}
积分不足
充值地址:https://kie.ai/billing
MATONAPIKEY未设置(Drive上传)
- 1. 在 https://maton.ai 注册
- 将 MATONAPIKEY 添加至 openclaw.json
- 在 https://ctrl.maton.ai 创建Google Drive连接
Drive上传失败
- 1. 检查MATONAPIKEY是否已设置
- 验证Google Drive连接在 https://ctrl.maton.ai 是否活跃
- 确保config.json中的folder_id正确
- 先尝试不使用 --upload-drive 生成
与OpenClaw集成
通过exec或直接在OpenClaw代理对话中使用:
bash
从OpenClaw聊天
使用kie.ai生成赛博朋克城市图像
代理将运行:
cd ~/src/kie-ai-skill && ./kie-ai.sh generate-image 赛博朋克城市
安全性
环境变量
| 变量 | 必需 | 用途 |
|---|
| KIEAPIKEY | 是 | 认证所有对 api.kie.ai 的请求 |
| MATONAPIKEY |
否 | 通过 gateway.maton.ai 认证Google Drive上传 |
外部端点
| 端点 | 方法 | 发送的数据 | 使用方 |
|---|
| https://api.kie.ai/api/v1/jobs/createTask | POST | 提示词、模型、分辨率、宽高比 | generate-image.py |
| https://api.kie.ai/api/v1/jobs/recordInfo |
GET | 任务ID | generate-image.py、