- Cloudflare-hosted
FLUX.1 [schnell] 是一个拥有 120 亿参数的整流流(rectified flow)Transformer,能够根据文本描述生成图像。
| 模型信息 | |
|---|---|
| 条款和许可证 | 链接 ↗ |
| 单位定价 | $0.000053 per 512 by 512 tile, $0.00011 per step |
用法
export interface Env {
AI: Ai;
}
export default {
async fetch(request, env): Promise<Response> {
const response = await env.AI.run('@cf/black-forest-labs/flux-1-schnell', {
prompt: 'a cyberpunk lizard',
seed: Math.floor(Math.random() * 10)
});
// response.image is base64 encoded which can be used directly as an <img src=""> data URI
const dataURI = `data:image/jpeg;charset=utf-8;base64,${response.image}`;
return Response.json({ dataURI });
},
} satisfies ExportedHandler<Env>;
export interface Env {
AI: Ai;
}
export default {
async fetch(request, env): Promise<Response> {
const response = await env.AI.run('@cf/black-forest-labs/flux-1-schnell', {
prompt: 'a cyberpunk lizard',
seed: Math.floor(Math.random() * 10)
});
// Convert from base64 string
const binaryString = atob(response.image);
// Create byte representation
const img = Uint8Array.from(binaryString, (m) => m.codePointAt(0));
return new Response(img, {
headers: {
'Content-Type': 'image/jpeg',
},
});
},
} satisfies ExportedHandler<Env>;
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run/@cf/black-forest-labs/flux-1-schnell \
-X POST \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
-d '{ "prompt": "cyberpunk cat", "seed": "Random positive integer" }'参数
prompt
stringrequiredminLength: 1maxLength: 2048对您希望生成的图像的文本描述。steps
integerdefault: 4maximum: 8扩散步数;值越高,质量可能越好,但耗时越长。image
string生成的 Base64 格式图像。