Agnes Image — Agnes Image 2.1 Flash 图像模型
Overview
Agnes Image 2.1 Flash is Sapiens AI's free image generation model with an OpenAI-compatible images API. Supports text-to-image generation and image-to-image editing.
- Model ID:
agnes-image-2.1-flash - Base URL:
https://apihub.agnes-ai.com/v1 - Pricing: ~$0.003/image (free tier available)
- Auth:
Authorization: Bearer YOUR_API_KEY - Generate endpoint:
POST /v1/images/generations
Quick Start
API key from AGNES_API_KEY environment variable.
Python (OpenAI SDK)
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["AGNES_API_KEY"],
base_url="https://apihub.agnes-ai.com/v1",
)
# Text-to-Image
resp = client.images.generate(
model="agnes-image-2.1-flash",
prompt="A cute cat playing soccer on a green field, sunny day, cinematic style",
size="1024x1024",
)
print(resp.data[0].url)
cURL (Text-to-Image)
curl https://apihub.agnes-ai.com/v1/images/generations \
-H "Authorization: Bearer $AGNES_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "agnes-image-2.1-flash",
"prompt": "A futuristic city at sunrise, cinematic realism",
"size": "1024x768",
"extra_body": {"response_format": "url"}
}'
cURL (Image-to-Image)
curl https://apihub.agnes-ai.com/v1/images/generations \
-H "Authorization: Bearer $AGNES_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "agnes-image-2.1-flash",
"prompt": "Turn the scene into a rainy cyberpunk night with neon lights",
"size": "1024x768",
"extra_body": {
"image": ["https://example.com/input.png"],
"response_format": "url"
}
}'
Endpoint
| Item | Value |
|---|---|
| Method | POST |
| URL | https://apihub.agnes-ai.com/v1/images/generations |
| Content-Type | application/json |
| Auth Header | Authorization: Bearer <key> |
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model |
string | Yes | agnes-image-2.1-flash |
prompt |
string | Yes | Image description / edit instruction |
size |
string | Yes | Output size, e.g. 1024x768, 1024x1024 |
image |
string[] | For img2img | Input image URLs or Data URIs |
return_base64 |
boolean | No | Return base64 instead of URL |
extra_body |
object | No | Extra parameters (see below) |
extra_body.response_format |
string | No | url (default) or b64_json |
extra_body.image |
string[] | For img2img | Alternative way to pass input images |
Response Format
{
"created": 1780000000,
"data": [
{
"url": "https://storage.googleapis.com/agnes-aigc/xxx.png",
"b64_json": null,
"revised_prompt": null
}
]
}
Access the image at data[0].url. For base64 output, use data[0].b64_json.
Capabilities
1. Text-to-Image (文生图)
Generate an image from a text description. Use detailed prompts with:
[主体] + [场景/环境] + [风格] + [光线] + [构图] + [质量要求]
Example: A futuristic city marketplace, flying vehicles, holographic signs, dense crowds, neon lighting, cinematic realism, ultra-detailed
2. Image-to-Image (图生图)
Edit an existing image while preserving its structure. Provide the input
image URL via extra_body.image:
edit = client.images.generate(
model="agnes-image-2.1-flash",
prompt="Keep the cat and soccer ball, change scene to snowy winter field",
size="1024x1024",
extra_body={"image": ["https://example.com/original.png"]},
)
3. Base64 Output
For programmatic processing without downloading from URL:
resp = client.images.generate(
model="agnes-image-2.1-flash",
prompt="A simple red circle on white background",
size="512x512",
return_base64=True,
)
b64_data = resp.data[0].b64_json
Important Notes
response_formatmust be placed insideextra_body, NOT at the top level- Image generation may take 10-60 seconds; set client timeout to 60-360s
- Input images for img2img must be publicly accessible HTTPS URLs or Data URIs
- Do NOT add
tags: ["img2img"]— just provide theimagearray - Both
agnes-image-2.1-flash(text-to-image) andagnes-image-2.0-flash(image-to-image focused) are available; 2.1 handles both tasks
Bundled Scripts
scripts/generate.py
Generate images from the command line:
# Text-to-image
python scripts/generate.py --prompt "A dragon flying over mountains" --size 1024x768
# Image-to-image
python scripts/generate.py --prompt "Make it nighttime" --input-image https://example.com/photo.png
# Save to file
python scripts/generate.py --prompt "Sunset beach" --output sunset.png
Reads AGNES_API_KEY from environment.
Reference
See references/api_reference.md for complete parameter details,
error handling, prompt engineering tips, and more examples.
