Skip to content

Gemini Image

Gemini Image is available through the OpenAI-compatible Chat Completions API. Client applications only need to call Cubicspaces /v1/chat/completions and set model to a Gemini image model.

Endpoint

http
POST /v1/chat/completions

Supported Models

ModelNotes
gemini-3-pro-image-previewGemini 3 Pro image preview model
gemini-3.1-flash-image-previewGemini 3.1 Flash image preview model

Actual model availability depends on account permissions and platform configuration.

Request Example

bash
curl https://cubicspaces.cloud/v1/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-3.1-flash-image-preview",
    "messages": [
      {
        "role": "user",
        "content": "Generate a realistic warm-toned photo of a cat in a cafe"
      }
    ],
    "stream": false
  }'

Response Format

Images are returned in choices[0].message.content of the OpenAI Chat Completions response as Markdown images:

json
{
  "id": "chatcmpl_123",
  "object": "chat.completion",
  "model": "gemini-3.1-flash-image-preview",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "![image](data:image/png;base64,BASE64_IMAGE_DATA)"
      },
      "finish_reason": "stop"
    }
  ]
}

If the model returns both text and images, content may contain both explanatory text and Markdown images. Clients can render the Markdown directly or extract the image data from the data:image/...;base64,... URL.

SDK Examples

python
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://cubicspaces.cloud/v1"
)

response = client.chat.completions.create(
    model="gemini-3.1-flash-image-preview",
    messages=[
        {"role": "user", "content": "Generate an image of a cat in a cafe"}
    ],
    stream=False
)

print(response.choices[0].message.content)
js
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "YOUR_API_KEY",
  baseURL: "https://cubicspaces.cloud/v1"
});

const response = await client.chat.completions.create({
  model: "gemini-3.1-flash-image-preview",
  messages: [
    { role: "user", content: "Generate an image of a cat in a cafe" }
  ],
  stream: false
});

console.log(response.choices[0].message.content);

Notes

  • When using the OpenAI Chat Completions format, you do not need to send Gemini-native fields in the request body.
  • Image results are returned in message.content as Markdown data URLs.
  • Non-streaming requests are recommended for image generation so clients can read the complete image content at once.