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

# Gemini

Die Plattform unterstützt den Zugriff auf Gemini-Modelle über das OpenAI-Protokoll chat/completions sowie über das native Gemini-Protokoll.

Die folgenden Beispiele verwenden alle den Nicht-Stream-Modus. Wenn Sie den Stream-Modus benötigen, ändern Sie einfach den Path zu /gemini/v1/models/{model}:**streamGenerateContent**.

## Schnellstart

<CodeGroup>
  ```bash OpenAI theme={null}
  curl https://api.highwayapi.ai/openai/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <YOUR-API-KEY>" \
  -d '{
      "model": "gemini-2.5-flash",
      "messages": [{
          "role": "user", "content": "What is the capital of France?"
      }],
      "reasoning_effort": "low"
    }'
  ```

  ```bash Gemini theme={null}
  curl https://api.highwayapi.ai/gemini/v1/models/gemini-2.5-flash:generateContent \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <YOUR-API-KEY>" \
  -d '{
      "contents": [{
          "role": "user",
          "parts": [{"text": "What is the capital of France?"}]
      }],
      "generationConfig": {
          "thinkingConfig": {
              "thinkingBudget": 1024
          }
      }
    }'
  ```
</CodeGroup>

## Steuerung des Denkprozesses im OpenAI-Protokoll

Die Plattform konvertiert den Parameter reasoning\_effort aus OpenAI-chat/completions-Anfragen in Gemini-thinking-Parameter.

| reasoning\_effort | thinking               |
| ----------------- | ---------------------- |
| "disable", "none" | "budget\_tokens": 0    |
| "low"             | "budget\_tokens": 1024 |
| "medium"          | "budget\_tokens": 2048 |
| "high"            | "budget\_tokens": 4096 |

⚠️ Die nicht standardmäßigen OpenAI-Werte disable/none können verwendet werden, um den Denkprozess zu deaktivieren.

### Standardeinstellungen je Modell

| Modell         | Standardeinstellung (wenn reasoning\_effort nicht gesetzt ist)         |
| -------------- | ---------------------------------------------------------------------- |
| 2.5 Pro        | Dynamisches Denken: Das Modell entscheidet, wann und wie viel es denkt |
| 2.5 Flash      | Dynamisches Denken: Das Modell entscheidet, wann und wie viel es denkt |
| 2.5 Flash Lite | Denken ist deaktiviert                                                 |

⚠️ Für Gemini 2.5 Pro kann das Denken nicht deaktiviert werden; reasoning\_effort: none wird in das minimale thinkingBudget 128 konvertiert
⚠️ thinkingBudget wird nur in Gemini 2.5 Flash, 2.5 Pro und 2.5 Flash-Lite unterstützt. Je nach Prompt kann das Modell das Token-Budget über- oder unterschreiten.

## Verwendung serverseitiger Tools

### Google Search

Mit Google Search können Gemini-Modelle mit Echtzeit-Webinhalten verknüpft werden, wobei alle verfügbaren Sprachen unterstützt werden. Dadurch kann Gemini genauere Antworten liefern und überprüfbare Quellen zitieren, die nach dem Wissensstichtag liegen.

<CodeGroup>
  ```bash OpenAI theme={null}
  curl https://api.highwayapi.ai/openai/chat/completions \
  -H "Authorization: Bearer <YOUR-API-KEY>" \
  -H "Content-Type: application/json" -d @- <<EOF
  {
    "model": "gemini-2.5-flash-lite",
    "messages": [
      {
        "role": "user",
        "content": "列一下今天中国的热点新闻"
      }
    ],
    "tools": [
      {
        "function": {"name": "google_search"}
      }
    ]
  }
  EOF
  ```

  ```bash Gemini theme={null}
  curl https://api.highwayapi.ai/gemini/v1/models/gemini-2.5-flash-lite:generateContent \
  -H "Authorization: Bearer <YOUR-API-KEY>" \
  -H "Content-Type: application/json" -d @- <<EOF
  {
    "contents": [
      {
        "role": "user",
        "parts": [{"text": "列一下今天中国的热点新闻"}]
      }
    ],
    "tools": [
      {
        "googleSearch": {}
      }
    ]
  }
  EOF
  ```
</CodeGroup>

Ein Beispielergebnis sieht wie folgt aus. Beim OpenAI-Protokoll können Grounding-Informationen über das nicht standardmäßige Feld gemini\_grounding\_metadata abgerufen werden.

