Back to skills
extension
Category: OtherAPI key required

Agnes AI 免费图片视频生成

Generate images and videos using Agnes AI models (agnes-image-2.0-flash, agnes-image-2.1-flash, agnes-video-v2.0). Trigger when user wants to generate images from text, edit images, create videos from text or images, or mentions '生图', '生视频', 'image generation', 'video generation', 'Agnes AI', 'agnes-ai.com'.

personAuthor: user_cdd89df6hubcommunity

Agnes AI Skill

Generate images and videos via the Agnes AI platform API (https://apihub.agnes-ai.com/v1). All models are free to use.

Quick Reference

| Model | Type | Model ID | |-------|------|----------| | Text-to-Image (high density) | Image | agnes-image-2.1-flash | | Image Editing / Img2Img | Image | agnes-image-2.0-flash | | Text-to-Video / Image-to-Video | Video | agnes-video-v2.0 |

Prerequisites

  1. Obtain an API key from platform.agnes-ai.com
  2. Configuration methods (priority order):
    • Method 1 (Recommended): Edit config.json and set "api_key": "your-api-key"
    • Method 2: Set environment variable AGNES_API_KEY=sk-...
    • Method 3: Add AGNES_API_KEY=sk-... to .env file in skill directory
  3. Base URL: https://apihub.agnes-ai.com/v1
  4. Auth: Authorization: Bearer YOUR_API_KEY

Image Generation

Text-to-Image

Use agnes-image-2.1-flash for generating images from text only.

Endpoint: POST /v1/images/generations

Request:

{
  "model": "agnes-image-2.1-flash",
  "prompt": "一只可爱的小猫在绿茵足球场上踢足球,阳光明媚,动感瞬间,高清摄影风格",
  "size": "1024x1024",
  "seed": null
}

Response:

{
  "created": 1774432125,
  "data": [
    { "url": "https://..." }
  ],
  "usage": { "generated_images": 1 }
}

Image Editing (Img2Img)

Use agnes-image-2.0-flash for editing existing images or multi-image composition.

Endpoint: POST /v1/images/generations

Request:

{
  "model": "agnes-image-2.0-flash",
  "prompt": "保留小猫踢足球的动作和足球不变,把场景改成傍晚的专业足球场",
  "size": "1024x768",
  "tags": ["img2img"],
  "extra_body": {
    "image": ["https://example.com/source-image.jpg"],
    "response_format": "url"
  }
}

Key parameters:

  • tags: ["img2img"] — Required for image-to-image mode
  • extra_body.image — Array of image URLs (supports single or multiple reference images)
  • seed — Set a fixed value for reproducible results

Supported sizes: 1024x768, 1024x1024, 768x1024

Video Generation

Video generation uses agnes-video-v2.0 and is asynchronous — create a task then poll for results.

Supported modes: Text-to-Video, Image-to-Video, Keyframe Animation

Create Video Task

Endpoint: POST /v1/videos

Request:

{
  "model": "agnes-video-v2.0",
  "prompt": "一只可爱的小猫在傍晚的专业足球场上踢球",
  "image": "https://example.com/source-image.jpg",
  "num_frames": 121,
  "frame_rate": 24,
  "height": 768,
  "width": 1152
}

Hard constraint: num_frames must be 8n+1, max 441 (e.g., 81, 121, 161, 241, 441).

Duration formula: seconds = num_frames / frame_rate → 121 frames @ 24fps ≈ 5s

Response (task created):

{
  "id": "task_xxx",
  "task_id": "task_xxx",
  "object": "video",
  "model": "agnes-video-v2.0",
  "status": "queued",
  "progress": 0,
  "created_at": 1780457477,
  "seconds": "5.0",
  "size": "1152x768"
}

IMPORTANT: Save task_id (or id, they are the same value) to poll for the result.

Poll for Result

Endpoint: GET /v1/videos/{task_id}

Status lifecycle: queuedin_progresscompleted / failed

Response (when completed):

{
  "id": "task_xxx",
  "task_id": "task_xxx",
  "status": "completed",
  "progress": 100,
  "seconds": "5.0",
  "size": "1152x768",
  "error": null,
  "remixed_from_video_id": "https://storage.../video_xxx.mp4"
}

IMPORTANT: The video download URL is in remixed_from_video_id — NOT video_url or url. This is a known inconsistency in the API docs.

Video Parameters

| Parameter | Type | Required | Description | |-----------|------|----------|-------------| | model | string | Yes | Fixed value: agnes-video-v2.0 | | prompt | string | Yes | Video description (text-to-video) or edit instruction (image-to-video) | | image | string | Conditional | Source image URL for image-to-video mode | | num_frames | int | Yes | Must be 8n+1, max 441. Common: 81 (~3s), 121 (~5s), 241 (~10s), 441 (~18s) | | frame_rate | int | No | 1-60, default 24 | | height | int | No | Video height, default 768 | | width | int | No | Video width, default 1152 |

Implementation Pattern (stdlib only, no httpx required)

import urllib.request, json, time

BASE_URL = "https://apihub.agnes-ai.com/v1"
headers = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json",
}

