- Cloudflare ホスト
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
string必須minLength: 1maxLength: 2048生成したい画像のテキスト説明です。steps
integerデフォルト: 4maximum: 8拡散ステップ数です。値が高いほど品質は上がりますが、時間がかかります。image
stringBase64 形式の生成画像です。