<CodeGroup>
  ```json OpenAI theme={null}
  {
    "id": "dcc7eab10b5adeb9e8648d134e815409",
    "object": "chat.completion",
    "choices": [
      {
        "index": 0,
        "message": {
          "role": "assistant",
          "content": "Here are some of today's top news in China: ..."
        },
        "finish_reason": "stop"
      }
    ],
    "gemini_grounding_metadata": {  # 👈 GEMINI GROUNDING
      "webSearchQueries": [
        "中国今日热点新闻"
      ],
      ...
      "groundingChunks": [
        ...
      ]
    }
  }
  ```

  ```json Gemini theme={null}
  {
    "candidates": [
      {
        "content": {
          "role": "model",
          "parts": [
            {
              "text": "根据您提供的搜索结果，以下是今日中国的一些热点新闻：..."
            }
          ]
        },
        "finishReason": "STOP",
        "index": 0,
        "groundingMetadata": {
          "webSearchQueries": [
            "今日中国热点新闻",
            "中国最新新闻头条"
          ],
          "searchEntryPoint": {...},
          "groundingChunks": [...],
          "groundingSupports": [...]
        }
      }
    ]
  }
  ```
</CodeGroup>

### Code Execution

Gemini stellt ein Tool zur Codeausführung bereit, mit dem das Modell Python-Code generieren und ausführen kann. Anschließend kann das Modell anhand der Ergebnisse der Codeausführung iterativ lernen, bis die endgültige Ausgabe erreicht ist.

<CodeGroup>
  ```bash OpenAI theme={null}
  curl https://api.highwayapi.ai/openai/chat/completions \
  -H "Authorization: Bearer <YOUR-API-KEY>" \
  -H "Content-Type: application/json" -d @- <<EOF
  {
    "model": "gemini-2.5-flash",
    "messages": [
      {
        "role": "user",
        "content": "What is the sum of the first 50 prime numbers? Generate and run code for the calculation, and make sure you get all 50."
      }
    ],
    "tools": [
        {
             "function":  {"name": "code_execution"}
        }
    ],
    "reasoning_effort": "low"
  }
  EOF
  ```

  ```bash Gemini theme={null}
  curl https://api.highwayapi.ai/gemini/v1/models/gemini-2.5-flash:generateContent \
  -H "Authorization: Bearer <YOUR-API-KEY>" \
  -H "Content-Type: application/json" -d @- <<EOF
  {
    "contents": [
      {
        "role": "user",
        "parts": [{"text": "What is the sum of the first 50 prime numbers? Generate and run code for the calculation, and make sure you get all 50."}]
      }
    ],
    "tools": [
      {
        "codeExecution": {}
      }
    ],
    "generationConfig": {
      "thinkingConfig": {
        "thinkingBudget": 1024
      }
    }
  }
  EOF
  ```
</CodeGroup>

Ein Beispielergebnis sieht wie folgt aus. Beim OpenAI-Protokoll werden der Code und die Ergebnisse der Codeausführung in content dargestellt. Beim Gemini-Protokoll befindet sich der Code im Feld executableCode, das Ausführungsergebnis im Feld codeExecutionResult und die Zusammenfassung im Feld text.

<CodeGroup>
  ````markdown OpenAI theme={null}
  Okay, I can help you with that. I will write a Python script to find the
  first 50 prime numbers and then calculate their sum.

  Here's the plan:

  1.  Create a function to check if a number is prime.
  2.  Create a function to generate the first `n` prime numbers.
  3.  Call the generation function for the first 50 primes.
  4.  Sum the resulting list of primes.

  Here is the code to perform this calculation:

  ```PYTHON
  def is_prime(num):
      """Checks if a number is prime."""
      if num <= 1:
          return False
      if num <= 3:
          return True
      if num % 2 == 0 or num % 3 == 0:
          return False
      i = 5
      while i * i <= num:
          if num % i == 0 or num % (i + 2) == 0:
              return False
          i += 6
      return True

  def get_first_n_primes(n):
      """Generates a list of the first n prime numbers."""
      primes = []
      num = 2
      while len(primes) < n:
          if is_prime(num):
              primes.append(num)
          num += 1
      return primes

  # Get the first 50 prime numbers
  first_50_primes = get_first_n_primes(50)


  # Calculate the sum of these prime numbers

  sum_of_primes = sum(first_50_primes)


  print(f"The first 50 prime numbers are: {first_50_primes}")

  print(f"The sum of the first 50 prime numbers is: {sum_of_primes}")
  ```

  The first 50 prime numbers are: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31,
  37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107,
  109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191,
  193, 197, 199, 211, 223, 227, 229]

  The sum of the first 50 prime numbers is: 5117
  ````

  ```markdown Gemini theme={null}
  - executableCode:
      language: PYTHON
      code: |
        import sympy

        def is_prime(n):
            if n <= 1:
                return False
            if n <= 3:
                return True
            if n % 2 == 0 or n % 3 == 0:
                return False
            i = 5
            while i * i <= n:
                if n % i == 0 or n % (i + 2) == 0:
                    return False
                i += 6
            return True

        prime_numbers = []
        num = 2
        while len(prime_numbers) < 50:
            if is_prime(num):
                prime_numbers.append(num)
            num += 1

        sum_of_primes = sum(prime_numbers)

        print(f"The first 50 prime numbers are: {prime_numbers}")
        print(f"The sum of the first 50 prime numbers is: {sum_of_primes}")
  - codeExecutionResult:
      outcome: OUTCOME_OK
      output: >
        The first 50 prime numbers are: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
        31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103,
        107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179,
        181, 191, 193, 197, 199, 211, 223, 227, 229]

        The sum of the first 50 prime numbers is: 5117
  - text: The sum of the first 50 prime numbers is 5117.
  ```
