Source: https://ailoot.ai/models/th/gemini-3-1-flash-image/
Canonical: https://ailoot.ai/models/th/gemini-3-1-flash-image/
Language: th

# Google: Nano Banana 2 (Gemini 3.1 Flash Image)

[Markdown](https://ailoot.ai/models/th/gemini-3-1-flash-image/index.md) · [JSON](https://ailoot.ai/models/th/gemini-3-1-flash-image/facts.json)

## [Google: Nano Banana 2 (Gemini 3.1 Flash Image)](https://ailoot.ai/models/th/gemini-3-1-flash-image/)

Nano Banana 2 (Gemini 3.1 Flash Image) สร้างและแก้ภาพในบทสนทนา รองรับแหล่งข้อความและภาพ เอาต์พุต 0.5K–4K การจัดองค์ประกอบจากภาพอ้างอิง และการอิงผลค้นหาสำหรับฉากสินค้า อินโฟกราฟิก และงานภาพแบบวนปรับ

- [**Ailoot · รูปภาพ** `POST /v1/images/generations` `gemini-3.1-flash-image`](https://ailoot.ai/models/th/gemini-3-1-flash-image/#method-0)
- [**Ailoot Ultra · OpenAI Chat** `POST /v1/chat/completions` `google/gemini-3.1-flash-image`](https://ailoot.ai/models/th/gemini-3-1-flash-image/#method-1)
- [**Ailoot Ultra · รูปภาพ** `POST /v1/images/generations` `google/gemini-3.1-flash-image`](https://ailoot.ai/models/th/gemini-3-1-flash-image/#method-2)
- [**Ailoot Ultra · Anthropic Messages** `POST /v1/messages` `google/gemini-3.1-flash-image`](https://ailoot.ai/models/th/gemini-3-1-flash-image/#method-3)

เกี่ยวกับโมเดล

คำอธิบายนี้ครอบคลุมความสามารถของโมเดล อินพุต เอาต์พุต และตัวเลือกที่ใช้ได้ใน Ailoot แสดงด้านล่างตามเมธอดที่เลือก

Nano Banana 2 เป็นโมเดล Gemini 3.1 Flash Image ของ Google สำหรับสร้างภาพในตัวและแก้ภาพผ่านบทสนทนา ออกแบบเน้นสร้างภาพอย่างมีประสิทธิภาพและปรับแก้ซ้ำ โปรไฟล์ API ที่ระบุรับข้อความ ภาพ วิดีโอ และ PDF แล้วคืนภาพกับข้อความ เป็นรุ่นชื่อเฉพาะที่แยกจาก Gemini Nano Banana 2.1 แทนป้ายสำหรับทุกอัปเดต Nano Banana ภายหลัง

ขนาดเอาต์พุตมี 0.5K, 1K, 2K และ 4K โดยค่าเริ่มต้นคือ 1K ตัวเลือกเล็ก 0.5K เป็นลักษณะเฉพาะโปรไฟล์นี้และเหมาะกับการจัดองค์ประกอบแรก ระดับใหญ่ให้พิกเซลมากขึ้นตามรูปทรงเอาต์พุตที่เลือก อัตราส่วนที่ระบุครอบคลุมจัตุรัส แนวตั้ง และแนวนอน ได้แก่ 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9 และ 21:9 พร้อมรูปแบบเพิ่มเติม 1:4, 4:1, 1:8 และ 8:1 เช่น เอาต์พุตจัตุรัสมีตั้งแต่ 512 × 512 ที่ 0.5K ถึง 4096 × 4096 ที่ 4K เลือกรูปทรงตามตำแหน่งใช้งานก่อนปรับรายละเอียดเล็ก

Google ระบุการทำตามอัตราส่วนภาพ ความต่อเนื่องภาพ และการแสดงข้อความหลายภาษาที่ดีขึ้นเป็นส่วนอัปเดตรุ่นนี้ ใช้ถ้อยคำตรงสำหรับโปสเตอร์ เมนู หรืออินโฟกราฟิก และกำหนดว่าป้ายใดอยู่กับวัตถุใด สำหรับข้อความเล็กหรือยาว ข้อมูลรุ่นรายงานข้อจำกัดอ่านง่ายที่ยังเหลือ โดยเฉพาะ 1K ให้คำบรรยายกระชับและกำหนดขนาดสัมพันธ์ชัด สำหรับเนื้อความหนาแน่น ให้ใช้ภาพเป็นภาพอ้างอิงเลย์เอาต์แล้วตรวจตัวอักษรจริงอย่างรอบคอบ

รวมภาพอ้างอิงได้สูงสุด 14 ภาพในเวิร์กโฟลว์ คู่มือภาพอธิบายความตรงต้นฉบับสำหรับวัตถุสูงสุดสิบชิ้นและความคล้ายตัวละครสูงสุดสี่ตัว ติดป้ายภาพอ้างอิงและระบุสิ่งที่แต่ละภาพให้ สำหรับฉากสินค้า ภาพหนึ่งกำหนดวัตถุ อีกภาพกำหนดสภาพแวดล้อม และอีกภาพกำหนดแสง สำหรับชุดตัวละคร นำเอาต์พุตก่อนหน้าไปพรอมป์ต์ถัดไปและระบุคุณสมบัติที่ต้องคงเมื่อเปลี่ยนมุมหรือท่า

การอิง Web Search และ Image Search ช่วยสร้างด้วยข้อมูลปัจจุบันและภาพอ้างอิงที่ค้นได้ Image Search เพิ่มบริบทภาพ แทนมีเพียงคำอธิบายผลค้น ผู้ผลิตรองรับการค้นข้ามค่า thinking ที่ระบุ ขั้นตอนค้นภาพไม่รวมภาพบุคคลจริงเป็นภาพอ้างอิงที่ได้จากค้น และคืนเมทาดาทาระบุที่มากับผลอิงข้อมูล ให้เก็บเมทาดาทานั้นเมื่อใช้ผลในแอป

ตัวควบคุม thinking ของ Gemini 3.1 Flash Image ที่ระบุคือ minimal และ high โดย minimal เป็นค่าเริ่มต้น ต่างจากโปรไฟล์สามระดับที่เริ่มต้น medium ของ Nano Banana 2.1 Thinking ช่วยจัดองค์ประกอบและทำตามคำสั่งซับซ้อนขึ้น โมเดลมีพื้นฐานจาก Gemini 3 Flash แต่ความสัมพันธ์นี้ไม่ได้ทำให้เป็นโมเดลรันโค้ดหรือเรียกฟังก์ชันทั่วไป ตารางรุ่นภาพนี้ระบุความสามารถเหล่านั้นว่าไม่รองรับ

การแก้ผ่านบทสนทนารองรับเปลี่ยนภาพที่ให้หรือปรับภาพที่สร้างก่อน บรีฟชัดอาจว่า “รักษารูปทรงขวด ข้อความฉลาก และมุมกล้อง เปลี่ยนพื้นหลังเป็นพื้นหินสีอ่อนและเพิ่มเงานุ่มขึ้น” อธิบายองค์ประกอบที่คงไว้อย่างละเอียดเท่าส่วนที่เปลี่ยน ข้อมูลรุ่นระบุว่าความต่อเนื่องตัวละคร การระบุซ้าย/ขวา และการแก้ตามภาพขีดเขียนยังไม่สมบูรณ์ จึงเทียบรายละเอียดเหล่านั้นก่อนทำชุดภาพต่อ

ตารางโมเดล API ระบุอินพุต 131,072 และเอาต์พุต 32,768 โทเคน รองรับสร้างภาพ อิงผลค้นหา thinking และประมวลผล batch ส่วนสร้างเสียง แคช เอาต์พุตมีโครงสร้าง ค้นไฟล์ Live API และบริบท URL ไม่รองรับ เวิร์กโฟลว์ภาพไม่รับอินพุตเสียง วิดีโอหรือ PDF ประกอบงานภาพนิ่งในโปรไฟล์ API นี้ได้ แต่เอาต์พุตยังเป็นภาพกับข้อความ ภาพที่สร้างมี SynthID และจำนวนภาพที่ขอไม่ได้ถูกทำตามแน่นอนเสมอ

สำหรับอินโฟกราฟิกใช้จริง ให้ป้ายที่อนุมัติ กลุ่มผู้ชม ลำดับอ่าน ข้อมูลอ้างอิง และอัตราส่วนเป้าหมาย ขอคำอธิบายภาพชัดหนึ่งชิ้น แล้วใช้เทิร์นถัดไปแก้คำหรือระยะโดยรักษาองค์ประกอบเดิม สำหรับต้นแบบสินค้า ระบุรูปทรง พื้นผิว แสง และรายละเอียดภาพที่นิยามสินค้า ผลที่มีประโยชน์คือภาพกับข้อความเกี่ยวข้องที่ตรวจ เลือก และปรับในลำดับควบคุมได้

งานตัวอย่างจริง

### งานตัวอย่างจริง

ตัวอย่างทางเทคนิคภาษาอังกฤษ

```
Create a simple bicycle-care infographic

Create one portrait infographic teaching three bicycle checks before a short ride: tires, brakes and chain. Use three large illustrated steps in that order, a warm ivory background and dark green accents. Include only these headings: 'TIRES', 'BRAKES', 'CHAIN'. Leave generous space around each heading and keep the illustrations clearly separated.
```

#### ผลลัพธ์ที่คาดหวัง

```
One portrait image with three ordered illustrated steps and the three exact, readable headings.
```

#### ตรวจสอบผลลัพธ์

```
Inspect the rendered image for heading spelling, order and clear separation of the three checks.
```

**Ailoot · รูปภาพ** `POST /v1/images/generations` `gemini-3.1-flash-image`

[`gemini-3.1-flash-image`](https://ailoot.ai/models/th/#m=google%2Fgemini-3.1-flash-image&route=Core&caller=gemini-3.1-flash-image&fmt=images)

Google /`gemini-3.1-flash-image`

### เริ่มต้น

Nano Banana 2 (Gemini 3.1 Flash Image) สร้างและแก้ภาพในบทสนทนา รองรับแหล่งข้อความและภาพ เอาต์พุต 0.5K–4K การจัดองค์ประกอบจากภาพอ้างอิง และการอิงผลค้นหาสำหรับฉากสินค้า อินโฟกราฟิก และงานภาพแบบวนปรับ

อินพุตที่รองรับ

ข้อความ

ผลลัพธ์

รูปภาพ · ข้อความ

### ใช้งานได้ใน Ailoot · อินพุตและเมธอด

**Ailoot · รูปภาพ** `POST /v1/images/generations`

ขาเข้า

`text`

ขาออก

`image`, `text`

บริบท

131,072 tokens

เอาต์พุตสูงสุด

32,768 tokens

รูปแบบเอาต์พุต

ไฟล์ภาพ

| ฟิลด์ | ประเภท | ข้อกำหนด | ค่าและข้อจำกัด | ค่าเริ่มต้น |
| --- | --- | --- | --- | --- |
| ฟิลด์`model` | ประเภท`string` | ข้อกำหนดจำเป็น | ค่าและข้อจำกัด gemini-3.1-flash-image | ค่าเริ่มต้น— |
| ฟิลด์`prompt` | ประเภท`string` | ข้อกำหนดจำเป็น | ค่าและข้อจำกัด ความยาวขั้นต่ำ: 1 | ค่าเริ่มต้น— |
| ฟิลด์`n` | ประเภท`integer` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ขั้นต่ำ: 1 | ค่าเริ่มต้น1 |
| ฟิลด์`response_format` | ประเภท`string` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด url, b64\_json | ค่าเริ่มต้น— |
| ฟิลด์`stream` | ประเภท`boolean` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด | ค่าเริ่มต้นfalse |
| ฟิลด์`size` | ประเภท`string` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ขึ้นอยู่กับโมเดล | ค่าเริ่มต้น— |
| ฟิลด์`quality` | ประเภท`string` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ขึ้นอยู่กับโมเดล | ค่าเริ่มต้น— |
| ฟิลด์`background` | ประเภท`string` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ขึ้นอยู่กับโมเดล | ค่าเริ่มต้น— |
| ฟิลด์`output_format` | ประเภท`string` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ขึ้นอยู่กับโมเดล | ค่าเริ่มต้น— |
| ฟิลด์`output_compression` | ประเภท`integer` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ขึ้นอยู่กับโมเดล | ค่าเริ่มต้น— |
| ฟิลด์`moderation` | ประเภท`string` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ขึ้นอยู่กับโมเดล | ค่าเริ่มต้น— |
| ฟิลด์`input_fidelity` | ประเภท`string` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ขึ้นอยู่กับโมเดล | ค่าเริ่มต้น— |
| ฟิลด์`style` | ประเภท`string` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ขึ้นอยู่กับโมเดล | ค่าเริ่มต้น— |
| ฟิลด์`partial_images` | ประเภท`integer` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ขึ้นอยู่กับโมเดล | ค่าเริ่มต้น— |

ชุดผสมของสื่ออินพุต

**สร้างภาพจากข้อความ** · จำเป็น: prompt

พารามิเตอร์และวงจรการทำงานของเมธอด

| พารามิเตอร์ | ข้อกำหนด |
| --- | --- |
| พารามิเตอร์`material_types` | ข้อกำหนดtext |
| พารามิเตอร์`required` | ข้อกำหนดmodel, prompt |
| พารามิเตอร์`optional_controls` | ข้อกำหนดnull |
| พารามิเตอร์`content_type` | ข้อกำหนดapplication/json |

วงจรการทำงาน: `synchronous_result_then_owned_library`

`GET /v1/media/tasks/{task_id}` · ค่า task\_id ที่ส่งกลับมาจริง หรือระเบียนในคลังสื่อ

`GET /v1/media/assets/{asset_id}/content`

`GET /v1/media/assets`

`GET /v1/media/assets/{asset_id}`

รูปแบบเมธอดและ ID ระบุอย่างแม่นยำ ความสามารถของผู้ให้บริการแยกจากการอนุญาตให้รับคำขอ

### ราคา

#### อัตราค่าบริการเมธอด Ailoot

ข้อความอินพุต

US$0.0005 */ 1K*

ข้อความเอาต์พุต

US$0.003 */ 1K*

ขาออก, รูปภาพ

US$0.06 */ 1K tokens*

ขาเข้า

US$0.0005 */ 1K โทเค็นภาพ*

ขาออก

≈US$0.0448 *ต่อภาพความละเอียด 0.5K*

ขาออก

US$0.0672 *ต่อภาพความละเอียด 1K*

ขาออก

≈US$0.101 *ต่อภาพความละเอียด 2K*

ขาออก

≈US$0.151 *ต่อภาพความละเอียด 4K*

Ailoot กันยอดเงินประมาณการไว้ก่อนส่งคำขอ หลังได้ผลลัพธ์ จะคิดค่าบริการสุดท้ายตามการใช้งานที่วัดได้ การคิดค่าบริการแบบสตรีมใช้บันทึกการใช้งานสุดท้าย [วิธีกันยอดเงินและคิดค่าบริการสุดท้าย →](https://ailoot.ai/docs/th/billing/reserve/)

#### รายละเอียดอัตราอ้างอิง

ตารางอัตราอ้างอิงระดับโมเดลไม่เปลี่ยนเมธอดที่เลือก ยอดประมาณการ หรือค่าบริการ การคิดค่าบริการจริงใช้อัตราของเมธอด Ailoot ที่เลือก

ตารางอัตราอ้างอิงของโมเดล

#### ราคาตามการตั้งค่า

| การตั้งค่า | ตารางอัตราค่าบริการ | ค่าบริการ |
| --- | --- | --- |
| การตั้งค่าUltra | ตารางอัตราค่าบริการอัตราพื้นฐาน | ค่าบริการ ขาเข้า · โทเค็นอินพุต **$0.0010000** / 1K โทเค็น ขาออก · โทเค็นเอาต์พุต **$0.006000** / 1K โทเค็น ขาออก · ภาพขาออก **$0.12000** / 1K โทเค็น ขาออก · การค้นหาบนเว็บ **$0.028** ต่อการค้นหาเว็บ |

### ตัวอย่างคำขอ

#### Ailoot · รูปภาพ

curlPython SDKNode.js SDK

```bash
set -eu
: "${AILOOT_API_KEY:?Set your Ailoot API key}"
export AILOOT_API_KEY
export AILOOT_API_KEY
: "${AILOOT_PROMPT_FILE:?Set your actual UTF-8 image brief}"
export AILOOT_PROMPT_FILE
python3 - <<'PY_REQUEST'
import json,os
from pathlib import Path
p=json.loads('{"model": "gemini-3.1-flash-image", "prompt": ""}')
f=Path(os.environ["AILOOT_PROMPT_FILE"])
if not f.is_file():raise SystemExit("Choose your actual UTF-8 brief")
p['prompt']=f.read_text(encoding="utf-8")
if not p['prompt'].strip():raise SystemExit("Brief must contain text")
Path("request.json").write_text(json.dumps(p,ensure_ascii=False))
PY_REQUEST
curl --fail-with-body --silent --show-error https://api.ailoot.ai/v1/images/generations \
  -H "Authorization: Bearer $AILOOT_API_KEY" -H 'Content-Type: application/json' \
  --data-binary @request.json -D response-headers.txt -o result.json
python3 - <<'PY_RESULT'
import base64, json, os, subprocess
from pathlib import Path
from urllib.parse import urlsplit, urljoin

def save_images(items):
    if not items: raise SystemExit("No completed images; retain the full response")
    for index, item in enumerate(items):
        encoded=item.get("b64_json")
        uri=item.get("url", "")
        if not encoded and uri.startswith("data:image/"):
            header, separator, encoded=uri.partition(",")
            if not separator or ";base64" not in header: raise SystemExit("Unsupported image data URI")
        if encoded:
            raw=base64.b64decode(encoded,validate=True)
        elif uri:
            uri=urljoin("https://api.ailoot.ai",uri)
            parsed=urlsplit(uri)
            if parsed.scheme!="https" or not parsed.netloc or parsed.username or parsed.password:
                raise SystemExit("Invalid returned image URL")
            owned=parsed.netloc=="api.ailoot.ai" and parsed.path.startswith("/v1/media/assets/") and parsed.path.endswith("/content")
            args=["curl","--fail-with-body","--silent","--show-error",uri]
            if owned: args += ["-H","Authorization: Bearer "+os.environ["AILOOT_API_KEY"]]
            temporary=Path(f"image-{index}.bin")
            subprocess.run(args+["-o",str(temporary)],check=True)
            raw=temporary.read_bytes()
            temporary.unlink()
        else: raise SystemExit("Image has neither bytes nor URL")
        if not raw: raise SystemExit("Empty image result")
        ext="png" if raw.startswith(b"\x89PNG") else "jpg" if raw.startswith(b"\xff\xd8") else "webp" if raw[:4]==b"RIFF" and raw[8:12]==b"WEBP" else "svg" if raw.lstrip().startswith((b"<svg",b"<?xml")) else "bin"
        Path(f"image-{index}.{ext}").write_bytes(raw)
    print("Every returned image saved; complete response metadata retained")
save_images(json.loads(Path("result.json").read_text())["data"])
PY_RESULT
```

```python
from openai import OpenAI
import base64, json, os, subprocess
from pathlib import Path
from urllib.parse import urlsplit, urljoin

def save_images(items):
    if not items: raise SystemExit("No completed images; retain the full response")
    for index, item in enumerate(items):
        encoded=item.get("b64_json")
        uri=item.get("url", "")
        if not encoded and uri.startswith("data:image/"):
            header, separator, encoded=uri.partition(",")
            if not separator or ";base64" not in header: raise SystemExit("Unsupported image data URI")
        if encoded:
            raw=base64.b64decode(encoded,validate=True)
        elif uri:
            uri=urljoin("https://api.ailoot.ai",uri)
            parsed=urlsplit(uri)
            if parsed.scheme!="https" or not parsed.netloc or parsed.username or parsed.password:
                raise SystemExit("Invalid returned image URL")
            owned=parsed.netloc=="api.ailoot.ai" and parsed.path.startswith("/v1/media/assets/") and parsed.path.endswith("/content")
            args=["curl","--fail-with-body","--silent","--show-error",uri]
            if owned: args += ["-H","Authorization: Bearer "+os.environ["AILOOT_API_KEY"]]
            temporary=Path(f"image-{index}.bin")
            subprocess.run(args+["-o",str(temporary)],check=True)
            raw=temporary.read_bytes()
            temporary.unlink()
        else: raise SystemExit("Image has neither bytes nor URL")
        if not raw: raise SystemExit("Empty image result")
        ext="png" if raw.startswith(b"\x89PNG") else "jpg" if raw.startswith(b"\xff\xd8") else "webp" if raw[:4]==b"RIFF" and raw[8:12]==b"WEBP" else "svg" if raw.lstrip().startswith((b"<svg",b"<?xml")) else "bin"
        Path(f"image-{index}.{ext}").write_bytes(raw)
    print("Every returned image saved; complete response metadata retained")

f=Path(os.environ["AILOOT_PROMPT_FILE"])
if not f.is_file():raise SystemExit("Set your actual UTF-8 image brief file")
request={'model': 'gemini-3.1-flash-image', 'prompt': ''}
request["prompt"]=f.read_text(encoding="utf-8")
client=OpenAI(base_url="https://api.ailoot.ai/v1",api_key=os.environ["AILOOT_API_KEY"],max_retries=0)
result=client.images.generate(**request)
Path("sdk-result.txt").write_text(str(result),encoding="utf-8")
save_images([{"b64_json":getattr(item,"b64_json",None),"url":getattr(item,"url",None)} for item in result.data])
```

```js
import OpenAI from "openai";
import { readFileSync, writeFileSync } from "node:fs";
const key=process.env.AILOOT_API_KEY;
if(!key) throw new Error("Set your actual Ailoot API key");
const client=new OpenAI({baseURL:"https://api.ailoot.ai/v1",apiKey:key,maxRetries:0});
const request={"model": "gemini-3.1-flash-image", "prompt": ""};
if(!process.env.AILOOT_PROMPT_FILE)throw new Error("Set your actual UTF-8 image brief file");
request.prompt=readFileSync(process.env.AILOOT_PROMPT_FILE,"utf8");
const result=await client.images.generate(request);
writeFileSync("sdk-result.json",JSON.stringify(result,null,2));
if(!result.data?.length) throw new Error("No completed images");
for(let index=0;index<result.data.length;index++) {
  const item=result.data[index];let encoded=item.b64_json,uri=item.url||"",raw;
  if(!encoded && uri.startsWith("data:image/")) {
    const comma=uri.indexOf(",");if(comma<0 || !uri.slice(0,comma).includes(";base64")) throw new Error("Unsupported image data URI");
    encoded=uri.slice(comma+1);
  }
  if(encoded) {
    if(encoded.length%4!==0 || !/^[A-Za-z0-9+/]*={0,2}$/.test(encoded)) throw new Error("Invalid Base64");
    raw=Buffer.from(encoded,"base64");
  } else if(uri) {
    const u=new URL(uri,"https://api.ailoot.ai");
    if(u.protocol!=="https:" || u.username || u.password) throw new Error("Invalid returned URL");
    const owned=u.origin==="https://api.ailoot.ai" && u.pathname.startsWith("/v1/media/assets/") && u.pathname.endsWith("/content");
    const response=await fetch(u,{headers:owned?{Authorization:"Bearer "+key}:{},redirect:"manual"});
    if(!response.ok) throw new Error("Image content download failed: "+response.status);
    raw=Buffer.from(await response.arrayBuffer());
  } else throw new Error("Image has neither bytes nor URL");
  if(!raw.length) throw new Error("Empty image result");
  const ext=raw.subarray(0,4).equals(Buffer.from([137,80,78,71]))?"png":raw[0]===255&&raw[1]===216?"jpg":raw.toString("ascii",0,4)==="RIFF"&&raw.toString("ascii",8,12)==="WEBP"?"webp":raw.toString("utf8").trimStart().startsWith("<svg")||raw.toString("utf8").trimStart().startsWith("<?xml")?"svg":"bin";
  writeFileSync(`image-${index}.${ext}`,raw);
}
console.log("Every returned image saved; sdk-result.json retains complete metadata");
```

### รับและบันทึกผลลัพธ์

#### Ailoot · รูปภาพ

ดาวน์โหลดภาพที่ส่งกลับมาทุกภาพ หรือบันทึกเนื้อหา Base64 ของภาพนั้น

- `GET /v1/media/tasks/{task_id}`
- `GET /v1/media/assets/{asset_id}/content`
- `GET /v1/media/assets`
- `GET /v1/media/assets/{asset_id}`

##### เก็บผลลัพธ์ที่เสร็จสมบูรณ์ทั้งหมด

บันทึกภาพที่สร้างเสร็จทุกภาพ โดยดึงภาพจากทุก URL ที่ส่งกลับมา หรือถอดรหัสเนื้อหา Base64

บันทึกข้อมูลทุกรายการ ถอดรหัส b64\_json แต่ละรายการ หรือดึงข้อมูลจาก URL ที่ลงนามแล้วและส่งกลับมาทุกรายการ เลือกนามสกุลไฟล์จาก MIME/ไบต์จริง

##### เมื่อต้องตรวจสอบการตอบกลับต้นฉบับ

หากผลลัพธ์การสร้างหรือแก้ไขภาพต้องได้รับการตรวจสอบ ให้เก็บ operation\_id/X-Client-Request-ID เดิมและข้อมูลผลลัพธ์ที่ส่งกลับมาไว้ กู้คืนผลลัพธ์ที่มีอยู่และเป็นของตนเองผ่านคลังสื่อโดยใช้ค่า task\_id หรือ asset\_id จริง ห้ามส่งคำขอสร้าง/แก้ไขซ้ำ หรือสร้าง URL สำหรับตรวจสอบสถานะเป็นระยะจาก operation\_id

ฟิลด์การตอบกลับ

| ฟิลด์ | ประเภท |
| --- | --- |
| ฟิลด์`created` | ประเภทinteger |
| ฟิลด์`data[].url` | ประเภทstring |
| ฟิลด์`data[].b64_json` | ประเภทbase64 string |
| ฟิลด์`usage` | ประเภทobject |

ข้อผิดพลาดและขั้นตอนถัดไป

| การตอบกลับ | เงื่อนไข | ขั้นตอนถัดไป |
| --- | --- | --- |
| การตอบกลับ400 · `invalid_request_error` | เงื่อนไขฟิลด์จำเป็น รูปแบบการแทนข้อมูล หรือค่าพารามิเตอร์ไม่ถูกต้อง | ขั้นตอนถัดไปแก้ฟิลด์ที่ระบุก่อนส่งคำขอสร้างครั้งใหม่ |
| การตอบกลับ`server_error` | เงื่อนไขการตอบกลับที่ได้รับระบุว่าต้องตรวจสอบการดำเนินการหรือผลลัพธ์ | ขั้นตอนถัดไปเก็บ ID การดำเนินการ/งานที่ส่งกลับมาแต่เดิม ส่วนหัวของคำขอ และการตอบกลับไว้ แล้วอ่านข้อมูลการดำเนินการเดิมนั้นต่อด้วยวิธีที่รองรับ ห้ามส่งคำขอสร้างซ้ำ |

### ชื่ออื่น

#### ชื่ออื่นของโมเดล

<strong>Ailoot</strong> [`gemini-3.1-flash-image`](https://ailoot.ai/models/th/#m=google%2Fgemini-3.1-flash-image&route=Core&caller=gemini-3.1-flash-image&fmt=images)
**Ailoot Ultra** [`google/gemini-3.1-flash-image`](https://ailoot.ai/models/th/#m=google%2Fgemini-3.1-flash-image&route=Ultra&caller=google%2Fgemini-3.1-flash-image&fmt=images)

#### ชื่อพาธเมธอดอื่น

`/v1/images`

#### ID ที่เกี่ยวข้องสำหรับเรียกใช้โมเดล

[`google/gemini-3.1-flash-image`](https://ailoot.ai/models/th/#m=google%2Fgemini-3.1-flash-image&route=Ultra&caller=google%2Fgemini-3.1-flash-image&fmt=images), [`gemini-3.1-flash-image`](https://ailoot.ai/models/th/#m=google%2Fgemini-3.1-flash-image&route=Core&caller=gemini-3.1-flash-image&fmt=images)

**Ailoot Ultra · OpenAI Chat** `POST /v1/chat/completions` `google/gemini-3.1-flash-image`

[`google/gemini-3.1-flash-image`](https://ailoot.ai/models/th/#m=google%2Fgemini-3.1-flash-image&route=Ultra&caller=google%2Fgemini-3.1-flash-image&fmt=chat)

Google /`google/gemini-3.1-flash-image`

### เริ่มต้น

Nano Banana 2 (Gemini 3.1 Flash Image) สร้างและแก้ภาพในบทสนทนา รองรับแหล่งข้อความและภาพ เอาต์พุต 0.5K–4K การจัดองค์ประกอบจากภาพอ้างอิง และการอิงผลค้นหาสำหรับฉากสินค้า อินโฟกราฟิก และงานภาพแบบวนปรับ

อินพุตที่รองรับ

ข้อความ

ผลลัพธ์

ข้อความ

### ใช้งานได้ใน Ailoot · อินพุตและเมธอด

**Ailoot Ultra · OpenAI Chat** `POST /v1/chat/completions`

ขาเข้า

`text`

ขาออก

`text`

รูปแบบเอาต์พุต

json หรือ SSE

| ฟิลด์ | ประเภท | ข้อกำหนด | ค่าและข้อจำกัด | ค่าเริ่มต้น |
| --- | --- | --- | --- | --- |
| ฟิลด์`model` | ประเภท`string` | ข้อกำหนดจำเป็น | ค่าและข้อจำกัด google/gemini-3.1-flash-image | ค่าเริ่มต้น— |
| ฟิลด์`messages` | ประเภท`message[]` | ข้อกำหนดจำเป็น | ค่าและข้อจำกัด จำนวนรายการขั้นต่ำ: 1 | ค่าเริ่มต้น— |
| ฟิลด์`messages[].role` | ประเภท`string` | ข้อกำหนดจำเป็น | ค่าและข้อจำกัด ตัวอย่าง: system, user, assistant, tool, function เงื่อนไข: บทบาทเหล่านี้แทนอย่างชัดเจนด้วยชนิดข้อมูลเพื่อความเข้ากันได้ในซอร์สโค้ด แต่ชุดบทบาทที่แน่นอนยังขึ้นกับแต่ละโมเดล ขึ้นอยู่กับโมเดล | ค่าเริ่มต้น— |
| ฟิลด์`messages[].content` | ประเภท`string\|content_part[]\|null` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด | ค่าเริ่มต้น— |
| ฟิลด์`messages[].tool_calls` | ประเภท`tool_call[]` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด | ค่าเริ่มต้น— |
| ฟิลด์`messages[].tool_call_id` | ประเภท`string` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ใช้เมื่อ: role=tool โดยใช้ ID ที่ส่งกลับจริง | ค่าเริ่มต้น— |
| ฟิลด์`messages[].name` | ประเภท`string` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด | ค่าเริ่มต้น— |
| ฟิลด์`messages[].reasoning_content` | ประเภท`string` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ใช้เมื่อ: ส่งเนื้อหาการใช้เหตุผลที่คืนจริงกลับในคำขอถัดไป เมื่อโมเดลนี้ใช้เนื้อหานั้น | ค่าเริ่มต้น— |
| ฟิลด์`messages[].reasoning_details` | ประเภท`object\|array` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ขึ้นอยู่กับโมเดล | ค่าเริ่มต้น— |
| ฟิลด์`max_tokens` | ประเภท`integer` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ขั้นต่ำ: 1 ขึ้นอยู่กับโมเดล | ค่าเริ่มต้น— |
| ฟิลด์`max_completion_tokens` | ประเภท`integer` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ขั้นต่ำ: 1 ขึ้นอยู่กับโมเดล | ค่าเริ่มต้น— |
| ฟิลด์`stream` | ประเภท`boolean` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด | ค่าเริ่มต้นfalse |
| ฟิลด์`stream_options.include_usage` | ประเภท`boolean` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ขึ้นอยู่กับโมเดล | ค่าเริ่มต้น— |
| ฟิลด์`temperature` | ประเภท`number` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ขึ้นอยู่กับโมเดล | ค่าเริ่มต้น— |
| ฟิลด์`top_p` | ประเภท`number` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ขึ้นอยู่กับโมเดล | ค่าเริ่มต้น— |
| ฟิลด์`stop` | ประเภท`string\|string[]` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ขึ้นอยู่กับโมเดล | ค่าเริ่มต้น— |
| ฟิลด์`tools` | ประเภท`function_tool[]` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ขึ้นอยู่กับโมเดล | ค่าเริ่มต้น— |
| ฟิลด์`tools[].type` | ประเภท`string` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด function ขึ้นอยู่กับโมเดล | ค่าเริ่มต้น— |
| ฟิลด์`tools[].function.name` | ประเภท`string` | ข้อกำหนดจำเป็น | ค่าและข้อจำกัด ใช้เมื่อ: มีเครื่องมือฟังก์ชันให้ใช้ | ค่าเริ่มต้น— |
| ฟิลด์`tools[].function.description` | ประเภท`string` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด | ค่าเริ่มต้น— |
| ฟิลด์`tools[].function.parameters` | ประเภท`JSON_schema` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด | ค่าเริ่มต้น— |
| ฟิลด์`tool_choice` | ประเภท`string\|object` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ขึ้นอยู่กับโมเดล | ค่าเริ่มต้น— |
| ฟิลด์`parallel_tool_calls` | ประเภท`boolean` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ขึ้นอยู่กับโมเดล | ค่าเริ่มต้น— |
| ฟิลด์`response_format` | ประเภท`object` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ขึ้นอยู่กับโมเดล | ค่าเริ่มต้น— |
| ฟิลด์`reasoning_effort` | ประเภท`string` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ขึ้นอยู่กับโมเดล | ค่าเริ่มต้น— |
| ฟิลด์`reasoning` | ประเภท`object` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ขึ้นอยู่กับโมเดล | ค่าเริ่มต้น— |
| ฟิลด์`service_tier` | ประเภท`string` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ขึ้นอยู่กับโมเดล | ค่าเริ่มต้น— |
| ฟิลด์`instructions` | ประเภท`string` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ฟิลด์เพื่อความเข้ากันได้ | ค่าเริ่มต้น— |
| ฟิลด์`functions` | ประเภท`function[]` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ขึ้นอยู่กับโมเดล | ค่าเริ่มต้น— |
| ฟิลด์`function_call` | ประเภท`string\|object` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ขึ้นอยู่กับโมเดล | ค่าเริ่มต้น— |
| ฟิลด์`prompt_cache_options` | ประเภท`object` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ขึ้นอยู่กับโมเดล | ค่าเริ่มต้น— |
| ฟิลด์`modalities` | ประเภท`string[]` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด text | ค่าเริ่มต้น— |
| ฟิลด์`provider` | ประเภท`object` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด เงื่อนไข: เส้นทางข้อความ Ultra นี้ปฏิเสธ provider.options | ค่าเริ่มต้น— |
| ฟิลด์`cache_control.ttl` | ประเภท`string` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด เงื่อนไข: ตำแหน่งแคชพรอมป์ต์จริงปฏิเสธ 1h | ค่าเริ่มต้น— |

ชุดผสมของสื่ออินพุต

**ข้อความ** · ข้อความ UTF8

`messages[].content`

พารามิเตอร์และวงจรการทำงานของเมธอด

| พารามิเตอร์ | ข้อกำหนด |
| --- | --- |
| พารามิเตอร์`content_type` | ข้อกำหนดapplication/json |
| พารามิเตอร์`required` | ข้อกำหนดmodel, messages |
| พารามิเตอร์`material_types` | ข้อกำหนดtext |
| พารามิเตอร์`messages` | ข้อกำหนดอาร์เรย์ข้อความที่มีโครงสร้าง role/content |
| พารามิเตอร์`file_material` | ข้อกำหนดแทรกเอกสาร UTF-8 จริงเป็นข้อความตามต้นฉบับ โดยไม่อนุมาน ID ไฟล์ |
| พารามิเตอร์`optional_controls` | ข้อกำหนดstream, temperature, top\_p, stop, max\_tokens, max\_completion\_tokens, reasoning, response\_format, tools, tool\_choice |
| พารามิเตอร์`control_scope` | ข้อกำหนดขึ้นกับโมเดล เครื่องมือฟังก์ชันของผู้ใช้ต่างจากเครื่องมือที่โฮสต์จัดให้ |
| พารามิเตอร์`output_modalities` | ข้อกำหนดtext |
| พารามิเตอร์`hosted_operations` | ข้อกำหนดfalse |
| พารามิเตอร์`multimodal_input_binding` | ข้อกำหนดnull |

วงจรการทำงาน: `synchronous_or_streamed`

ส่ง ID โมเดลที่ตรงทุกตัวพร้อม messages

ความยาวบริบทไม่ใช่เพดานผลลัพธ์

ไฟล์ข้อความให้ข้อความตามต้นฉบับได้ ส่วนข้อมูลเข้าภาพ/เสียง/ออบเจ็กต์ไฟล์ต้องมีการผูกที่ตรงตามจริง

### ราคา

ข้อมูลอัตราราคาไม่ได้เพิ่มตัวเลือกคำขอ พารามิเตอร์ที่รองรับระบุไว้สำหรับเมธอดที่เลือก

โหมดรวดเร็ว

อัตรามาตรฐาน เมื่อเลือกโหมดรวดเร็ว

โหมดยืดหยุ่น

อัตรามาตรฐาน เมื่อเลือกโหมด flex

ระดับการใช้เหตุผลสูงสุด

อัตรามาตรฐาน เมื่อใช้การปรับตามค่าเริ่มต้น (default) สำหรับระดับการใช้เหตุผลสูงสุด

ระดับการใช้เหตุผล · สูง

อัตรามาตรฐาน เมื่อระดับการใช้เหตุผลอยู่ในระดับสูง

ระดับการใช้เหตุผล · ต่ำสุด

อัตรามาตรฐาน เมื่อระดับการใช้เหตุผลอยู่ในระดับต่ำสุด

การคิดราคาแคชแบบระบุชัด

ไม่ได้เปิดใช้ เมื่อร้องขอแคชแบบระบุชัด

#### อัตราค่าบริการ Ailoot

#### ราคาตามการตั้งค่า

เทียบค่าบริการแต่ละรายการกับเงื่อนไขที่แสดง เลือกใช้อัตราเดียวสำหรับแต่ละชุดการตั้งค่าที่เป็นตัวเลือกทดแทนกัน

| การตั้งค่า | ตารางอัตราค่าบริการ | โทเค็นบริบท มากกว่า | โทเค็นบริบท ไม่เกินและรวมค่า | ค่าบริการ |
| --- | --- | --- | --- | --- |
| การตั้งค่าอัตราราคาพื้นฐานของโทเคน | ตารางอัตราค่าบริการอัตราพื้นฐาน | โทเค็นบริบท มากกว่า— | โทเค็นบริบท ไม่เกินและรวมค่าไม่มีขีดจำกัดสูงสุด | ค่าบริการ ขาเข้า · โทเค็นอินพุต **$0.001** / 1K โทเค็น ขาออก · โทเค็นเอาต์พุต **$0.006** / 1K โทเค็น ขาเข้า · การอ่านแคช **—** / 1K โทเค็น ขาเข้า · การเขียนแคช **—** / 1K โทเค็น ขาเข้า · การเขียนแคช, 1 ชั่วโมง **—** / 1K โทเค็น ขาออก · โทเคนภาพขาออก **$0.12** / 1K โทเค็นภาพ |
| การตั้งค่าระดับความยาวคำขอ 1 | ตารางอัตราค่าบริการ— | โทเค็นบริบท มากกว่า0 | โทเค็นบริบท ไม่เกินและรวมค่าไม่มีขีดจำกัดสูงสุด | ค่าบริการ ขาเข้า · โทเค็นอินพุต **$0.001** / 1K โทเค็น ขาออก · โทเค็นเอาต์พุต **$0.006** / 1K โทเค็น ขาเข้า · การอ่านแคช **—** / 1K โทเค็น ขาเข้า · การเขียนแคช **—** / 1K โทเค็น ขาเข้า · การเขียนแคช, 1 ชั่วโมง **—** / 1K โทเค็น |

#### รายละเอียดอัตราอ้างอิง

ตารางอัตราอ้างอิงระดับโมเดลไม่เปลี่ยนเมธอดที่เลือก ยอดประมาณการ หรือค่าบริการ การคิดค่าบริการจริงใช้อัตราของเมธอด Ailoot ที่เลือก

Google: Nano Banana 2 (Gemini 3.1 Flash Image)

#### ราคาตามการตั้งค่า

| การตั้งค่า | เงื่อนไขคิดค่าบริการ | ค่าบริการ |
| --- | --- | --- |
| การตั้งค่าGoogle: Nano Banana 2 (Gemini 3.1 Flash Image) · การตั้งค่าเริ่มต้น | เงื่อนไขคิดค่าบริการการตั้งค่าเริ่มต้น | ค่าบริการ ขาเข้า · โทเค็นอินพุต **US$0.001** / 1K โทเค็น ขาออก · โทเค็นเอาต์พุต **US$0.006** / 1K โทเค็น ขาออก · ภาพขาออก **US$0.12** / 1K โทเค็น ขาออก · การค้นหาบนเว็บ **US$0.028** ต่อการค้นหา |

Ailoot กันยอดเงินประมาณการไว้ก่อนส่งคำขอ หลังได้ผลลัพธ์ จะคิดค่าบริการสุดท้ายตามการใช้งานที่วัดได้ การคิดค่าบริการแบบสตรีมใช้บันทึกการใช้งานสุดท้าย [วิธีกันยอดเงินและคิดค่าบริการสุดท้าย →](https://ailoot.ai/docs/th/billing/reserve/)

### ตัวอย่างคำขอ

#### Ailoot Ultra · OpenAI Chat

curlPython SDKสตรีมด้วย Python

```bash
set -eu
: "${AILOOT_API_KEY:?Set your Ailoot API key}"
python3 - <<'PY_REQUEST'
import json,os
from pathlib import Path
p=json.loads('{"model": "google/gemini-3.1-flash-image", "messages": [{"role": "user", "content": "Explain the difference between an observation and a hypothesis in three sentences."}]}')

Path("request.json").write_text(json.dumps(p,ensure_ascii=False))
PY_REQUEST
curl --fail-with-body --silent --show-error https://api.ailoot.ai/v1/chat/completions \
  -H "Authorization: Bearer $AILOOT_API_KEY" -H 'Content-Type: application/json' \
  --data-binary @request.json -D response-headers.txt -o result.json
python3 - <<'PY_RESULT'
import json
from pathlib import Path
r=json.loads(Path("result.json").read_text())
for x in r.get("choices",[]):
    if x.get("message",{}).get("content"): print(x["message"]["content"])
PY_RESULT
```

```python
from openai import OpenAI
import os

if not os.environ.get("AILOOT_API_KEY", "").strip(): raise SystemExit("Set AILOOT_API_KEY before making a request")
client=OpenAI(base_url="https://api.ailoot.ai/v1",api_key=os.environ["AILOOT_API_KEY"],max_retries=0)
result=client.chat.completions.create(model='google/gemini-3.1-flash-image',messages=[{"role":"user","content":"Explain observations and hypotheses in three sentences."}])
import base64, json
from pathlib import Path

def save_result(data, stem="result"):
    # Keep every field, including usage, IDs, reasoning and tool requests.
    Path(stem + ".json").write_text(json.dumps(data, ensure_ascii=False, indent=2), encoding="utf-8")
    print(json.dumps(data, ensure_ascii=False, indent=2))
    def save_blob(encoded, suffix, label):
        raw = base64.b64decode(encoded, altchars=b"-_", validate=True)
        ext = "png" if raw.startswith(b"\x89PNG\r\n\x1a\n") else "jpg" if raw.startswith(b"\xff\xd8") else "webp" if raw[:4] == b"RIFF" and raw[8:12] == b"WEBP" else suffix
        file = Path(stem + "-" + label + "." + ext)
        file.write_bytes(raw)
        print("Saved", file)
    for index, block in enumerate(data.get("content") or []):
        print("Content", index, json.dumps(block, ensure_ascii=False))
    for choice in data.get("choices") or []:
        print("Choice", choice.get("index"), json.dumps(choice.get("message", choice.get("delta", {})), ensure_ascii=False))
    for index, item in enumerate(data.get("output") or []):
        print("Output", index, json.dumps(item, ensure_ascii=False))
        if item.get("type") == "image_generation_call" and item.get("result"):
            save_blob(item["result"], item.get("output_format") or "bin", "output-" + str(index))
    for ci, candidate in enumerate(data.get("candidates") or []):
        for pi, part in enumerate((candidate.get("content") or {}).get("parts") or []):
            print("Candidate/part", ci, pi, json.dumps(part, ensure_ascii=False))
            blob = part.get("inlineData") or part.get("inline_data")
            if blob and blob.get("data"):
                mime = blob.get("mimeType") or blob.get("mime_type")
                suffix = {"image/png":"png", "image/jpeg":"jpg", "image/webp":"webp", "audio/wav":"wav", "audio/mpeg":"mp3", "video/mp4":"mp4"}.get(mime, "bin")
                save_blob(blob["data"], suffix, "candidate-" + str(ci) + "-part-" + str(pi))

save_result(result.to_dict(mode="json"))
```

```python
from openai import OpenAI
import os
from pathlib import Path

if not os.environ.get("AILOOT_API_KEY", "").strip(): raise SystemExit("Set AILOOT_API_KEY before making a request")
client=OpenAI(base_url="https://api.ailoot.ai/v1",api_key=os.environ["AILOOT_API_KEY"],max_retries=0)
import base64, json
from pathlib import Path

def save_result(data, stem="result"):
    # Keep every field, including usage, IDs, reasoning and tool requests.
    Path(stem + ".json").write_text(json.dumps(data, ensure_ascii=False, indent=2), encoding="utf-8")
    print(json.dumps(data, ensure_ascii=False, indent=2))
    def save_blob(encoded, suffix, label):
        raw = base64.b64decode(encoded, altchars=b"-_", validate=True)
        ext = "png" if raw.startswith(b"\x89PNG\r\n\x1a\n") else "jpg" if raw.startswith(b"\xff\xd8") else "webp" if raw[:4] == b"RIFF" and raw[8:12] == b"WEBP" else suffix
        file = Path(stem + "-" + label + "." + ext)
        file.write_bytes(raw)
        print("Saved", file)
    for index, block in enumerate(data.get("content") or []):
        print("Content", index, json.dumps(block, ensure_ascii=False))
    for choice in data.get("choices") or []:
        print("Choice", choice.get("index"), json.dumps(choice.get("message", choice.get("delta", {})), ensure_ascii=False))
    for index, item in enumerate(data.get("output") or []):
        print("Output", index, json.dumps(item, ensure_ascii=False))
        if item.get("type") == "image_generation_call" and item.get("result"):
            save_blob(item["result"], item.get("output_format") or "bin", "output-" + str(index))
    for ci, candidate in enumerate(data.get("candidates") or []):
        for pi, part in enumerate((candidate.get("content") or {}).get("parts") or []):
            print("Candidate/part", ci, pi, json.dumps(part, ensure_ascii=False))
            blob = part.get("inlineData") or part.get("inline_data")
            if blob and blob.get("data"):
                mime = blob.get("mimeType") or blob.get("mime_type")
                suffix = {"image/png":"png", "image/jpeg":"jpg", "image/webp":"webp", "audio/wav":"wav", "audio/mpeg":"mp3", "video/mp4":"mp4"}.get(mime, "bin")
                save_blob(blob["data"], suffix, "candidate-" + str(ci) + "-part-" + str(pi))

with client.chat.completions.stream(model='google/gemini-3.1-flash-image',messages=[{"role":"user","content":"Explain observations and hypotheses in three sentences."}]) as stream:
    with Path("stream-events.jsonl").open("w",encoding="utf-8") as log:
        for event in stream:
            payload=event.to_dict(mode="json")
            log.write(json.dumps(payload,ensure_ascii=False)+"\n"); log.flush()
            print(json.dumps(payload,ensure_ascii=False))
    final=stream.get_final_completion()
    save_result(final.to_dict(mode="json"),"stream-result")
```

### รับและบันทึกผลลัพธ์

#### Ailoot Ultra · OpenAI Chat

json หรือ SSE

##### เก็บผลลัพธ์ที่เสร็จสมบูรณ์ทั้งหมด

เก็บทุกการตอบกลับ ไฟล์ และส่วนเนื้อหาที่ส่งกลับมาอย่างครบถ้วน

เก็บทุกตัวเลือกพร้อมเนื้อหา/การเรียกเครื่องมือ/การใช้เหตุผล ใน SSE ให้ประกอบส่วนเพิ่มตามดัชนีตัวเลือก/เครื่องมือ และเก็บเหตุผลสิ้นสุดกับข้อมูลการใช้งานสุดท้าย

##### เมื่อต้องตรวจสอบการตอบกลับต้นฉบับ

เก็บ ID และส่วนหัวของคำขอ/คำตอบ ไม่มี URL ทั่วไปสำหรับดึงงานข้อความให้ใช้

ฟิลด์การตอบกลับ

| ฟิลด์ | ประเภท |
| --- | --- |
| ฟิลด์`choices[].index` | ประเภทinteger |
| ฟิลด์`choices[].message.content` | ประเภทstring\|null |
| ฟิลด์`choices[].message.tool_calls` | ประเภทtool\_call\[\] |
| ฟิลด์`choices[].message.reasoning_content` | ประเภทstring |
| ฟิลด์`choices[].message.reasoning_details` | ประเภทobject\|array |
| ฟิลด์`choices[].finish_reason` | ประเภทstring\|null |
| ฟิลด์`usage` | ประเภทobject |

ข้อผิดพลาดและขั้นตอนถัดไป

| การตอบกลับ | เงื่อนไข | ขั้นตอนถัดไป |
| --- | --- | --- |
| การตอบกลับ400 · `invalid_request_error` | เงื่อนไขฟิลด์จำเป็น รูปแบบการแทนข้อมูล หรือค่าพารามิเตอร์ไม่ถูกต้อง | ขั้นตอนถัดไปแก้ฟิลด์ที่ระบุก่อนส่งคำขอสร้างครั้งใหม่ |

### ชื่ออื่น

#### ชื่ออื่นของโมเดล

<strong>Ailoot</strong> [`gemini-3.1-flash-image`](https://ailoot.ai/models/th/#m=google%2Fgemini-3.1-flash-image&route=Core&caller=gemini-3.1-flash-image)
**Ailoot Ultra** [`google/gemini-3.1-flash-image`](https://ailoot.ai/models/th/#m=google%2Fgemini-3.1-flash-image&route=Ultra&caller=google%2Fgemini-3.1-flash-image&fmt=chat)

#### ชื่อพาธเมธอดอื่น

`/v1/images`

#### ID ที่เกี่ยวข้องสำหรับเรียกใช้โมเดล

[`google/gemini-3.1-flash-image`](https://ailoot.ai/models/th/#m=google%2Fgemini-3.1-flash-image&route=Ultra&caller=google%2Fgemini-3.1-flash-image&fmt=chat), [`gemini-3.1-flash-image`](https://ailoot.ai/models/th/#m=google%2Fgemini-3.1-flash-image&route=Core&caller=gemini-3.1-flash-image)

**Ailoot Ultra · รูปภาพ** `POST /v1/images/generations` `google/gemini-3.1-flash-image`

[`google/gemini-3.1-flash-image`](https://ailoot.ai/models/th/#m=google%2Fgemini-3.1-flash-image&route=Ultra&caller=google%2Fgemini-3.1-flash-image&fmt=images)

Google /`google/gemini-3.1-flash-image`

### เริ่มต้น

Nano Banana 2 (Gemini 3.1 Flash Image) สร้างและแก้ภาพในบทสนทนา รองรับแหล่งข้อความและภาพ เอาต์พุต 0.5K–4K การจัดองค์ประกอบจากภาพอ้างอิง และการอิงผลค้นหาสำหรับฉากสินค้า อินโฟกราฟิก และงานภาพแบบวนปรับ

อินพุตที่รองรับ

ข้อความ · รูปภาพ

ผลลัพธ์

รูปภาพ

### ใช้งานได้ใน Ailoot · อินพุตและเมธอด

**Ailoot Ultra · รูปภาพ** `POST /v1/images/generations`

ขาเข้า

`text`, `image`

ขาออก

`image`

| ฟิลด์ | ประเภท | ข้อกำหนด | ค่าและข้อจำกัด | ค่าเริ่มต้น |
| --- | --- | --- | --- | --- |
| ฟิลด์`model` | ประเภท`string` | ข้อกำหนดจำเป็น | ค่าและข้อจำกัด google/gemini-3.1-flash-image | ค่าเริ่มต้น— |
| ฟิลด์`prompt` | ประเภท`string` | ข้อกำหนดจำเป็น | ค่าและข้อจำกัด ความยาวขั้นต่ำ: 1 | ค่าเริ่มต้น— |
| ฟิลด์`resolution` | ประเภท`string` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด 512, 1K, 2K, 4K | ค่าเริ่มต้น— |
| ฟิลด์`aspect_ratio` | ประเภท`string` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด 1:1, 1:4, 1:8, 2:3, 3:2, 3:4, 4:1, 4:3, 4:5, 5:4, 8:1, 9:16, 16:9, 21:9 | ค่าเริ่มต้น— |
| ฟิลด์`n` | ประเภท`integer` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด ขั้นต่ำ: 1 สูงสุด: 1 | ค่าเริ่มต้น— |
| ฟิลด์`input_references` | ประเภท`array` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด จำนวนรายการขั้นต่ำ: 0 จำนวนรายการสูงสุด: 14 | ค่าเริ่มต้น— |
| ฟิลด์`provider` | ประเภท`object` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด | ค่าเริ่มต้น— |

พารามิเตอร์และวงจรการทำงานของเมธอด

| พารามิเตอร์ | ข้อกำหนด |
| --- | --- |
| พารามิเตอร์`content_type` | ข้อกำหนดapplication/json |
| พารามิเตอร์`required` | ข้อกำหนดmodel, prompt |
| พารามิเตอร์`material_types` | ข้อกำหนดtext, image |

วงจรการทำงาน: `synchronous_result_then_owned_library`

`GET /v1/media/tasks/{task_id}` · ค่า task\_id ที่ส่งกลับมาจริง หรือระเบียนในคลังสื่อ

`GET /v1/media/assets/{asset_id}/content`

`GET /v1/media/assets`

`GET /v1/media/assets/{asset_id}`

### ราคา

##### วิธีคำนวณค่าบริการสุดท้าย

อัตราที่แสดงใช้ประมาณการค่าใช้จ่ายก่อนการสร้างผลลัพธ์ ยอดเรียกเก็บสุดท้ายคำนวณจากค่าใช้จ่ายที่บันทึกไว้สำหรับการสร้างผลลัพธ์ครั้งเดิม ระยะเวลาของผลลัพธ์ที่วัดได้และปริมาณที่คาดการณ์ไว้ไม่ใช่ปริมาณสุดท้ายที่ใช้คิดค่าบริการ

ข้อมูลอัตราราคาไม่ได้เพิ่มตัวเลือกคำขอ พารามิเตอร์ที่รองรับระบุไว้สำหรับเมธอดที่เลือก

โหมดรวดเร็ว

ไม่ได้ระบุ เมื่อเลือกโหมดรวดเร็ว

โหมดยืดหยุ่น

ไม่ได้ระบุ เมื่อเลือกโหมด flex

ระดับการใช้เหตุผลสูงสุด

ไม่ได้ระบุ เมื่อใช้การปรับตามค่าเริ่มต้น (default) สำหรับระดับการใช้เหตุผลสูงสุด

#### อัตราประมาณการเพื่อเปรียบเทียบ

#### ราคาตามการตั้งค่า

เทียบค่าบริการแต่ละรายการกับเงื่อนไขที่แสดง เลือกใช้อัตราเดียวสำหรับแต่ละชุดการตั้งค่าที่เป็นตัวเลือกทดแทนกัน

| การตั้งค่า | ตารางอัตราค่าบริการ | ปริมาณคาดการณ์ | ค่าบริการ |
| --- | --- | --- | --- |
| การตั้งค่าอัตราค่าบริการโทเคนพื้นฐาน | ตารางอัตราค่าบริการอัตราพื้นฐาน | ปริมาณคาดการณ์— | ค่าบริการ ขาเข้า · โทเค็นอินพุต · ประมาณการเพื่อเปรียบเทียบเท่านั้น **—** / 1K โทเค็น ขาออก · โทเค็นเอาต์พุต · ประมาณการเพื่อเปรียบเทียบเท่านั้น **—** / 1K โทเค็น ขาเข้า · การอ่านแคช · ประมาณการเพื่อเปรียบเทียบเท่านั้น **—** / 1K โทเค็น ขาเข้า · การเขียนแคช · ประมาณการเพื่อเปรียบเทียบเท่านั้น **—** / 1K โทเค็น ขาเข้า · การเขียนแคช, 1 ชั่วโมง · ประมาณการเพื่อเปรียบเทียบเท่านั้น **—** / 1K โทเค็น |
| การตั้งค่าต้นทุนการสร้างโดยประมาณ | ตารางอัตราค่าบริการ— | ปริมาณคาดการณ์ค่าประมาณสำหรับการสร้างหนึ่งครั้ง | ค่าบริการ ขาออก · ค่าใช้จ่ายในการสร้างโดยประมาณ · ประมาณการเพื่อเปรียบเทียบเท่านั้น **$0.49152** ประมาณการก่อนสร้าง ค่าประมาณนี้ไม่ใช่ค่าใช้จ่ายเพิ่มเติมหรืออัตราคงที่สำหรับการสร้างผลลัพธ์ที่เสร็จสมบูรณ์แล้ว |

Ailoot กันยอดเงินประมาณการไว้ก่อนส่งคำขอ หลังได้ผลลัพธ์ จะคิดค่าบริการสุดท้ายตามการใช้งานที่วัดได้ การคิดค่าบริการแบบสตรีมใช้บันทึกการใช้งานสุดท้าย [วิธีกันยอดเงินและคิดค่าบริการสุดท้าย →](https://ailoot.ai/docs/th/billing/reserve/)

### ตัวอย่างคำขอ

#### Ailoot Ultra · รูปภาพ

curl

```bash
set -eu
: "${AILOOT_API_KEY:?Set your Ailoot API key}"
export AILOOT_API_KEY
python3 - <<'PY_REQUEST'
import json,os
from pathlib import Path
p={'model': 'google/gemini-3.1-flash-image', 'prompt': 'a red panda astronaut floating in space, studio lighting'}

Path("request.json").write_text(json.dumps(p,ensure_ascii=False))
PY_REQUEST
curl --fail-with-body --silent --show-error https://api.ailoot.ai/v1/images/generations \
  -H "Authorization: Bearer $AILOOT_API_KEY" -H 'Content-Type: application/json' \
  --data-binary @request.json -D response-headers.txt -o result.json
python3 - <<'PY_RESULT'
import base64, json, os, subprocess
from pathlib import Path
from urllib.parse import urlsplit, urljoin

def save_images(items):
    if not items: raise SystemExit("No completed images; retain the full response")
    for index, item in enumerate(items):
        encoded=item.get("b64_json")
        uri=item.get("url", "")
        if not encoded and uri.startswith("data:image/"):
            header, separator, encoded=uri.partition(",")
            if not separator or ";base64" not in header: raise SystemExit("Unsupported image data URI")
        if encoded:
            raw=base64.b64decode(encoded,validate=True)
        elif uri:
            uri=urljoin("https://api.ailoot.ai",uri)
            parsed=urlsplit(uri)
            if parsed.scheme!="https" or not parsed.netloc or parsed.username or parsed.password:
                raise SystemExit("Invalid returned image URL")
            owned=parsed.netloc=="api.ailoot.ai" and parsed.path.startswith("/v1/media/assets/") and parsed.path.endswith("/content")
            args=["curl","--fail-with-body","--silent","--show-error",uri]
            if owned: args += ["-H","Authorization: Bearer "+os.environ["AILOOT_API_KEY"]]
            temporary=Path(f"image-{index}.bin")
            subprocess.run(args+["-o",str(temporary)],check=True)
            raw=temporary.read_bytes()
            temporary.unlink()
        else: raise SystemExit("Image has neither bytes nor URL")
        if not raw: raise SystemExit("Empty image result")
        ext="png" if raw.startswith(b"\x89PNG") else "jpg" if raw.startswith(b"\xff\xd8") else "webp" if raw[:4]==b"RIFF" and raw[8:12]==b"WEBP" else "svg" if raw.lstrip().startswith((b"<svg",b"<?xml")) else "bin"
        Path(f"image-{index}.{ext}").write_bytes(raw)
    print("Every returned image saved; complete response metadata retained")
save_images(json.loads(Path("result.json").read_text())["data"])
PY_RESULT
```

### รับและบันทึกผลลัพธ์

#### Ailoot Ultra · รูปภาพ

ดาวน์โหลดภาพที่ส่งกลับมาทุกภาพ หรือบันทึกเนื้อหา Base64 ของภาพนั้น

- `GET /v1/media/tasks/{task_id}`
- `GET /v1/media/assets/{asset_id}/content`
- `GET /v1/media/assets`
- `GET /v1/media/assets/{asset_id}`

การอ่านเนื้อหาแบบอื่น

อ่านไฟล์สื่อที่มีอยู่และเป็นของคุณ

```bash
set -eu
: "${AILOOT_API_KEY:?Set your Ailoot API key}"
curl --fail-with-body --silent --show-error https://api.ailoot.ai/v1/media/assets \
  -H "Authorization: Bearer $AILOOT_API_KEY" -o owned-assets.json
# Preserve every returned asset and follow its exact signed content URL. Do not construct a signed token.
```

##### เก็บผลลัพธ์ที่เสร็จสมบูรณ์ทั้งหมด

บันทึกภาพที่สร้างเสร็จทุกภาพ โดยดึงภาพจากทุก URL ที่ส่งกลับมา หรือถอดรหัสเนื้อหา Base64

เก็บการตอบกลับและส่วนหัวให้ครบถ้วน เก็บผลลัพธ์จริงทุกรายการ ตัวระบุที่ส่งกลับมาแต่เดิม และฟิลด์ข้อมูลการใช้งานทั้งหมด กู้คืนการดำเนินการเดิมโดยไม่ส่งคำขอสร้างซ้ำ

##### เมื่อต้องตรวจสอบการตอบกลับต้นฉบับ

เก็บ X-Client-Request-ID ที่ส่งกลับมาไว้เพื่อกระทบยอด อ่านเฉพาะค่า task\_id/asset\_id ที่ส่งกลับมาจริง หรืออ่านจากคลังสื่อที่เป็นของตนเอง ห้ามสร้าง URL ของงานจาก ID การดำเนินการ และห้ามส่งคำขอสร้างซ้ำเด็ดขาด

ฟิลด์การตอบกลับ

| ฟิลด์ | ประเภท |
| --- | --- |
| ฟิลด์`created` | ประเภท |
| ฟิลด์`data[].url` | ประเภท |
| ฟิลด์`data[].b64_json` | ประเภท |
| ฟิลด์`usage` | ประเภท |

### ชื่ออื่น

#### ชื่ออื่นของโมเดล

<strong>Ailoot</strong> [`gemini-3.1-flash-image`](https://ailoot.ai/models/th/#m=google%2Fgemini-3.1-flash-image&route=Core&caller=gemini-3.1-flash-image&fmt=images)
**Ailoot Ultra** [`google/gemini-3.1-flash-image`](https://ailoot.ai/models/th/#m=google%2Fgemini-3.1-flash-image&route=Ultra&caller=google%2Fgemini-3.1-flash-image&fmt=images)

#### ชื่อพาธเมธอดอื่น

`/v1/images`

#### ID ที่เกี่ยวข้องสำหรับเรียกใช้โมเดล

[`google/gemini-3.1-flash-image`](https://ailoot.ai/models/th/#m=google%2Fgemini-3.1-flash-image&route=Ultra&caller=google%2Fgemini-3.1-flash-image&fmt=images), [`gemini-3.1-flash-image`](https://ailoot.ai/models/th/#m=google%2Fgemini-3.1-flash-image&route=Core&caller=gemini-3.1-flash-image&fmt=images)

**Ailoot Ultra · Anthropic Messages** `POST /v1/messages` `google/gemini-3.1-flash-image`

[`google/gemini-3.1-flash-image`](https://ailoot.ai/models/th/#m=google%2Fgemini-3.1-flash-image&route=Ultra&caller=google%2Fgemini-3.1-flash-image&fmt=messages)

Google /`google/gemini-3.1-flash-image`

### เริ่มต้น

Nano Banana 2 (Gemini 3.1 Flash Image) สร้างและแก้ภาพในบทสนทนา รองรับแหล่งข้อความและภาพ เอาต์พุต 0.5K–4K การจัดองค์ประกอบจากภาพอ้างอิง และการอิงผลค้นหาสำหรับฉากสินค้า อินโฟกราฟิก และงานภาพแบบวนปรับ

อินพุตที่รองรับ

ข้อความ

ผลลัพธ์

json · sse

### ใช้งานได้ใน Ailoot · อินพุตและเมธอด

**Ailoot Ultra · Anthropic Messages** `POST /v1/messages`

ขาเข้า

`text`

ขาออก

`json`, `sse`

รูปแบบเอาต์พุต

JSON หรือ SSE

| ฟิลด์ | ประเภท | ข้อกำหนด | ค่าและข้อจำกัด | ค่าเริ่มต้น |
| --- | --- | --- | --- | --- |
| ฟิลด์`model` | ประเภท`string` | ข้อกำหนดจำเป็น | ค่าและข้อจำกัด google/gemini-3.1-flash-image | ค่าเริ่มต้น— |
| ฟิลด์`messages` | ประเภท`message[]` | ข้อกำหนดจำเป็น | ค่าและข้อจำกัด | ค่าเริ่มต้น— |
| ฟิลด์`messages[].role` | ประเภท`string` | ข้อกำหนดจำเป็น | ค่าและข้อจำกัด user, assistant | ค่าเริ่มต้น— |
| ฟิลด์`messages[].content` | ประเภท`string` | ข้อกำหนดจำเป็น | ค่าและข้อจำกัด | ค่าเริ่มต้น— |
| ฟิลด์`max_tokens` | ประเภท`integer` | ข้อกำหนดจำเป็น | ค่าและข้อจำกัด | ค่าเริ่มต้น— |
| ฟิลด์`stream` | ประเภท`boolean` | ข้อกำหนดไม่บังคับ | ค่าและข้อจำกัด | ค่าเริ่มต้นfalse |

ชุดผสมของสื่ออินพุต

**ข้อความ** · ข้อความ UTF-8

`สตริง messages[].content`

พารามิเตอร์และวงจรการทำงานของเมธอด

| พารามิเตอร์ | ข้อกำหนด |
| --- | --- |
| พารามิเตอร์`content_type` | ข้อกำหนดapplication/json |
| พารามิเตอร์`required` | ข้อกำหนดmodel, messages, max\_tokens |
| พารามิเตอร์`optional_controls` | ข้อกำหนดstream |
| พารามิเตอร์`material_types` | ข้อกำหนดtext |
| พารามิเตอร์`text_file_material` | ข้อกำหนดอ่านเอกสาร UTF-8 จริง แล้วใส่ข้อความใน input หรือสตริงเนื้อหาข้อความที่ระบุ |

วงจรการทำงาน: `synchronous_or_streamed`

### ราคา

ข้อมูลอัตราราคาไม่ได้เพิ่มตัวเลือกคำขอ พารามิเตอร์ที่รองรับระบุไว้สำหรับเมธอดที่เลือก

โหมดรวดเร็ว

อัตรามาตรฐาน เมื่อเลือกโหมดรวดเร็ว

โหมดยืดหยุ่น

อัตรามาตรฐาน เมื่อเลือกโหมด flex

ระดับการใช้เหตุผลสูงสุด

อัตรามาตรฐาน เมื่อใช้การปรับตามค่าเริ่มต้น (default) สำหรับระดับการใช้เหตุผลสูงสุด

ระดับการใช้เหตุผล · สูง

อัตรามาตรฐาน เมื่อระดับการใช้เหตุผลอยู่ในระดับสูง

ระดับการใช้เหตุผล · ต่ำสุด

อัตรามาตรฐาน เมื่อระดับการใช้เหตุผลอยู่ในระดับต่ำสุด

การคิดราคาแคชแบบระบุชัด

ไม่ได้เปิดใช้ เมื่อร้องขอแคชแบบระบุชัด

#### อัตราค่าบริการ Ailoot

#### ราคาตามการตั้งค่า

เทียบค่าบริการแต่ละรายการกับเงื่อนไขที่แสดง เลือกใช้อัตราเดียวสำหรับแต่ละชุดการตั้งค่าที่เป็นตัวเลือกทดแทนกัน

| การตั้งค่า | ตารางอัตราค่าบริการ | โทเค็นบริบท มากกว่า | โทเค็นบริบท ไม่เกินและรวมค่า | ค่าบริการ |
| --- | --- | --- | --- | --- |
| การตั้งค่าอัตราราคาพื้นฐานของโทเคน | ตารางอัตราค่าบริการอัตราพื้นฐาน | โทเค็นบริบท มากกว่า— | โทเค็นบริบท ไม่เกินและรวมค่าไม่มีขีดจำกัดสูงสุด | ค่าบริการ ขาเข้า · โทเค็นอินพุต **$0.001** / 1K โทเค็น ขาออก · โทเค็นเอาต์พุต **$0.006** / 1K โทเค็น ขาเข้า · การอ่านแคช **—** / 1K โทเค็น ขาเข้า · การเขียนแคช **—** / 1K โทเค็น ขาเข้า · การเขียนแคช, 1 ชั่วโมง **—** / 1K โทเค็น ขาออก · โทเคนภาพขาออก **$0.12** / 1K โทเค็นภาพ |
| การตั้งค่าระดับความยาวคำขอ 1 | ตารางอัตราค่าบริการ— | โทเค็นบริบท มากกว่า0 | โทเค็นบริบท ไม่เกินและรวมค่าไม่มีขีดจำกัดสูงสุด | ค่าบริการ ขาเข้า · โทเค็นอินพุต **$0.001** / 1K โทเค็น ขาออก · โทเค็นเอาต์พุต **$0.006** / 1K โทเค็น ขาเข้า · การอ่านแคช **—** / 1K โทเค็น ขาเข้า · การเขียนแคช **—** / 1K โทเค็น ขาเข้า · การเขียนแคช, 1 ชั่วโมง **—** / 1K โทเค็น |

Ailoot กันยอดเงินประมาณการไว้ก่อนส่งคำขอ หลังได้ผลลัพธ์ จะคิดค่าบริการสุดท้ายตามการใช้งานที่วัดได้ การคิดค่าบริการแบบสตรีมใช้บันทึกการใช้งานสุดท้าย [วิธีกันยอดเงินและคิดค่าบริการสุดท้าย →](https://ailoot.ai/docs/th/billing/reserve/)

### ตัวอย่างคำขอ

#### Ailoot Ultra · Anthropic Messages

เนื้อหาคำขอ JSON ขั้นต่ำที่ครบถ้วนcurl · ใช้เอกสาร UTF-8 ของคุณPython · บันทึกผลลัพธ์ให้ครบถ้วน

```json
{
  "model": "google/gemini-3.1-flash-image",
  "max_tokens": 128,
  "messages": [
    {
      "role": "user",
      "content": "Summarize the incident report."
    }
  ],
  "stream": false
}
```

```bash
set -eu
: "${AILOOT_API_KEY:?Set your Ailoot API key}"
: "${AILOOT_TEXT_FILE:?Set your actual UTF-8 document}"
export AILOOT_TEXT_FILE
python3 - <<'PY_REQUEST'
import json, os
from pathlib import Path

source_file = Path(os.environ['AILOOT_TEXT_FILE'])
if not source_file.is_file():
    raise SystemExit('Set AILOOT_TEXT_FILE to your actual UTF-8 document')
text = source_file.read_text(encoding='utf-8')
if not text.strip():
    raise SystemExit('Choose a document containing text')
payload = {'model': 'google/gemini-3.1-flash-image', 'max_tokens': 128, 'messages': [{'role': 'user', 'content': 'Summarize the incident report.'}]}
payload['messages'][0]['content'] = 'Summarize this material and quote supporting source passages.\n\n' + text
Path('request.json').write_text(json.dumps(payload, ensure_ascii=False), encoding='utf-8')
PY_REQUEST
curl --fail-with-body --silent --show-error https://api.ailoot.ai/v1/messages \
  -H "x-api-key: $AILOOT_API_KEY" -H 'anthropic-version: 2023-06-01' -H 'Content-Type: application/json' \
  --data-binary @request.json -D response-headers.txt -o result.json
python3 - <<'PY_RESULT'
import json
from pathlib import Path

result = json.loads(Path('result.json').read_text(encoding='utf-8'))
print(json.dumps(result, ensure_ascii=False, indent=2))
PY_RESULT
```

```python
import json, os
from pathlib import Path

source_file = Path(os.environ['AILOOT_TEXT_FILE'])
if not source_file.is_file():
    raise SystemExit('Set AILOOT_TEXT_FILE to your actual UTF-8 document')
text = source_file.read_text(encoding='utf-8')
if not text.strip():
    raise SystemExit('Choose a document containing text')
payload = {'model': 'google/gemini-3.1-flash-image', 'max_tokens': 128, 'messages': [{'role': 'user', 'content': 'Summarize the incident report.'}]}
payload['messages'][0]['content'] = 'Summarize this material and quote supporting source passages.\n\n' + text
from urllib.request import Request, urlopen
from urllib.error import HTTPError

api_key = os.environ['AILOOT_API_KEY']
if not api_key.strip():
    raise SystemExit('Set AILOOT_API_KEY before making a request')
headers = {'x-api-key': 'PLACEHOLDER_KEY', 'anthropic-version': '2023-06-01', 'Content-Type': 'application/json'}
headers['x-api-key'] = api_key
request = Request('https://api.ailoot.ai/v1/messages', data=json.dumps(payload, ensure_ascii=False).encode('utf-8'), headers=headers, method='POST')
try:
    with urlopen(request, timeout=120) as response:
        raw = response.read()
        Path('response-headers.txt').write_text(str(response.headers), encoding='utf-8')
except HTTPError as error:
    Path('result.json').write_bytes(error.read())
    Path('response-headers.txt').write_text(str(error.headers), encoding='utf-8')
    raise
Path('result.json').write_bytes(raw)
import json
from pathlib import Path

result = json.loads(Path('result.json').read_text(encoding='utf-8'))
print(json.dumps(result, ensure_ascii=False, indent=2))
```

### รับและบันทึกผลลัพธ์

#### Ailoot Ultra · Anthropic Messages

JSON หรือ SSE

##### เก็บผลลัพธ์ที่เสร็จสมบูรณ์ทั้งหมด

เก็บทุกการตอบกลับ ไฟล์ และส่วนเนื้อหาที่ส่งกลับมาอย่างครบถ้วน

เก็บทุกบล็อกเนื้อหา ลายเซ็นการคิด และ ID การใช้เครื่องมือจริง ประกอบส่วนเพิ่มของบล็อก SSE ทั้งหมด บล็อกข้อความแรกไม่ใช่ผลลัพธ์ทั้งหมด

##### เมื่อต้องตรวจสอบการตอบกลับต้นฉบับ

เก็บ ID และส่วนหัวของคำขอ/คำตอบ ไม่มี URL ทั่วไปสำหรับดึงงานข้อความให้ใช้

ฟิลด์การตอบกลับ

| ฟิลด์ | ประเภท |
| --- | --- |
| ฟิลด์`id` | ประเภทstring |
| ฟิลด์`model` | ประเภทstring |
| ฟิลด์`content[]` | ประเภทtext\|thinking\|tool\_use\|other content block |
| ฟิลด์`stop_reason` | ประเภทstring\|null |
| ฟิลด์`usage` | ประเภทobject |

ข้อผิดพลาดและขั้นตอนถัดไป

| การตอบกลับ | เงื่อนไข | ขั้นตอนถัดไป |
| --- | --- | --- |
| การตอบกลับ400 · `invalid_request_error` | เงื่อนไขฟิลด์จำเป็น รูปแบบการแทนข้อมูล หรือค่าพารามิเตอร์ไม่ถูกต้อง | ขั้นตอนถัดไปแก้ฟิลด์ที่ระบุก่อนส่งคำขอสร้างครั้งใหม่ |

### ชื่ออื่น

#### ชื่ออื่นของโมเดล

<strong>Ailoot</strong> [`gemini-3.1-flash-image`](https://ailoot.ai/models/th/#m=google%2Fgemini-3.1-flash-image&route=Core&caller=gemini-3.1-flash-image)
**Ailoot Ultra** [`google/gemini-3.1-flash-image`](https://ailoot.ai/models/th/#m=google%2Fgemini-3.1-flash-image&route=Ultra&caller=google%2Fgemini-3.1-flash-image&fmt=messages)

#### ชื่อพาธเมธอดอื่น

`/v1/images`

#### ID ที่เกี่ยวข้องสำหรับเรียกใช้โมเดล

[`google/gemini-3.1-flash-image`](https://ailoot.ai/models/th/#m=google%2Fgemini-3.1-flash-image&route=Ultra&caller=google%2Fgemini-3.1-flash-image&fmt=messages), [`gemini-3.1-flash-image`](https://ailoot.ai/models/th/#m=google%2Fgemini-3.1-flash-image&route=Core&caller=gemini-3.1-flash-image)

FAQ · Google: Nano Banana 2 (Gemini 3.1 Flash Image)

มีอินพุตและผลลัพธ์ใดบ้าง?

`POST /v1/images/generations` · `gemini-3.1-flash-image`: `text` → `image`, `text` `POST /v1/chat/completions` · `google/gemini-3.1-flash-image`: `text` → `text` `POST /v1/images/generations` · `google/gemini-3.1-flash-image`: `text`, `image` → `image` `POST /v1/messages` · `google/gemini-3.1-flash-image`: `text` → `json`, `sse`

คำขอใช้ฟิลด์ใดบ้าง?

`POST /v1/images/generations` · `gemini-3.1-flash-image`: `model`, `prompt`, `n`, `response_format`, `stream` `POST /v1/chat/completions` · `google/gemini-3.1-flash-image`: `model`, `messages`, `stream`, `modalities`, `provider` `POST /v1/images/generations` · `google/gemini-3.1-flash-image`: `model`, `prompt`, `resolution`, `aspect_ratio`, `n`, `input_references`, `provider` `POST /v1/messages` · `google/gemini-3.1-flash-image`: `model`, `messages`, `max_tokens`, `stream`

มีข้อจำกัดใดบ้าง?

`POST /v1/images/generations` · `gemini-3.1-flash-image`: `ctx`: `131072`; `max_out`: `32768`; `n.minimum`: `1` `POST /v1/chat/completions` · `google/gemini-3.1-flash-image`: `messages.min_items`: `1` `POST /v1/images/generations` · `google/gemini-3.1-flash-image`: `n.minimum`: `1`; `n.maximum`: `1`

เชื่อม Ailoot กับ Claude Code, OpenCode, Hermes หรือแอปของคุณ

## บริษัทและพอร์ตโฟลิโอโครงการของบริษัท

บริษัทและพอร์ตโฟลิโอโครงการของบริษัท: ลูกค้าหลายล้านราย; ยอดขายระดับหลายพันล้านต่อเดือน.

## ซื้อโทเคนพร้อมส่วนลด

ส่วนลดสมาชิกสำหรับงานประจำ โค้ดโปรโมชั่นลดซื้อโทเคนสูงสุด 50%

สมาชิก

เลือกแพ็กเกจมีส่วนลดสำหรับคำขอประจำ

โค้ดลดสูงสุด 50%

ใส่โค้ดขณะซื้อ ราคาคำนวณใหม่ตามโปรโมชั่นที่ใช้

รายจ่ายในประวัติ

เก็บโมเดล โทเคน และยอดสำหรับทุกคำขอ

[เลือกสมาชิก](https://ailoot.ai/docs/th/billing/subscriptions/) · [ดูราคาโมเดล](https://ailoot.ai/models/th/)

## เชื่อม API กับผลิตภัณฑ์ ที่คุณขาย

SaaS แอป และบอต ตามข้อเสนอและสัญญาอนุญาต Ailoot หากขายต่อให้ขอใบอนุญาตรีเซลเลอร์

แอปเชิงพาณิชย์

ใส่การสร้างข้อความ ภาพ วิดีโอ และเสียงในฟีเจอร์เสียเงินของบริการคุณ

ใบอนุญาตรีเซลเลอร์

ส่งคำอธิบายโครงการและรูปแบบการเข้าถึง ขอเงื่อนไขใช้และขายต่อเป็นลายลักษณ์อักษร

เอกสารบนเว็บไซต์

อ่านข้อเสนอ สัญญาอนุญาต และนโยบายประมวลผลข้อมูลก่อนเชื่อมได้

[ขอใบอนุญาตขายต่อ](mailto:support@ailoot.ai) · [ข้อเสนอและสัญญาอนุญาต](https://ailoot.ai/legal/offer?lang=th)

## Ailoot · บริษัทและพอร์ตโฟลิโอโครงการของบริษัท





Ailoot อาศัยประสบการณ์การดำเนินงานที่สั่งสม ฐานลูกค้าขนาดใหญ่ บริการที่เสถียร และการติดตาม KPI อย่างต่อเนื่อง





บริษัทและพอร์ตโฟลิโอโครงการของบริษัท: ลูกค้าหลายล้านราย; ยอดขายระดับหลายพันล้านต่อเดือน.





Ailoot นำประสบการณ์การดำเนินงานนี้มาใช้เพื่อให้เข้าถึงฟังก์ชัน AI ผ่าน API ในผลิตภัณฑ์ของลูกค้า เอเจนต์ แอปพลิเคชัน และระบบอัตโนมัติ
