Text to Image
Fast-API supports calling image generation models via the OpenAI-compatible format, including the GPT-Image series.
Basic Information
- Endpoint:
https://fast-api.org/v1/images/generations - Authentication: Bearer Token (API Key)
- Request Method: POST
Request Parameters
| Parameter | Type | Description |
|---|---|---|
| model | string | Model name (e.g., gpt-image-1) |
| prompt | string | Image description text |
| n | integer | Number of images to generate (default 1) |
| size | string | Image size (e.g., 1024x1024) |
| quality | string | Image quality (standard or hd) |
Python Request Example
python
import requests
import base64
url = "https://fast-api.org/v1/images/generations"
headers = {
"Authorization": "Bearer sk-your API Key",
"Content-Type": "application/json"
}
payload = {
"model": "gpt-image-1",
"prompt": "A cute orange tabby cat sits on the windowsill, sunlight streaming in, cozy atmosphere",
"n": 1,
"size": "1024x1024"
}
response = requests.post(url, headers=headers, json=payload)
result = response.json()
if "data" in result:
for i, img in enumerate(result["data"]):
if "url" in img:
print(f"Image {i+1} URL: {img['url']}")
elif "b64_json" in img:
image_data = base64.b64decode(img["b64_json"])
with open(f"image_{i+1}.png", "wb") as f:
f.write(image_data)
print(f"Image {i+1} saved")cURL Example
bash
curl https://fast-api.org/v1/images/generations \
-H "Authorization: Bearer sk-your API Key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-1",
"prompt": "A beautiful sunset over the ocean",
"n": 1,
"size": "1024x1024"
}'Notes
- Image generation usually takes longer, please be patient
- The generated images may have content safety restrictions
- Size options may vary depending on the model
- Image generation usually consumes more tokens, please monitor your balance