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

# Gemini Generate Content

> 互換 API から Google Gemini を呼び出します。

**Endpoint:** `POST /projects/cognition/locations/us/publishers/google/models/{model}:generateContent`

Google Gemini でテキストまたはマルチモーダル生成を行います。

<Note>
  多くの統合は [Create Chat Completion](/ja/api-reference/chat/create) を推奨します。Google ネイティブの `generateContent` 形式が必要な場合にこのエンドポイントを使ってください。
</Note>

<CodeGroup>
  ```python Python theme={null}
  import os
  import requests

  url = "https://api.yourouter.ai/v1/projects/cognition/locations/us/publishers/google/models/gemini-1.5-pro-latest:generateContent"

  response = requests.post(
      url,
      headers={
          "Authorization": f"Bearer {os.environ['YOUROUTER_API_KEY']}",
          "Content-Type": "application/json",
          "vendor": "google"
      },
      json={
          "contents": [
              {"role": "user", "parts": [{"text": "hello gemini"}]}
          ]
      }
  )
  print(response.json())
  ```

  ```bash cURL theme={null}
  curl https://api.yourouter.ai/v1/projects/cognition/locations/us/publishers/google/models/gemini-1.5-pro-latest:generateContent \
    -H "Authorization: Bearer $YOUROUTER_API_KEY" \
    -H "Content-Type: application/json" \
    -H "vendor: google" \
    -d '{"contents": [{"role": "user", "parts": [{"text": "hello gemini"}]}]}'
  ```
</CodeGroup>

## パラメータ

<ResponseField name="model" type="string" required>
  使用する Gemini モデル（例: `gemini-1.5-pro-latest`）。
</ResponseField>

<ResponseField name="contents" type="array" required>
  入力テキストやマルチメディア parts。
</ResponseField>

<ResponseField name="safetySettings" type="object">
  コンテンツしきい値を制御する任意のセーフティ設定。
</ResponseField>

## 画像入力

base64 エンコードした画像バイトは `inlineData` で渡します。

```bash theme={null}
curl https://api.yourouter.ai/v1/projects/cognition/locations/us/publishers/google/models/gemini-2.5-flash:generateContent \
  -H "Authorization: Bearer $YOUROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -H "vendor: google" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [
          { "text": "Describe this image in one sentence." },
          {
            "inlineData": {
              "mimeType": "image/jpeg",
              "data": "<BASE64_IMAGE>"
            }
          }
        ]
      }
    ]
  }'
```

## PDF 入力

Gemini 原生の `generateContent` 形式では、`inlineData` で PDF を送信できます。`mimeType` を `application/pdf` にし、PDF の生バイト列を base64 エンコードした値を `data` に渡します。

```bash theme={null}
curl https://api.yourouter.ai/v1/projects/cognition/locations/us/publishers/google/models/gemini-2.5-flash:generateContent \
  -H "Authorization: Bearer $YOUROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -H "vendor: google" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [
          { "text": "Summarize this PDF's key content." },
          {
            "inlineData": {
              "mimeType": "application/pdf",
              "data": "<BASE64_PDF>"
            }
          }
        ]
      }
    ]
  }'
```

<Note>
  PDF 対応は選択した Gemini モデルに依存します。長い文書はより多くのコンテキストウィンドウを消費するため、本番環境ではファイルサイズとページ数を制御し、必要に応じて文書を分割してください。
</Note>

より広い連携パスは [マルチモーダル](/ja/guides/multimodal) を参照してください。
