ai-image-skills
Overview
Use this skill to turn OpenAPI definitions into working image-generation API calls for
skills.video.
Prefer deterministic extraction from
openapi.json instead of guessing fields.
Workflow
- 1. Check API key and bootstrap environment on first use.
- Identify the active spec.
- Select the SSE endpoint pair for an image model.
- Extract request schema and generate a payload template.
- Execute
POST /generation/sse/... as default and keep the stream open. - If SSE does not reach terminal completion, poll
GET /generation/{id} to terminal status. - Return only terminal result (
COMPLETED/SUCCEEDED/FAILED/CANCELED), never IN_PROGRESS. - Apply retry and failure handling.
0) Check API key (first run)
Run this check before any API call.
CODEBLOCK0
If ok is false, tell the user to:
- - Open
https://skills.video/dashboard/developer and log in - Click INLINECODE12
- Export the key as INLINECODE13
Example:
CODEBLOCK1
1) Identify the spec
Load the most specific OpenAPI first.
- - Prefer model-specific OpenAPI when available (for example
/v1/openapi.json under a model namespace). - Fall back to platform-level
openapi.json. - Use
references/open-platform-api.md for base URL, auth, and async lifecycle.
2) Select an image endpoint
If
docs.json exists, derive image endpoints from the
Images navigation group.
Use
default_endpoints from the script output as the primary list (SSE first).
CODEBLOCK2
When docs.json is unavailable, pass a known endpoint directly (for example /generation/sse/google/nano-banana-pro).
Use references/image-model-endpoints.md as a snapshot list.
3) Extract schema and build payload
Inspect endpoint details and generate a request template from required/default fields.
CODEBLOCK3
Use the returned request_template as the starting point.
Do not add fields not defined by the endpoint schema.
Use default_create_endpoint from output unless an explicit override is required.
4) Execute SSE request (default) with automatic fallback
Prefer the helper script. It creates via SSE and keeps streaming; if stream ends before terminal completion, it automatically switches to polling fallback.
CODEBLOCK4
Treat SSE as the default result channel.
Do not finish the task on IN_QUEUE or IN_PROGRESS.
Return only after terminal result.
5) Fall back to polling
Use polling only if SSE cannot be established, disconnects early, or does not reach a terminal state.
Use
GET /generation/{id} (or model-spec equivalent path if the OpenAPI uses
/v1/...).
CODEBLOCK5
Stop polling on terminal states:
- - INLINECODE29
- INLINECODE30
- INLINECODE31
Recommended helper:
CODEBLOCK6
Return to user only after helper emits event=terminal.
6) Handle errors and retries
Handle these response codes for create, SSE, and fallback poll operations:
- -
400: request format issue - INLINECODE34 : missing/invalid API key
- INLINECODE35 : possible payment/credits issue in runtime
- INLINECODE36 : endpoint or generation id not found
- INLINECODE37 : schema validation failed
Classify non-2xx runtime errors with:
CODEBLOCK7
If category is insufficient_credits, tell the user to recharge:
- - Open
https://skills.video/dashboard and go to Billing/Credits - Recharge or purchase additional credits
- Retry after recharge
Optional balance check:
CODEBLOCK8
Apply retries only for transient conditions (network failure or temporary 5xx).
Use bounded exponential backoff (for example 1s, 2s, 4s, max 16s, then fail).
Do not retry unchanged payloads after 4xx validation errors.
Rate limits and timeouts
Treat rate limits and server-side timeout windows as unknown unless documented in the active OpenAPI or product docs.
If unknown, explicitly note this in output and choose conservative client defaults.
Resources
- -
scripts/ensure_api_key.py: validate SKILLS_VIDEO_API_KEY and show first-run setup guidance - INLINECODE48 : classify runtime errors and provide recharge guidance for insufficient credits
- INLINECODE49 : extract SSE/polling endpoint pair, contract, and payload template
- INLINECODE50 : create via SSE and auto-fallback to polling when stream does not reach terminal status
- INLINECODE51 : poll generation status until terminal completion and return final response
- INLINECODE52 : SSE-first lifecycle, fallback polling, retry baseline
- INLINECODE53 : current image endpoint snapshot from INLINECODE54
ai-image-skills
概述
使用此技能将OpenAPI定义转换为skills.video可用的图像生成API调用。优先从openapi.json中确定性提取,而非猜测字段。
工作流程
- 1. 首次使用时检查API密钥并引导环境配置。
- 识别当前使用的规范文件。
- 为图像模型选择SSE端点对。
- 提取请求模式并生成载荷模板。
- 默认执行POST /generation/sse/...并保持流连接。
- 若SSE未达到最终完成状态,轮询GET /generation/{id}直至终端状态。
- 仅返回终端结果(COMPLETED/SUCCEEDED/FAILED/CANCELED),绝不返回IN_PROGRESS。
- 应用重试和故障处理机制。
0) 检查API密钥(首次运行)
在任何API调用前执行此检查。
bash
python scripts/ensureapikey.py
如果ok为false,告知用户:
- - 打开https://skills.video/dashboard/developer并登录
- 点击创建API密钥
- 将密钥导出为SKILLSVIDEOAPI_KEY
示例:
bash
export SKILLSVIDEOAPI_KEY=<你的API密钥>
1) 识别规范文件
优先加载最具体的OpenAPI规范。
- - 优先使用模型专属的OpenAPI(例如模型命名空间下的/v1/openapi.json)。
- 回退到平台级别的openapi.json。
- 使用references/open-platform-api.md获取基础URL、认证和异步生命周期信息。
2) 选择图像端点
如果存在docs.json,从图像导航组中推导图像端点。
使用脚本输出的default_endpoints作为主列表(优先SSE)。
bash
python scripts/inspect_openapi.py \
--openapi /绝对路径/to/openapi.json \
--docs /绝对路径/to/docs.json \
--list-endpoints
当docs.json不可用时,直接传入已知端点(例如/generation/sse/google/nano-banana-pro)。
使用references/image-model-endpoints.md作为快照列表。
3) 提取模式并构建载荷
检查端点详情并从必需/默认字段生成请求模板。
bash
python scripts/inspect_openapi.py \
--openapi /绝对路径/to/openapi.json \
--endpoint /generation/sse/google/nano-banana-pro \
--include-template
使用返回的request_template作为起点。
不添加端点模式未定义的字段。
除非需要显式覆盖,否则使用输出中的defaultcreateendpoint。
4) 执行SSE请求(默认)并自动回退
优先使用辅助脚本。它通过SSE创建并保持流连接;若流在终端完成前结束,自动切换到轮询回退。
bash
python scripts/createandwait.py \
--sse-endpoint /generation/sse/google/nano-banana-pro \
--payload {prompt:白色背景上哑光黑色咖啡研磨机的极简产品照片} \
--poll-timeout 900 \
--poll-interval 3
将SSE视为默认结果通道。
不要在INQUEUE或INPROGRESS状态下完成任务。
仅在终端结果后返回。
5) 回退到轮询
仅在SSE无法建立、提前断开或未达到终端状态时使用轮询。
使用GET /generation/{id}(如果OpenAPI使用/v1/...,则使用模型专属的等效路径)。
bash
curl -X GET https://open.skills.video/api/v1/generation/<生成ID> \
-H Authorization: Bearer $SKILLSVIDEOAPI_KEY
在终端状态下停止轮询:
- - COMPLETED
- FAILED
- CANCELED
推荐辅助脚本:
bash
python scripts/wait_generation.py \
--generation-id <生成ID> \
--timeout 900 \
--interval 3
仅在辅助脚本输出event=terminal后返回给用户。
6) 处理错误和重试
处理创建、SSE和回退轮询操作的以下响应码:
- - 400:请求格式问题
- 401:缺少/无效的API密钥
- 402:运行时可能的支付/积分问题
- 404:端点或生成ID未找到
- 422:模式验证失败
使用以下命令分类非2xx运行时错误:
bash
python scripts/handleruntimeerror.py \
--status \
--body <原始错误体JSON或文本>
如果类别为insufficient_credits,告知用户充值:
- - 打开https://skills.video/dashboard并前往计费/积分页面
- 充值或购买额外积分
- 充值后重试
可选的余额检查:
bash
curl -X GET https://open.skills.video/api/v1/credits \
-H Authorization: Bearer $SKILLSVIDEOAPI_KEY
仅对临时条件(网络故障或临时5xx)应用重试。
使用有界指数退避(例如1s、2s、4s,最大16s,然后失败)。
在4xx验证错误后不重试未更改的载荷。
速率限制和超时
除非在活动OpenAPI或产品文档中有说明,否则将速率限制和服务器端超时窗口视为未知。
如果未知,在输出中明确注明并选择保守的客户端默认值。
资源
- - scripts/ensureapikey.py:验证SKILLSVIDEOAPIKEY并显示首次运行设置指南
- scripts/handleruntimeerror.py:分类运行时错误并为积分不足提供充值指南
- scripts/inspectopenapi.py:提取SSE/轮询端点对、契约和载荷模板
- scripts/createandwait.py:通过SSE创建并在流未达到终端状态时自动回退到轮询
- scripts/wait_generation.py:轮询生成状态直至终端完成并返回最终响应
- references/open-platform-api.md:SSE优先生命周期、回退轮询、重试基线
- references/image-model-endpoints.md:来自docs.json的当前图像端点快照