# Step 1: Create task
payload = {
    "model": "agnes-video-v2.0",
    "prompt": prompt,
    "num_frames": 121,
    "frame_rate": 24,
    "height": 768,
    "width": 1152,
}
if image_url:
    payload["image"] = image_url

req = urllib.request.Request(
    f"{BASE_URL}/videos",
    data=json.dumps(payload).encode("utf-8"),
    headers=headers,
    method="POST"
)
resp = urllib.request.urlopen(req, timeout=120)
task = json.loads(resp.read().decode("utf-8"))
task_id = task["task_id"]  # also available as task["id"]
print(f"Task created: {task_id} | Duration: {task['seconds']}s")

# Step 2: Poll until done (video gen takes ~2-3 min for 5s video)
while True:
    time.sleep(30)
    poll_req = urllib.request.Request(
        f"{BASE_URL}/videos/{task_id}",
        headers=headers,
        method="GET"
    )
    result = json.loads(urllib.request.urlopen(poll_req, timeout=60).read().decode("utf-8"))
    status = result["status"]
    progress = result.get("progress", 0)
    print(f"  Status: {status} | Progress: {progress}%")
    
    if status == "completed":
        # ⚠️ URL is in remixed_from_video_id, NOT video_url or url
        video_url = result.get("remixed_from_video_id") or result.get("video_url") or result.get("url")
        print(f"Done! Video URL: {video_url}")
        break
    elif status == "failed":
        raise Exception(f"Video failed: {result.get('error')}")

Python SDK Alternative

The API is fully compatible with the OpenAI SDK:

from openai import OpenAI

client = OpenAI(
    api_key=API_KEY,
    base_url="https://apihub.agnes-ai.com/v1"
)

# Image
img = client.images.generate(
    model="agnes-image-2.1-flash",
    prompt="A futuristic city",
    size="1024x1024",
)
print(img.data[0].url)

# Video
task = client.post(
    "/videos",
    body={
        "model": "agnes-video-v2.0",
        "prompt": "A cat playing soccer",
        "image": img.data[0].url,
        "num_frames": 121,
    },
    cast_to=object,
)
task_id = task["id"]
# Poll: client.get(f"/videos/{task_id}", cast_to=object)

Limitations & Gotchas

  • No SLA: Free plan has no availability guarantee; 500/502/503 errors possible during peak times
  • Video queuing: Video generation is async and may have queue wait time
  • RPM limit: Free users are rate-limited per minute; add backoff when needed
  • No billing: Models are free, no balance consumption
  • Security: Store API key in environment variable, never commit to Git

Decision Guide

| Need | Recommended Model | |------|-------------------| | Generate image from text (general) | agnes-image-2.1-flash | | Generate image from text (simple/fast) | agnes-image-2.1-flash | | Edit an existing image | agnes-image-2.0-flash | | Multi-image composition | agnes-image-2.0-flash | | Reproduce results (seed) | agnes-image-2.0-flash | | Create video from text | agnes-video-v2.0 | | Create video from image | agnes-video-v2.0 (provide image) | | Keyframe animation | agnes-video-v2.0 |

Usage Workflow

  1. User requests image or video generation
  2. Ask for the prompt (and source image if img2img/video)
  3. Build and send the HTTP request via the Python script or direct API call
  4. For images: return the URL from response
  5. For videos: poll until status == "completed", then return the video URL