</CodeGroup>

### URL context

Mit dem URL context-Tool können Sie dem Modell zusätzlichen Kontext in Form von URLs bereitstellen.
Wenn Sie URLs zur Anfrage hinzufügen, greift das Modell auf die Inhalte dieser Webseiten zu, um Informationen für die Antwort bereitzustellen und die Antwortqualität zu verbessern.

<CodeGroup>
  ```bash OpenAI theme={null}
  curl https://api.highwayapi.ai/openai/chat/completions \
  -H "Authorization: Bearer <YOUR-API-KEY>" \
  -H "Content-Type: application/json" -d @- <<EOF
  {
    "model": "gemini-2.5-flash-lite",
    "messages": [
      {
        "role": "user",
        "content": "这份食谱适合什么人士 https://www.foodnetwork.com/recipes/ina-garten/perfect-roast-chicken-recipe-1940592"
      }
    ],
    "tools": [
      {
        "function": {"name": "url_context"}
      }
    ]
  }
  EOF
  ```

  ```bash Gemini theme={null}
  curl https://api.highwayapi.ai/gemini/v1/models/gemini-2.5-flash-lite:generateContent \
  -H "Authorization: Bearer <YOUR-API-KEY>" \
  -H "Content-Type: application/json" -d @- <<EOF
  {
    "contents": [
      {
        "role": "user",
        "parts": [{"text": "这份食谱适合什么人士 https://www.foodnetwork.com/recipes/ina-garten/perfect-roast-chicken-recipe-1940592"}]
      }
    ],
    "tools": [
      {
        "urlContext": {}
      }
    ]
  }
  EOF
  ```
</CodeGroup>

Eine Beispielantwort sieht wie folgt aus

