Repository navigation
Add KIE AI multi-model gateway integration - #777
pha13071993-oss wants to merge 2 commits into
Conversation
Adds a provider adapter for KIE AI (https://kie.ai), a multi-model aggregator offering one API key in front of dozens of video/image models (Veo, Kling, Runway, Seedream, Nano Banana, GPT Image, etc.). - tools/kie_client.py: shared plumbing for KIE's unified async task API (createTask/recordInfo), file upload, and result download. - tools/video/kie_video.py: kie_video tool, defaults to Veo 3.1 (text/image/reference-to-video), with kie_model + extra_input passthrough for any other Market video model. - tools/graphics/kie_image.py: kie_image tool, defaults to Google Nano Banana / Nano Banana Edit, with the same passthrough pattern for other Market image models. - .env.example: document KIE_API_KEY/KIEAI_API_KEY, plus two previously-undocumented env vars (ATLASCLOUD_API_KEY, FREESOUND_API_KEY) that already had tools reading them. Both tools register automatically via the existing registry discovery and report available/unavailable based on key presence, consistent with every other provider tool in tools/.
calesthio
left a comment
There was a problem hiding this comment.
Thank you for contributing KIE coverage. The current official docs do support the unified createTask route and veo-3-1 model. Before approval, the paid-job lifecycle needs correction.
[P1] Preserve accepted task identity and implement poll-only recovery. Both adapters create a task, then catch all polling/download failures and return a failed ToolResult without structured task_id. Their retry policy explicitly includes timeout, while execute always creates a new task and exposes no resume input. A timed-out job can still complete and bill; retrying the tool can therefore submit a second paid generation. Persist/return the task ID as soon as acceptance is known, disable automatic submission retries, provide a query/collect path that never submits, and explicitly report an unknown outcome when the paid POST response is lost. Add mocked submit-once, timeout, interrupted download and resume tests.
The PR adds no automated provider/registry/selector/transport tests and no docs/PROVIDERS.md entry. Please add the minimum coverage and setup/API/pricing guidance required by docs/PR_REVIEW_GUIDE.md. No live or paid call was made.
Addresses PR review: both kie_video and kie_image created a task then
caught all polling/download failures as a plain failed ToolResult with
no task_id, and retry_policy listed "timeout" as retryable even though
createTask is not idempotent -- a timed-out job can still complete and
bill, so a naive retry could submit (and pay for) a second job.
- tools/kie_client.py: add poll_task_raw() (used by kie_music, whose
Suno result shape diverges from the generic {resultUrls: [...]}
envelope) alongside the existing poll_task().
- tools/video/kie_video.py, tools/graphics/kie_image.py: split
execute() into a submit phase and a poll+download phase. A failure
in the submit phase (no task_id yet) reports the outcome as
genuinely unknown and points at kie.ai/logs instead of guessing. A
failure after a task_id exists returns it in ToolResult.data and
names it in the error message. Both tools gained a resume_task_id
input that skips createTask entirely and only polls/downloads an
existing task -- the poll-only recovery path the review asked for.
retry_policy no longer lists "timeout" as retryable.
- tools/audio/kie_tts.py, tools/audio/kie_music.py: new tools
following the same pattern (Gemini 3.8 Flash TTS, Suno V6 via
ai-music-api/generate) -- built while verifying the lifecycle fix
end-to-end, since kie_video/kie_image alone don't exercise the
music result-shape branch.
- tests/contracts/test_kie_tools.py: contract tests (identity, status,
resume_task_id presence, retry policy, registry/selector discovery).
- tests/tools/test_kie_tools.py: mocked lifecycle tests -- submit-once,
poll timeout surfaces task_id, interrupted download after a
successful poll keeps task_id and never resubmits, resume_task_id
skips createTask, and a transport error on submission itself (no
task_id to report).
- tests/contracts/test_phase3_contracts.py: add "kie" to the expected
TTS provider set now that kie_tts registers under that capability.
- docs/PROVIDERS.md: new "KIE AI -- Multi-Model Gateway" section
covering setup, default models, and the resume_task_id recovery
contract.
python -m pytest tests/contracts tests/tools tests/qa -q
-> 1838 passed, 10 skipped, 3 xfailed
No live or paid KIE API calls were made in this follow-up; all tests
mock `requests`.
Summary
tools/kie_client.py: shared plumbing for KIE AI's (https://kie.ai) unified async task API (createTask/recordInfo), file upload, and result download — mirrors the existingatlas_client.pyaggregator pattern already in this repo.tools/video/kie_video.py(kie_video, capabilityvideo_generation): defaults to Veo 3.1 (text/image/reference-to-video), with akie_model+extra_inputpassthrough so any other KIE Market video model (Kling, Runway, Seedance, ...) can be called without a code change.tools/graphics/kie_image.py(kie_image, capabilityimage_generation): defaults to Google Nano Banana / Nano Banana Edit, same passthrough pattern for other Market image models.KIE_API_KEY/KIEAI_API_KEYin.env.example, plus two previously-undocumented env vars that already had tools reading them (ATLASCLOUD_API_KEY,FREESOUND_API_KEY).Both tools register automatically via the existing
tools/tool_registry.pydiscovery (no manual registration needed) and reportavailable/unavailablebased on key presence, consistent with every other provider tool intools/.Test plan
python -m py_compileon all three new filesregistry.discover()picks upkie_video/kie_image, reportsunavailablewith no key andavailableonceKIE_API_KEYis setkie_image/kie_videoend-to-end before merging (no live calls were made in this session)