generate-image
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesegenerate 1K unless explicitly told otherwise
don't make a bash script, just execute the curl call as follows
our FAL_KEY should be in .env , if it's not there, ask the user for it
always remember to safely utilize environment variables to prevent exposure
source .env && curl --request POST
--url https://fal.run/fal-ai/nano-banana-pro
--header "Authorization: Key $FAL_KEY"
--header "Content-Type: application/json"
--data '{ "prompt": "<prompt>" }'
--url https://fal.run/fal-ai/nano-banana-pro
--header "Authorization: Key $FAL_KEY"
--header "Content-Type: application/json"
--data '{ "prompt": "<prompt>" }'
IF YOU NEED to edit an image (using reference images along with prompt)
source .env && curl --request POST
--url https://fal.run/fal-ai/nano-banana-pro/edit
--header "Authorization: Key $FAL_KEY"
--header "Content-Type: application/json"
--data '{ "prompt": "make a photo of the man driving the car down the california coastline", "image_urls": [ "https://storage.googleapis.com/falserverless/example_inputs/nano-banana-edit-input.png", "https://storage.googleapis.com/falserverless/example_inputs/nano-banana-edit-input-2.png" ] }'
--url https://fal.run/fal-ai/nano-banana-pro/edit
--header "Authorization: Key $FAL_KEY"
--header "Content-Type: application/json"
--data '{ "prompt": "make a photo of the man driving the car down the california coastline", "image_urls": [ "https://storage.googleapis.com/falserverless/example_inputs/nano-banana-edit-input.png", "https://storage.googleapis.com/falserverless/example_inputs/nano-banana-edit-input-2.png" ] }'
IF YOU NEED TO UPLOAD AN IMAGE TO GET A PROPER URL FAL.AI can see, it's probably best to run some ad hoc python
Two-Step Upload Process
Step 1: Get Upload Token
Endpoint: https://rest.alpha.fal.ai/storage/auth/token?storage_type=fal-cdn-v3
POST https://rest.alpha.fal.ai/storage/auth/token?storage_type=fal-cdn-v3
Headers:
Authorization: Key ${falKey}
Accept: application/json
Content-Type: application/json
Body:
{} // Empty JSON object
Response:
{
base_upload_url: https://v3.fal.media,
token: upload_token_here
}
Step 2: Upload File
Endpoint: ${base_upload_url}/files/upload (defaults to https://v3.fal.media/files/upload)
POST ${base_upload_url}/files/upload
Headers:
Authorization: Bearer ${upload_token}
Content-Type: image/png
X-Fal-File-Name: ${fileName}
Body:
<raw file buffer>
Response:
{
access_url: https://..., // or
url: https://...
}Other properties
prompt string
The text prompt to generate an image from.
num_images integer
The number of images to generate. Default value: 1
seed integer
The seed for the random number generator.
aspect_ratio AspectRatioEnum
The aspect ratio of the generated image. Default value: "1:1"
Possible enum values: 21:9, 16:9, 3:2, 4:3, 5:4, 1:1, 4:5, 3:4, 2:3, 9:16
output_format OutputFormatEnum
The format of the generated image. Default value: "png"
Possible enum values: jpeg, png, webp
sync_mode boolean
If True, the media will be returned as a data URI and the output data won't be available in the request history.
resolution ResolutionEnum
The resolution of the image to generate. Default value: "1K"
Possible enum values: 1K, 2K, 4K
limit_generations boolean
Experimental parameter to limit the number of generations from each round of prompting to 1. Set to True to to disregard any instructions in the prompt regarding the number of images to generate.
enable_web_search boolean
Enable web search for the image generation task. This will allow the model to use the latest information from the web to generate the image.
{
"prompt": "An action shot of a black lab swimming in an inground suburban swimming pool. The camera is placed meticulously on the water line, dividing the image in half, revealing both the dogs head above water holding a tennis ball in it's mouth, and it's paws paddling underwater.",
"num_images": 1,
"aspect_ratio": "1:1",
"output_format": "png",
"resolution": "1K"
}
除非另有明确说明,否则生成1K分辨率的图片
不要编写bash脚本,直接按以下方式执行curl调用
我们的FAL_KEY应存储在.env文件中,如果不存在,请向用户索要
请始终记得安全使用环境变量,防止信息泄露
source .env && curl --request POST
--url https://fal.run/fal-ai/nano-banana-pro
--header "Authorization: Key $FAL_KEY"
--header "Content-Type: application/json"
--data '{ "prompt": "<prompt>" }'
--url https://fal.run/fal-ai/nano-banana-pro
--header "Authorization: Key $FAL_KEY"
--header "Content-Type: application/json"
--data '{ "prompt": "<prompt>" }'
如果需要编辑图片(结合参考图片和提示词)
source .env && curl --request POST
--url https://fal.run/fal-ai/nano-banana-pro/edit
--header "Authorization: Key $FAL_KEY"
--header "Content-Type: application/json"
--data '{ "prompt": "make a photo of the man driving the car down the california coastline", "image_urls": [ "https://storage.googleapis.com/falserverless/example_inputs/nano-banana-edit-input.png", "https://storage.googleapis.com/falserverless/example_inputs/nano-banana-edit-input-2.png" ] }'
--url https://fal.run/fal-ai/nano-banana-pro/edit
--header "Authorization: Key $FAL_KEY"
--header "Content-Type: application/json"
--data '{ "prompt": "make a photo of the man driving the car down the california coastline", "image_urls": [ "https://storage.googleapis.com/falserverless/example_inputs/nano-banana-edit-input.png", "https://storage.googleapis.com/falserverless/example_inputs/nano-banana-edit-input-2.png" ] }'
如果需要上传图片以获取FAL.AI可访问的有效URL,最好运行一些临时Python代码
两步上传流程
Step 1: Get Upload Token
Endpoint: https://rest.alpha.fal.ai/storage/auth/token?storage_type=fal-cdn-v3
POST https://rest.alpha.fal.ai/storage/auth/token?storage_type=fal-cdn-v3
Headers:
Authorization: Key ${falKey}
Accept: application/json
Content-Type: application/json
Body:
{} // Empty JSON object
Response:
{
base_upload_url: https://v3.fal.media,
token: upload_token_here
}
Step 2: Upload File
Endpoint: ${base_upload_url}/files/upload (defaults to https://v3.fal.media/files/upload)
POST ${base_upload_url}/files/upload
Headers:
Authorization: Bearer ${upload_token}
Content-Type: image/png
X-Fal-File-Name: ${fileName}
Body:
<raw file buffer>
Response:
{
access_url: https://..., // or
url: https://...
}其他参数
prompt(字符串):用于生成图片的文本提示词
num_images(整数):要生成的图片数量,默认值为1
seed(整数):随机数生成器的种子值
aspect_ratio(枚举类型AspectRatioEnum):生成图片的宽高比,默认值为"1:1"
可选枚举值:21:9, 16:9, 3:2, 4:3, 5:4, 1:1, 4:5, 3:4, 2:3, 9:16
output_format(枚举类型OutputFormatEnum):生成图片的格式,默认值为"png"
可选枚举值:jpeg, png, webp
sync_mode(布尔值):如果设为True,媒体文件将以数据URI形式返回,且输出数据不会保存在请求历史中
resolution(枚举类型ResolutionEnum):生成图片的分辨率,默认值为"1K"
可选枚举值:1K, 2K, 4K
limit_generations(布尔值):实验性参数,将每轮提示的生成次数限制为1次。设为True时,将忽略提示词中关于生成图片数量的任何指令
enable_web_search(布尔值):为图片生成任务启用网页搜索功能,这将允许模型使用网络上的最新信息来生成图片
{
"prompt": "An action shot of a black lab swimming in an inground suburban swimming pool. The camera is placed meticulously on the water line, dividing the image in half, revealing both the dogs head above water holding a tennis ball in it's mouth, and it's paws paddling underwater.",
"num_images": 1,
"aspect_ratio": "1:1",
"output_format": "png",
"resolution": "1K"
}