> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bettertoken.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Gemini テキスト画像生成 API

> BetterToken の Gemini API で Nano Banana の画像を生成します。モデル、プロンプト、解像度、比率を選択し、ページ内の API Playground でリクエストと応答を確認できます。

Nano Banana Pro、2、2.1 で文章から画像を生成します。

`POST /v1beta/models/{model}:generateContent`

テキストからの画像生成と画像編集は同じ API を使用します。画像編集ではリクエストに参照画像を追加します。

## リクエストを試す

**x-goog-api-key** に BetterToken API Key を入力し、**model** を選び、**contents** の文章を変更します。まず `1K`、`1:1` を使い、**Send** を押します。

<Note>
  **Send** を押すと実際の生成リクエストが送信され、料金が発生する場合があります。同期応答を待ってください。タイムアウトや切断時は、利用履歴と結果を確認してから再送してください。
</Note>

3 モデルとも `1K`、`2K`、`4K` を利用できます。Nano Banana 2 と 2.1 は 14 種類、Pro は 10 種類の比率に対応しています。 `X-BetterToken-Max-Images` は返却・課金する画像数の上限で、生成枚数を保証しません。 [対応比率](/ja/api-reference/nano-banana#aspect-ratios)

<Warning>
  BetterToken API は Google のウェブ検索や画像検索を利用した画像生成に対応していません。検索ツールを追加しないでください。
</Warning>

テキストからの画像生成には説明文だけで十分です。参照画像は不要です。非ストリーミングの `generateContent` を使用し、Files、Batch、Interactions、ストリーミングには対応していません。

## 応答を読み取る

画像は `candidates[].content.parts[].inlineData` にあります。すべての part を走査し、`thought: true` を除外して `data` をデコードし、`mimeType` に応じた拡張子を選びます。画像が先頭の part や PNG とは限りません。

## 関連ガイド

* [画像編集](/ja/api-reference/gemini-images-edits)
* [SDK、画像保存と継続編集](/ja/api-reference/nano-banana)
* [モデル紹介](/ja/model-updates/nano-banana)
* <a href={"https://bettertoken.ai/pricing"}>モデルカタログ</a>


## OpenAPI

````yaml api-reference/gemini-images-generations.ja.json POST /v1beta/models/{model}:generateContent
openapi: 3.1.0
info:
  title: Gemini テキスト画像生成 API
  description: >-
    BetterToken の Gemini API で Nano Banana の画像を生成します。モデル、プロンプト、解像度、比率を選択し、ページ内の
    API Playground でリクエストと応答を確認できます。
  version: 1.0.0
servers:
  - url: https://bettertoken.ai
security:
  - geminiApiKey: []
paths:
  /v1beta/models/{model}:generateContent:
    post:
      summary: Gemini テキスト画像生成 API
      description: >-
        Nano Banana Pro、2、2.1 で文章から画像を生成します。 BetterToken API は Google
        のウェブ検索や画像検索を利用した画像生成に対応していません。検索ツールを追加しないでください。
      operationId: generateGeminiImage_ja
      parameters:
        - name: model
          in: path
          required: true
          description: BetterToken のモデル ID。Nano Banana の 3 モデルから選びます。
          schema:
            type: string
            enum:
              - nano-banana-pro
              - nano-banana-2
              - nano-banana-2.1
            default: nano-banana-2.1
        - name: X-BetterToken-Max-Images
          in: header
          description: 返却・課金する画像数の上限です。枚数保証ではありません。既定値は 1。
          schema:
            type: integer
            minimum: 1
            maximum: 4
            default: 1
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - contents
              properties:
                contents:
                  type: array
                  description: 会話履歴。継続編集ではモデルの完全な content と thoughtSignature を保持します。
                  minItems: 1
                  items:
                    type: object
                    required:
                      - parts
                    properties:
                      role:
                        type: string
                        description: 新規リクエストは user、編集履歴のモデル応答は model。
                        enum:
                          - user
                          - model
                        default: user
                      parts:
                        type: array
                        description: 文章と画像。text と inlineData は別々の part に入れます。
                        minItems: 1
                        items:
                          anyOf:
                            - type: object
                              required:
                                - text
                              properties:
                                text:
                                  type: string
                                  description: 画像の説明または編集指示。
                                  example: 白いテーブルに置かれた青い陶器のマグカップのスタジオ商品写真。
                              additionalProperties: true
                            - type: object
                              required:
                                - inlineData
                              properties:
                                inlineData:
                                  type: object
                                  description: base64 で埋め込んだ参照画像。
                                  required:
                                    - mimeType
                                    - data
                                  properties:
                                    mimeType:
                                      type: string
                                      description: 参照画像の MIME 型。
                                      enum:
                                        - image/png
                                        - image/jpeg
                                      example: image/png
                                    data:
                                      type: string
                                      description: Data URL 接頭辞のない画像バイトの base64。
                                      contentEncoding: base64
                                      example: REPLACE_WITH_IMAGE_BASE64
                                  additionalProperties: false
                              additionalProperties: true
                    additionalProperties: false
                generationConfig:
                  type: object
                  description: 画像生成の設定。
                  properties:
                    responseModalities:
                      type: array
                      description: 画像出力を明示的に指定します。
                      items:
                        type: string
                        enum:
                          - IMAGE
                      default:
                        - IMAGE
                    candidateCount:
                      type: integer
                      enum:
                        - 1
                      default: 1
                      description: 省略するか整数 1 を指定。ルートに n を入れないでください。
                    imageConfig:
                      type: object
                      description: 出力画像の設定。
                      properties:
                        imageSize:
                          type: string
                          description: 出力解像度。K は大文字。
                          enum:
                            - 1K
                            - 2K
                            - 4K
                          default: 1K
                        aspectRatio:
                          type: string
                          description: 比率。Pro は 10 種類、2 と 2.1 は 1:4、4:1、1:8、8:1 も対応。
                          enum:
                            - '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'
                          default: '1:1'
                      additionalProperties: false
                  additionalProperties: false
              additionalProperties: false
            example:
              contents:
                - role: user
                  parts:
                    - text: 白いテーブルに置かれた青い陶器のマグカップのスタジオ商品写真。
              generationConfig:
                responseModalities:
                  - IMAGE
                candidateCount: 1
                imageConfig:
                  imageSize: 1K
                  aspectRatio: '1:1'
      responses:
        '200':
          description: 生成結果。最終画像の part と finishReason を確認します。
          content:
            application/json:
              schema:
                type: object
                properties:
                  candidates:
                    type: array
                    items:
                      type: object
                      properties:
                        content:
                          type: object
                          properties:
                            role:
                              type: string
                            parts:
                              type: array
                              items:
                                type: object
                                properties:
                                  text:
                                    type: string
                                  thought:
                                    type: boolean
                                  thoughtSignature:
                                    type: string
                                  inlineData:
                                    type: object
                                    properties:
                                      mimeType:
                                        type: string
                                      data:
                                        type: string
                                        contentEncoding: base64
                        finishReason:
                          type: string
                  promptFeedback:
                    type: object
                    additionalProperties: true
                  usageMetadata:
                    type: object
                    additionalProperties: true
              example:
                candidates:
                  - content:
                      role: model
                      parts:
                        - inlineData:
                            mimeType: image/png
                            data: BASE64_IMAGE_DATA
                    finishReason: STOP
        '400':
          description: 無効なパラメータまたは未対応機能。
        '401':
          description: API Key が未指定または無効。
        '402':
          description: 残高不足。
        '429':
          description: レート制限または上流サービスの混雑。
        '500':
          description: 生成エラー。再送前に結果を確認してください。
components:
  securitySchemes:
    geminiApiKey:
      type: apiKey
      in: header
      name: x-goog-api-key
      description: BetterToken API Key。

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.