<CodeGroup>
  ```json OpenAI theme={null}
  {
    "id": "82f10046aebe6697ed9d33a9fa398de4",
    "object": "chat.completion",
    "choices": [
      {
        "index": 0,
        "message": {
          "role": "assistant",
          "content": "这份食谱是关于如何制作 Ina Garten 的完美烤鸡。\n\n**关键信息：**\n* **食谱来源：** Ina Garten，改编自《Barefoot Contessa Cookbook》。\n* **准备时间：** 20 分钟\n* **烘烤时间：** 1 小时 30 分钟\n* **总时间：** 2 小时 10 分钟\n* **份量：** 8 人份\n* **难度：** 中等\n\n**食材：**\n* 一只 5-6 磅的烤鸡\n* 犹太盐\n* 新鲜磨碎的黑胡椒\n* 一大把新鲜百里香，外加 20 枝\n* 一个柠檬，对半切\n* 一头大蒜，横向切半\n* 2 汤匙（1/4 条）黄油，融化\n* 1 个大黄洋葱，厚切\n* 4 根胡萝卜，切成 2 英寸块\n* 1 个茴香头，去掉顶部，切成楔形\n* 橄榄油\n\n**制作步骤：**\n1. 预热烤箱至 425 华氏度（约 220 摄氏度）。\n2. 清理鸡的内脏，冲洗鸡的内外。去除多余的脂肪和残留的羽毛，并拍干鸡的外部。\n3. 在鸡的内部慷慨地撒上盐和胡椒。将一把百里香、半个柠檬和所有大蒜塞入鸡腔。\n4. 用融化的黄油刷鸡的外部，并再次撒上盐和胡椒。\n5. 用厨房绳子将鸡腿绑在一起，并将鸡翅尖塞到鸡身下方。\n6. 将洋葱、胡萝卜和茴香放入烤盘。用盐、胡椒、20 枝百里香和橄榄油拌匀。将蔬菜铺在烤盘底部，然后将鸡放在蔬菜上面。\n7. 烘烤鸡肉 1.5 小时，或直至用刀在腿和 thigh 之间切割时，汁水清澈。\n8. 将烤好的鸡和蔬菜移至盘子，用铝箔覆盖静置约 20 分钟。\n9. 将鸡肉切片装盘，与蔬菜一起食用。\n\n**烹饪技巧和用户反馈：**\n* 食谱中提到，如果蔬菜底部开始变褐色，可以加入一杯鸡汤帮助保持湿润。\n* 有用户建议使用更小的烤盘，以避免蔬菜烤焦。\n* 有用户将茴香替换成土豆。\n* 许多用户反馈鸡肉非常鲜嫩多汁，风味十足，而且烹饪过程简单。"
        },
        "finish_reason": "stop"
      }
    ],
    "gemini_grounding_metadata": {
      "groundingChunks": [
        {
          "web": {
            "uri": "https://www.foodnetwork.com/recipes/ina-garten/perfect-roast-chicken-recipe-1940592",
            "title": "Perfect Roast Chicken Recipe | Ina Garten | Food Network"
          }
        }
      ],
      "groundingSupports": [....]
    }
  }
  ```

  ```json Gemini theme={null}
  {
    "candidates": [
      {
        "content": {
          "role": "model",
          "parts": [
            {
              "text": "\n这份食谱适合那些喜欢经典烤鸡的人士，特别是对于那些想要制作一道美味又相对容易的菜肴的家庭厨师来说。食谱的难度被评为“中等”，总共需要2小时10分钟（包括20分钟的准备时间，20分钟的空闲时间，以及1小时30分钟的烹饪时间）。\n\n此外，它也适合那些希望在聚会或特殊场合制作一道令人印象深刻的主菜的人士，因为烤鸡通常是节日餐桌上的亮点。\n\n食谱还提到了可以根据个人口味调整配料，例如有评论提到可以省略茴香，或者加入鸡汤来帮助 Basting，这表明它也可以适合那些喜欢在烹饪中进行尝试和调整的人。"
            }
          ]
        },
        "finishReason": "STOP",
        "index": 0,
        "safetyRatings": null,
        "groundingMetadata": {
          "groundingChunks": [
            {
              "web": {
                "uri": "https://www.foodnetwork.com/recipes/ina-garten/perfect-roast-chicken-recipe-1940592",
                "title": "Perfect Roast Chicken Recipe | Ina Garten | Food Network"
              }
            }
          ],
          "groundingSupports": [
            {
              "segment": {
                "startIndex": 148,
                "endIndex": 317,
                "text": "食谱的难度被评为“中等”，总共需要2小时10分钟（包括20分钟的准备时间，20分钟的空闲时间，以及1小时30分钟的烹饪时间）。"
              },
              "groundingChunkIndices": [
                0
              ]
            },
            {
              "segment": {
                "startIndex": 319,
                "endIndex": 475,
                "text": "此外，它也适合那些希望在聚会或特殊场合制作一道令人印象深刻的主菜的人士，因为烤鸡通常是节日餐桌上的亮点。"
              },
              "groundingChunkIndices": [
                0
              ]
            },
            {
              "segment": {
                "startIndex": 477,
                "endIndex": 695,
                "text": "食谱还提到了可以根据个人口味调整配料，例如有评论提到可以省略茴香，或者加入鸡汤来帮助 Basting，这表明它也可以适合那些喜欢在烹饪中进行尝试和调整的人。"
              },
              "groundingChunkIndices": [
                0
              ]
            }
          ]
        }
      }
    ],
    "promptFeedback": {
      "safetyRatings": null
    },
    "usageMetadata": {
      "promptTokenCount": 37,
      "candidatesTokenCount": 159,
      "totalTokenCount": 3270,
      "trafficType": "ON_DEMAND",
      "promptTokensDetails": [
        {
          "modality": "TEXT",
          "tokenCount": 37
        }
      ],
      "candidatesTokensDetails": [
        {
          "modality": "TEXT",
          "tokenCount": 159
        }
      ],
      "toolUsePromptTokensDetails": [
        {
          "modality": "TEXT",
          "tokenCount": 3074
        }
      ],
      "toolUsePromptTokenCount": 3074
    },
    "responseId": "0472efecb0da2db5f78d047e70e54db6",
    "modelVersion": "gemini-2.5-flash-lite"
  }
  ```
</CodeGroup>
