Maliang Image — AI Image Generation & Editing
Provider: Maliang API (nano.djdog.ai)
Model: Google Gemini (image generation & editing)
Pricing: $0.60/image, free $6 credit on first use (~10 images)
What it does
Generate images from text descriptions or edit existing images using AI.
- - No images provided → text-to-image generation
- Images provided → AI image editing / inpainting (1–10 reference images, user-provided only)
Security & Data Handling
- - API Key: Auto-provisioned on first use via
POST /api/v1/provision. The key is stored only in your local environment (MALIANG_API_KEY). You can revoke it at any time. - Images: Only images explicitly provided by the user are sent to the API. The skill never reads files unless the user specifies the file path. All uploads go over HTTPS.
- No data collection: The API processes your request and returns results. Images are not stored permanently on the server.
Inputs needed
| Input | Source | Required |
|---|
| Text prompt | User message | YES |
| Reference images |
User provides file paths or URLs | NO (if omitted, generates from text) |
| Aspect ratio | User preference | NO (default:
1:1) |
Auto-Provision (First-time Setup)
On first use (when MALIANG_API_KEY is not set), automatically provision a new account:
CODEBLOCK0
Response:
CODEBLOCK1
Save the returned api_key as MALIANG_API_KEY for all subsequent requests.
Tell the user their short code (ML-XXXXXX) and initial balance — they'll need the short code to recharge later.
Balance Check
After each task, check remaining balance:
CODEBLOCK2
Response includes short_code for recharge reference. If balance is low, remind the user:
Your balance is $X.XX. To recharge, visit: https://nano.djdog.ai/recharge/{short_code}
Workflow
Step 0 — Ensure API key
If MALIANG_API_KEY is not set, run Auto-Provision first (see above) and store the returned key.
Step 1 — Determine mode
- - If the user provides one or more images (file paths, URLs, or pasted base64): edit mode
- Otherwise: generate mode
Step 2 — Prepare images (edit mode only)
For each image the user provides:
- 1. If it is a local file path, read and base64-encode it.
- If it is a URL, download it first, then base64-encode.
- Strip any
data:image/...;base64, prefix — the API accepts raw base64. - Verify each image is under 10 MB after decoding.
- Maximum 10 images total.
Step 3 — Submit task
Generate mode — call:
CODEBLOCK3
Edit mode — call:
CODEBLOCK4
Both return:
CODEBLOCK5
Extract task_id from the response.
Step 4 — Poll for result
Poll every 3 seconds, up to 120 seconds max:
CODEBLOCK6
Response data.status values:
| Status | Meaning | Action |
|---|
| INLINECODE12 | Queued | Keep polling |
| INLINECODE13 |
Generating | Keep polling |
|
completed | Done | Get image from
image_url or
image_base64 |
|
failed | Error | Show
error.message to user |
|
dead | Max retries exceeded | Show error, suggest retry |
Step 5 — Deliver result
When status is completed:
- - If
image_url is present: show the URL to the user (preferred). - If only
image_base64 is present: save to a local file and show the path.
Output format
CODEBLOCK7
Guardrails
- - Never fabricate task IDs or image URLs. Only use values from API responses.
- Never poll more than 40 times (120 seconds). If not completed, tell the user it is still processing and provide the task ID for manual checking.
- Do not send images larger than 10 MB to the edit endpoint.
- Do not send more than 10 images to the edit endpoint.
- If the API returns 402 (INSUFFICIENT_BALANCE), tell the user their balance is low and they need to recharge.
- Prompt max length is 4000 characters. If the user's prompt is longer, ask them to shorten it.
Failure handling
| Error | Action |
|---|
| 401 Unauthorized | MALIANGAPIKEY is invalid or missing. Try re-provisioning a new account. |
| 402 Insufficient Balance |
Tell user to recharge via
https://nano.djdog.ai/recharge/{short_code} (get short_code from balance endpoint) |
| 400 IMAGE
TOOLARGE | Tell user the image exceeds 10 MB limit |
| 400 TOO
MANYIMAGES | Tell user max 10 images allowed |
| Network error | Retry once, then report failure |
| Timeout (120s) | Report task ID, suggest checking later |
Examples
Text-to-image:
CODEBLOCK8
Image editing:
CODEBLOCK9
Multi-image editing:
CODEBLOCK10
Maliang Image — AI 图像生成与编辑
提供商: Maliang API (nano.djdog.ai)
模型: Google Gemini (图像生成与编辑)
定价: $0.60/张,首次使用赠送 $6 额度(约 10 张图片)
功能说明
通过文本描述生成图像,或使用 AI 编辑现有图像。
- - 未提供图像 → 文本生成图像
- 提供图像 → AI 图像编辑/修复(1–10 张参考图像,仅限用户提供)
安全与数据处理
- - API 密钥: 首次使用时通过 POST /api/v1/provision 自动配置。密钥仅存储在本地环境变量中(MALIANGAPIKEY)。可随时撤销。
- 图像: 仅用户明确提供的图像会发送至 API。除非用户指定文件路径,否则此技能不会读取任何文件。所有上传均通过 HTTPS 进行。
- 不收集数据: API 处理请求后返回结果。图像不会永久存储在服务器上。
所需输入
用户提供文件路径或 URL | 否(省略时从文本生成) |
| 宽高比 | 用户偏好 | 否(默认:1:1) |
自动配置(首次设置)
首次使用时(当 MALIANGAPIKEY 未设置时),自动配置新账户:
bash
curl -s -X POST https://nano.djdog.ai/api/v1/provision
响应:
json
{
success: true,
data: {
api_key: sk-...,
short_code: ML-XXXXXX,
balance: 6.0,
currency: USD,
recharge_url: https://nano.djdog.ai/recharge/ML-XXXXXX,
message: 您的 API 密钥已创建,初始额度为 $6(约 10 张图片)...
}
}
将返回的 apikey 保存为 MALIANGAPI_KEY,用于后续所有请求。
告知用户其短代码(ML-XXXXXX)和初始余额——后续充值需要用到短代码。
余额查询
每次任务完成后,检查剩余余额:
bash
curl -s https://nano.djdog.ai/api/v1/balance \
-H Authorization: Bearer ${MALIANGAPIKEY}
响应中包含用于充值的 short_code。如果余额不足,提醒用户:
您的余额为 $X.XX。如需充值,请访问:https://nano.djdog.ai/recharge/{short_code}
工作流程
步骤 0 — 确保 API 密钥
如果 MALIANGAPIKEY 未设置,先运行自动配置(见上文)并存储返回的密钥。
步骤 1 — 确定模式
- - 如果用户提供一张或多张图像(文件路径、URL 或粘贴的 base64):编辑模式
- 否则:生成模式
步骤 2 — 准备图像(仅编辑模式)
对于用户提供的每张图像:
- 1. 如果是本地文件路径,读取并转换为 base64 编码。
- 如果是 URL,先下载,再转换为 base64 编码。
- 去除任何 data:image/...;base64, 前缀——API 接受原始 base64。
- 验证每张图像解码后小于 10 MB。
- 最多 10 张图像。
步骤 3 — 提交任务
生成模式 — 调用:
bash
curl -s -X POST https://nano.djdog.ai/api/v1/generate \
-H Authorization: Bearer ${MALIANGAPIKEY} \
-H Content-Type: application/json \
-d {
prompt: <用户提示>,
aspect_ratio: <宽高比,默认 1:1>
}
编辑模式 — 调用:
bash
curl -s -X POST https://nano.djdog.ai/api/v1/edit \
-H Authorization: Bearer ${MALIANGAPIKEY} \
-H Content-Type: application/json \
-d {
prompt: <用户编辑指令>,
image: ,
aspect_ratio: <宽高比,可选>
}
两者均返回:
json
{
success: true,
data: {
task_id: ...,
status: pending,
created_at: ...
}
}
从响应中提取 task_id。
步骤 4 — 轮询结果
每 3 秒轮询一次,最长 120 秒:
bash
curl -s https://nano.djdog.ai/api/v1/tasks/${TASK_ID} \
-H Authorization: Bearer ${MALIANGAPIKEY}
响应 data.status 值:
| 状态 | 含义 | 操作 |
|---|
| pending | 排队中 | 继续轮询 |
| processing |
生成中 | 继续轮询 |
| completed | 完成 | 从 image
url 或 imagebase64 获取图像 |
| failed | 错误 | 向用户显示 error.message |
| dead | 超过最大重试次数 | 显示错误,建议重试 |
步骤 5 — 交付结果
当 status 为 completed 时:
- - 如果存在 imageurl:向用户显示 URL(推荐)。
- 如果仅存在 imagebase64:保存到本地文件并显示路径。
输出格式
图像生成成功!
URL: https://...
宽高比: 1:1
提示: <原始提示>
安全限制
- - 绝不伪造任务 ID 或图像 URL。仅使用 API 响应中的值。
- 轮询不超过 40 次(120 秒)。如果未完成,告知用户仍在处理中,并提供任务 ID 供手动查询。
- 不要向编辑接口发送大于 10 MB 的图像。
- 不要向编辑接口发送超过 10 张图像。
- 如果 API 返回 402(余额不足),告知用户余额不足,需要充值。
- 提示最大长度为 4000 个字符。如果用户提示过长,请其缩短。
错误处理
| 错误 | 操作 |
|---|
| 401 未授权 | MALIANGAPIKEY 无效或缺失。尝试重新配置新账户。 |
| 402 余额不足 |
告知用户通过 https://nano.djdog.ai/recharge/{short
code} 充值(从余额接口获取 shortcode) |
| 400 图像过大 | 告知用户图像超过 10 MB 限制 |
| 400 图像过多 | 告知用户最多允许 10 张图像 |
| 网络错误 | 重试一次,然后报告失败 |
| 超时(120 秒) | 报告任务 ID,建议稍后检查 |
示例
文本生成图像:
用户:生成一只可爱的橙色猫咪坐在窗台上,夕阳下,动漫风格
→ 如果没有 API 密钥则自动配置 → 使用提示调用 POST /api/v1/generate → 轮询结果 → 返回图像 URL
图像编辑:
用户:将这张照片的背景改为海滩场景 [附上照片]
→ 将照片转换为 base64 编码
→ 使用提示 + 图像调用 POST /api/v1/edit,轮询结果,返回图像 URL
多图像编辑:
用户:将这些角色设计合并成一张群像 [附上 3 张图像]
→ 将所有 3 张图像转换为 base64 编码
→ 使用提示 + 图像数组调用 POST /api/v1/edit,轮询结果,返回图像 URL