Appearance
Gemini 3.1 Flash Image Preview
gemini-3.1-flash-image-preview is the Gemini 3.1 Flash image model for generation and editing. Use the canonical Gemini model id and pass an aspect ratio through size.
API surface
| Operation | Endpoint | Mode |
|---|---|---|
| Image generation | POST /v1/images/generations | Sync |
| Image generation task | POST /v1/async/images/generations | Async |
| Image editing | POST /v1/images/edits | Sync |
| Image editing task | POST /v1/async/images/edits | Async |
Pricing
Credits
| Model id | Output tier | Credits / image |
|---|---|---|
gemini-3.1-flash-image-preview-512 | 512px | 4 |
gemini-3.1-flash-image-preview | 1K (1024px) | 4 |
gemini-3.1-flash-image-preview-2k | 2K (2048px) | 6 |
gemini-3.1-flash-image-preview-4k | 4K (4096px) | 8 |
Request fields
This model uses the same OpenAI-compatible image fields as the rest of Pixapi.
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Use gemini-3.1-flash-image-preview. |
prompt | string | Yes | Describe the desired image or edit. |
image | string or string[] | Required for edits | Input image URL, or an array of image URLs when multiple references are supported. |
n | number | No | Number of images to return. Only 1 is currently supported. |
size | string | No | Output aspect ratio: 1:1, 16:9, 9:16, 4:3, 3:4, 2:3, 3:2, 4:5, 5:4, 21:9, 1:4, 4:1, 8:1, or 1:8. |
Example
bash
curl https://api.pixapi.ai/v1/images/generations \
-H "Authorization: Bearer $PIXAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.1-flash-image-preview",
"prompt": "A polished product photo of a ceramic coffee cup",
"n": 1,
"size": "1:1"
}'py
import os
import requests
response = requests.post(
"https://api.pixapi.ai/v1/images/generations",
headers={
"Authorization": f"Bearer {os.environ['PIXAPI_KEY']}",
"Content-Type": "application/json",
},
json={
"model": "gemini-3.1-flash-image-preview",
"prompt": "A polished product photo of a ceramic coffee cup",
"n": 1,
"size": "1:1"
},
)
response.raise_for_status()
print(response.json())js
const response = await fetch('https://api.pixapi.ai/v1/images/generations', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.PIXAPI_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"model": "gemini-3.1-flash-image-preview",
"prompt": "A polished product photo of a ceramic coffee cup",
"n": 1,
"size": "1:1"
}),
});
if (!response.ok) {
throw new Error(await response.text());
}
console.log(await response.json());go
package main
import (
"bytes"
"fmt"
"io"
"net/http"
"os"
)
func main() {
body := []byte(`{
"model": "gemini-3.1-flash-image-preview",
"prompt": "A polished product photo of a ceramic coffee cup",
"n": 1,
"size": "1:1"
}`)
req, err := http.NewRequest(
"POST",
"https://api.pixapi.ai/v1/images/generations",
bytes.NewBuffer(body),
)
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer "+os.Getenv("PIXAPI_KEY"))
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
result, _ := io.ReadAll(resp.Body)
fmt.Println(string(result))
}For the shared response shape and edit upload example, see the API Reference.
