Downloads · 30 days
0
xujfcn/Crazyrouter-AI-Image-Generation
Crazyrouter-AI-Image-Generation is a machine learning model from xujfcn. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
通过 Crazyrouter API 调用 DALL-E 3、Flux 等图像生成模型
Downloads · 30 days
0
Access
Public
Updated Feb 25, 2026
Repo size
—
Likes
0
Public
Click a slice to open those files.
.md7.3 KB · 83%
From the Hugging Face model README
通过 Crazyrouter API 调用 DALL-E 3、Flux 等图像生成模型
Crazyrouter 不仅支持文本模型,还支持图像生成模型。一个 API Key 即可调用多种 AI 绘画模型。
| 模型 | 提供商 | 特点 |
|---|---|---|
dall-e-3 | OpenAI | 高质量、理解复杂提示词 |
dall-e-2 | OpenAI | 快速、便宜 |
flux-schnell | Black Forest Labs | 开源、速度快 |
flux-dev | Black Forest Labs | 高质量开源模型 |
from openai import OpenAI
client = OpenAI(
base_url="https://crazyrouter.com/v1",
api_key="sk-your-crazyrouter-key"
)
response = client.images.generate(
model="dall-e-3",
prompt="A cute robot serving coffee in a futuristic cafe, digital art style",
size="1024x1024",
quality="standard",
n=1,
)
image_url = response.data[0].url
print(f"Image URL: {image_url}")
curl https://crazyrouter.com/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-your-crazyrouter-key" \
-d '{
"model": "dall-e-3",
"prompt": "A serene Japanese garden with cherry blossoms, watercolor painting",
"size": "1024x1024",
"n": 1
}'
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://crazyrouter.com/v1",
apiKey: "sk-your-crazyrouter-key",
});
const response = await client.images.generate({
model: "dall-e-3",
prompt: "A cyberpunk cityscape at night with neon lights, 4K detailed",
size: "1024x1024",
n: 1,
});
console.log(response.data[0].url);
| 尺寸 | 用途 |
|---|---|
1024x1024 | 正方形(默认) |
1024x1792 | 竖版(手机壁纸、海报) |
1792x1024 | 横版(桌面壁纸、Banner) |
| 质量 | 说明 |
|---|---|
standard | 标准质量(默认,更快) |
hd | 高清质量(更细腻,更慢) |
| 风格 | 说明 |
|---|---|
vivid | 鲜艳风格(默认) |
natural | 自然风格 |
response = client.images.generate(
model="dall-e-3",
prompt="A majestic dragon flying over a medieval castle at sunset",
size="1792x1024", # 横版
quality="hd", # 高清
style="vivid", # 鲜艳
n=1,
)
prompts = [
"A minimalist logo for a tech startup, blue and white",
"A cozy reading nook with warm lighting, illustration style",
"An astronaut playing guitar on the moon, digital art",
"A steampunk mechanical butterfly, detailed 3D render",
]
for i, prompt in enumerate(prompts):
response = client.images.generate(
model="dall-e-3",
prompt=prompt,
size="1024x1024",
n=1,
)
print(f"Image {i+1}: {response.data[0].url}")
import requests
response = client.images.generate(
model="dall-e-3",
prompt="A beautiful sunset over the ocean",
size="1024x1024",
n=1,
)
image_url = response.data[0].url
# 下载保存
img_data = requests.get(image_url).content
with open("sunset.png", "wb") as f:
f.write(img_data)
print("Image saved as sunset.png")
Cherry Studio 内置 AI 绘画功能,配置 Crazyrouter 后可以直接在客户端中生成图片。
ChatBox 支持图片生成,在对话中输入绘画提示词即可。
这些客户端支持 DALL-E 插件,配置 Crazyrouter API 后可以在对话中生成图片。
[主体] + [风格] + [细节] + [氛围]
| 提示词 | 效果 |
|---|---|
A cat wearing a space suit, digital art, highly detailed | 太空猫,数字艺术风格 |
Minimalist mountain landscape, Japanese ink wash painting | 极简山水,水墨画风格 |
Product photo of a sleek smartphone, studio lighting, white background | 产品摄影风格 |
Isometric view of a tiny coffee shop, pixel art, warm colors | 等距像素风咖啡店 |
photorealistic, 8K, detailed, professional photographyillustration, digital art, concept art, artstationwatercolor painting, soft colors, artisticpixel art, retro, 16-bit, game style3D render, octane render, blender, cinema 4Danime style, manga, studio ghibliminimalist, clean, simple, flat design让 AI 先生成提示词,再用来绘画:
# Step 1: 用文本模型生成优化的提示词
chat_response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{
"role": "user",
"content": "Generate a detailed DALL-E prompt for: a cozy winter cabin. Include style, lighting, and mood details. Output only the prompt."
}]
)
optimized_prompt = chat_response.choices[0].message.content
# Step 2: 用优化后的提示词生成图片
image_response = client.images.generate(
model="dall-e-3",
prompt=optimized_prompt,
size="1792x1024",
quality="hd",
n=1,
)
print(f"Prompt: {optimized_prompt}")
print(f"Image: {image_response.data[0].url}")
如果你使用 ComfyUI 进行更高级的图像生成工作流,可以通过 Crazyrouter API 获取文本提示词优化:
# 用 Crazyrouter 的文本模型优化 ComfyUI 的提示词
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{
"role": "system",
"content": "You are a Stable Diffusion prompt expert. Convert user descriptions into optimized SD prompts with positive and negative prompts."
}, {
"role": "user",
"content": "A beautiful girl in a flower garden"
}]
)
print(response.choices[0].message.content)
# Output: positive prompt + negative prompt for ComfyUI/SD
| 模型 | 尺寸 | 质量 | 价格/张 |
|---|---|---|---|
| DALL-E 3 | 1024x1024 | standard | ~$0.04 |
| DALL-E 3 | 1024x1024 | hd | ~$0.08 |
| DALL-E 3 | 1792x1024 | standard | ~$0.08 |
| DALL-E 3 | 1792x1024 | hd | ~$0.12 |
| DALL-E 2 | 1024x1024 | - | ~$0.02 |
通过 Crazyrouter 调用,价格可能更优惠。