Gemini 3.1 Pro
Text Generation • Google • ProxiedGoogle's most intelligent Gemini model with improved reasoning, a medium thinking level, and a 1M token context window.
| Model Info | |
|---|---|
| Context Window ↗ | 1,000,000 tokens |
| Terms and License | link ↗ |
| More information | link ↗ |
| Pricing | View pricing in the Cloudflare dashboard ↗ |
Usage
const response = await env.AI.run( 'google/gemini-3.1-pro', { contents: [ { role: 'user', parts: [ { text: 'What are the three laws of thermodynamics?', }, ], }, ], }, { gateway: { id: 'default' }, })console.log(response)The laws of thermodynamics are the fundamental principles that describe how energy moves and changes within the universe. While the prompt asks for the "three" laws, there are actually four (scientists later added a "Zeroth" law). Here is a breakdown of the three main laws, plus the bonus Zeroth law, explained in both scientific terms and plain English. ### 1. The First Law: The Law of Conservation of Energy * **The Science:** Energy cannot be created or destroyed in an isolated system; it can only change forms. The change in a system's internal energy is equal to the heat added to the system minus the work done by the system. * **Plain English:** You can’t get something for nothing. Energy just trades places or changes its outfit. * **Everyday Example:** When you turn on a lightbulb, electrical energy isn't destroyed; it is transformed into light energy and heat energy. When you eat an apple, your body converts the chemical energy in the food into kinetic energy so you can move. ### 2. The Second Law: The Law of Entropy * **The Science:** The total entropy (a measure of disorder, randomness, or chaotic energy) of an isolated system will always increase over time. Furthermore, heat will always flow spontaneously from a hotter object to a colder one, never the other way around. * **Plain English:** Things naturally degrade and become more disorganized over time. Because some energy is always lost as unusable heat when it changes forms, no process is 100% efficient. * **Everyday Example:** If you leave a hot cup of coffee on a table, it will naturally cool down as its heat spreads into the room. It will never spontaneously gather heat from the room to make itself boiling hot again. Similarly, a tidy room will naturally become messy over time unless you expend energy (do work) to clean it. ### 3. The Third Law: Absolute Zero * **The Science:** As the temperature of a system approaches absolute zero (0 Kelvin, or -273.15°C / -459.67°F), the entropy of the system approaches a constant minimum. * **Plain English:** Absolute zero is the coldest possible temperature, where all molecular and atomic movement completely stops. This law states that it is physically impossible to actually reach absolute zero because doing so would require an infinite amount of work. * **Everyday Example:** Imagine a bustling crowd of people (molecules) moving around. As the room gets colder, they slow down. At absolute zero, every single person would be perfectly frozen in place. --- ### *Bonus: The Zeroth Law (Thermal Equilibrium)* Scientists realized this principle was so fundamental that it needed to precede the First, Second, and Third laws—hence, the "Zeroth" law. * **The Science:** If System A is in thermal equilibrium (the same temperature) with System B, and System B is in thermal equilibrium with System C, then System A is in thermal equilibrium with System C. * **Plain English:** If two things are the same temperature as a third thing, they are all the same temperature. * **Everyday Example:** This is why thermometers work. If a thermometer is the same temperature as a room, and you are the same temperature as the room, you are the same temperature as the thermometer. ### The "Gambling" Summary A famous and humorous way physicists remember the laws of thermodynamics is by comparing the universe to a rigged casino game: * **1st Law:** *You can’t win.* (You cannot create energy out of nothing). * **2nd Law:** *You can’t break even.* (You always lose some energy to heat/entropy). * **3rd Law:** *You can’t quit the game.* (You can never reach absolute zero).
{ "candidates": [ { "content": { "role": "model", "parts": [ { "text": "The laws of thermodynamics are the fundamental principles that describe how energy moves and changes within the universe. While the prompt asks for the \"three\" laws, there are actually four (scientists later added a \"Zeroth\" law). \n\nHere is a breakdown of the three main laws, plus the bonus Zeroth law, explained in both scientific terms and plain English.\n\n### 1. The First Law: The Law of Conservation of Energy\n* **The Science:** Energy cannot be created or destroyed in an isolated system; it can only change forms. The change in a system's internal energy is equal to the heat added to the system minus the work done by the system.\n* **Plain English:** You can’t get something for nothing. Energy just trades places or changes its outfit. \n* **Everyday Example:** When you turn on a lightbulb, electrical energy isn't destroyed; it is transformed into light energy and heat energy. When you eat an apple, your body converts the chemical energy in the food into kinetic energy so you can move.\n\n### 2. The Second Law: The Law of Entropy\n* **The Science:** The total entropy (a measure of disorder, randomness, or chaotic energy) of an isolated system will always increase over time. Furthermore, heat will always flow spontaneously from a hotter object to a colder one, never the other way around. \n* **Plain English:** Things naturally degrade and become more disorganized over time. Because some energy is always lost as unusable heat when it changes forms, no process is 100% efficient. \n* **Everyday Example:** If you leave a hot cup of coffee on a table, it will naturally cool down as its heat spreads into the room. It will never spontaneously gather heat from the room to make itself boiling hot again. Similarly, a tidy room will naturally become messy over time unless you expend energy (do work) to clean it.\n\n### 3. The Third Law: Absolute Zero\n* **The Science:** As the temperature of a system approaches absolute zero (0 Kelvin, or -273.15°C / -459.67°F), the entropy of the system approaches a constant minimum. \n* **Plain English:** Absolute zero is the coldest possible temperature, where all molecular and atomic movement completely stops. This law states that it is physically impossible to actually reach absolute zero because doing so would require an infinite amount of work.\n* **Everyday Example:** Imagine a bustling crowd of people (molecules) moving around. As the room gets colder, they slow down. At absolute zero, every single person would be perfectly frozen in place. \n\n---\n\n### *Bonus: The Zeroth Law (Thermal Equilibrium)*\nScientists realized this principle was so fundamental that it needed to precede the First, Second, and Third laws—hence, the \"Zeroth\" law.\n* **The Science:** If System A is in thermal equilibrium (the same temperature) with System B, and System B is in thermal equilibrium with System C, then System A is in thermal equilibrium with System C.\n* **Plain English:** If two things are the same temperature as a third thing, they are all the same temperature. \n* **Everyday Example:** This is why thermometers work. If a thermometer is the same temperature as a room, and you are the same temperature as the room, you are the same temperature as the thermometer.\n\n### The \"Gambling\" Summary\nA famous and humorous way physicists remember the laws of thermodynamics is by comparing the universe to a rigged casino game:\n* **1st Law:** *You can’t win.* (You cannot create energy out of nothing).\n* **2nd Law:** *You can’t break even.* (You always lose some energy to heat/entropy).\n* **3rd Law:** *You can’t quit the game.* (You can never reach absolute zero).", "thoughtSignature": "CukdAY89a1/JNlElaHLRqgJBgLDUmWtvxcCTkUFQDQoIKIzMnMD7okyPA4FwhCPTW+6WhdipRl7CbxH6TaTxG6pGaRYORUPogRIRzr8jHXtfUsIR51eJv4EruvMiz1qQqJ8ButQTSJIMD2fZG97i/3QMyxNAUXBmxoYH2Gd7jt/VkN+6iVjbDSwBpvf9T+oOh0l6MGClG1snOHBMIzEMuAxmHpCo0pl/1Fq7noAbBx9OJ72ME/HS+uBqAh8xI+8j6qd9VHPnAxgnjCPDXYd7TNcLprEjM84sEidmsh0Ot4NIQQcNPDwA18uu4WcE8hS0A1LsabbFRN6LNFTZ8IDMuzOod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s9hnSpIAI5wVJwhL28TXLY6zdoThKm3zP53b+9ZHdhNzno5WY6PnDO0H97ymmMpMEUhjPFQFpj2LyXLEHij/chhuW5+hInjbjmEHR+R6oHiEfGKm3H1iJ4xQTsZGaa6uYLrIZAyWdbKl1Xpz2cgXM8qTApjh91GdB0qePfWxVFjHPTay2159QWuHcgB0utwFw7bdW1czmI6mjwtL4Vo1x8FdekzITVUnRNW0Ochy9JS12O4PEee5zB47aHNlFjngGmnU9sGjxIpqRDOLgf7qFi/777tsMOjAHDKYq8D4Wx76lkWixgxXOXriXcxTVhzKC+YQueXxGkveVWivNo4VGY2Ztf7ovxkPvJZQFZjoRCbE92xXLcV8HaBJFsRp8JOu7XX+sCClWWZn5HU5aO3r2PTk6YpD9+XifMxkWCCm/cbyelEfRPktvw==" } ] }, "finishReason": "STOP", "avgLogprobs": -0.24408692330364393 } ], "usageMetadata": { "promptTokenCount": 8, "candidatesTokenCount": 828, "totalTokenCount": 1761, "trafficType": "ON_DEMAND", "promptTokensDetails": [ { "modality": "TEXT", "tokenCount": 8 } ], "candidatesTokensDetails": [ { "modality": "TEXT", "tokenCount": 828 } ], "thoughtsTokenCount": 925 }, "modelVersion": "gemini-3.1-pro-preview", "createTime": "2026-04-17T00:58:04.691850Z", "responseId": "nIXhaYqdKqyA9LsPwLiNqQg", "gatewayMetadata": { "keySource": "Unified" }}Examples
With System Instruction — Using a system instruction to set context
const response = await env.AI.run( 'google/gemini-3.1-pro', { contents: [ { role: 'user', parts: [ { text: 'How do I read a JSON file in Python?', }, ], }, ], systemInstruction: { parts: [ { text: 'You are a helpful coding assistant specializing in Python.', }, ], }, generationConfig: { temperature: 0.3, }, }, { gateway: { id: 'default' }, })console.log(response)To read a JSON file in Python, you can use the built-in `json` module.
Here is the most common and standard way to do it:
### Basic Example
Assuming you have a file named `data.json`, here is how you read it:
```python
import json
# Open the file in read mode
with open('data.json', 'r', encoding='utf-8') as file:
# Load the JSON data into a Python dictionary
data = json.load(file)
# Now you can use 'data' like a normal Python dictionary
print(data)
```
### How it works:
1. **`import json`**: Imports Python's built-in JSON library.
2. **`with open(...) as file:`**: Opens the file safely. Using `with` ensures that the file is automatically closed after it is read, even if an error occurs. Adding `encoding='utf-8'` is a best practice to prevent errors with special characters.
3. **`json.load(file)`**: Reads the file and converts the JSON data into the corresponding Python object (usually a dictionary or a list).
---
### Advanced Example (with Error Handling)
If you want to write robust code, it is a good idea to handle potential errors, such as the file not existing or the JSON being formatted incorrectly:
```python
import json
file_path = 'data.json'
try:
with open(file_path, 'r', encoding='utf-8') as file:
data = json.load(file)
print("Successfully read JSON data!")
except FileNotFoundError:
print(f"Error: The file {file_path} was not found.")
except json.JSONDecodeError:
print(f"Error: The file {file_path} does not contain valid JSON.")
```
### A Quick Note: `load()` vs `loads()`
* Use **`json.load()`** (no 's') when reading directly from a **file**.
* Use **`json.loads()`** (with an 's' for string) if you are reading JSON from a **string variable** in your code. { "candidates": [ { "content": { "role": "model", "parts": [ { "text": "To read a JSON file in Python, you can use the built-in `json` module. \n\nHere is the most common and standard way to do it:\n\n### Basic Example\n\nAssuming you have a file named `data.json`, here is how you read it:\n\n```python\nimport json\n\n# Open the file in read mode\nwith open('data.json', 'r', encoding='utf-8') as file:\n # Load the JSON data into a Python dictionary\n data = json.load(file)\n\n# Now you can use 'data' like a normal Python dictionary\nprint(data)\n```\n\n### How it works:\n1. **`import json`**: Imports Python's built-in JSON library.\n2. **`with open(...) as file:`**: Opens the file safely. Using `with` ensures that the file is automatically closed after it is read, even if an error occurs. Adding `encoding='utf-8'` is a best practice to prevent errors with special characters.\n3. **`json.load(file)`**: Reads the file and converts the JSON data into the corresponding Python object (usually a dictionary or a list).\n\n---\n\n### Advanced Example (with Error Handling)\n\nIf you want to write robust code, it is a good idea to handle potential errors, such as the file not existing or the JSON being formatted incorrectly:\n\n```python\nimport json\n\nfile_path = 'data.json'\n\ntry:\n with open(file_path, 'r', encoding='utf-8') as file:\n data = json.load(file)\n print(\"Successfully read JSON data!\")\n \nexcept FileNotFoundError:\n print(f\"Error: The file {file_path} was not found.\")\nexcept json.JSONDecodeError:\n print(f\"Error: The file {file_path} does not contain valid JSON.\")\n```\n\n### A Quick Note: `load()` vs `loads()`\n* Use **`json.load()`** (no 's') when reading directly from a **file**.\n* Use **`json.loads()`** (with an 's' for string) if you are reading JSON from a **string variable** in your code.", "thoughtSignature": "CvMRAY89a18FbXEddL8DanEpuPCn/i+5iM1SQjc0uDlyNyMluXp5ptu6txVx+5MaOceIyg/Y7qf9kL3tVpU4KBTvfWIgZxEK9JUi033jn/nLasOEbI94nT+sycFp+s+7ogv+sE6AL1wl2RNITCBM/pP/rxn47zEKHaq6432qCLrp+5AU8QM7T84TAZJYZi5+hq6tKp4jcuFuJ1paSmF6ibHTTznxd6FTMcayJSIf3F5gH0B/89vUf3l62rseMpM+kDgz/D4r43Lpg8RIl74D714K1uvuyeUUL9E9TnK6n8EPXkyaz3O/Pcn5uwNQcPVf+UsbLXx96JvMqI4K/WdkDQoS0pRXie6yWvwkdN4CKAsx2Ovcu3w/TOhs4iizEAbf+6TUuQnJaX78xYmXQ/aG+NfP85egxa4KMqth++MncCbbJjrvSrxTKG0IkJN90oRAy7zKItLBUGQJf6sq3sGdaWvbutfipAeZQPM4VWySW3gJmtNHf28w00FcLenv0g90c0sNLDeovz/bNAblrp75CC1C3pXCwWV0Fp1r60lRmOD012aQ3zJ+vMKD/yYV/ZQuYIgu7bS9tMFNYG+DWI4ZJl0CXWQg50XfDQu5eJEUnPhNCx2uiVeJPm8ShA62huUjsF5nCezXLXCR3t+4jHoIiOZ4GYO/nNU0fqBWRd7xXDHkWFKbOZlpJCFzuQ60jWSSMZWOl6NE3Oo6+yoghUmM6NpSL3y2EY1Lh2jtyHTvMZFmL3mqnkeehB3zNOzbAx1YGUXP3JMF5pD/TGNSYRpSbMVBjqxvRsTSVByg8+s9aeqA2FFHipoz99CaOTX5e24us51QyhilYgUsPj+vKMusLWWySeXW2fRpjQFMA/uJBKgAYwLIZTvJobHq7K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"finishReason": "STOP", "avgLogprobs": -0.13193573454933058 } ], "usageMetadata": { "promptTokenCount": 20, "candidatesTokenCount": 478, "totalTokenCount": 1088, "trafficType": "ON_DEMAND", "promptTokensDetails": [ { "modality": "TEXT", "tokenCount": 20 } ], "candidatesTokensDetails": [ { "modality": "TEXT", "tokenCount": 478 } ], "thoughtsTokenCount": 590 }, "modelVersion": "gemini-3.1-pro-preview", "createTime": "2026-04-17T00:58:06.706819Z", "responseId": "noXhaYOSK5eDpucP34WHiQw", "gatewayMetadata": { "keySource": "Unified" }}Multi-turn Conversation — Continuing a conversation with context
const response = await env.AI.run( 'google/gemini-3.1-pro', { contents: [ { role: 'user', parts: [ { text: 'I need help planning a road trip from San Francisco to Los Angeles.', }, ], }, { role: 'model', parts: [ { text: "I'd be happy to help! The drive is about 380 miles and takes roughly 5-6 hours. Would you like suggestions for scenic routes or interesting stops along the way?", }, ], }, { role: 'user', parts: [ { text: 'Yes, what are some good places to stop?', }, ], }, ], generationConfig: { maxOutputTokens: 500, }, }, { gateway: { id: 'default' }, })console.log(response)The best stops really depend on which route you decide to take! There are three
{ "candidates": [ { "content": { "role": "model", "parts": [ { "text": "The best stops really depend on which route you decide to take! There are three", "thoughtSignature": "CusNAY89a19w9AIPxKvbuUfUkzudgllnysvy8j4JkhUnfV4d8zcWGgZVCvhWZ8xsql7I+NdLOdBBpJqblTboQ3qA9Rc6Ct/JVFDAbrHhaICZPhI2fJCWrpyOgJbvFqxGy9CGAjIP2B4N+Ani9Zo4Gbhg/BWiz9Gxi/+owOUubc39d5QNdXrJsinP/9eLZ3tAhidZFMOaOXIw8N5d6V0AyTTjXpISAeJpjUT8KX/gfGcSwDyntIxikcCltG49TqR3AKkcJJvGpS2u5dUpLvjETIte2NmVeTVjDoNhrUOLa37W3u83+N/4+PygOjLvCUlEmuE+9uftsxZ3KQRw6QNbWRhkcIlXUOfo6juiLes+xsdDfTAGNQVy/CXbmEAvHjRueHhbWKXljT1090FYdE6rHvd3yllxR1uw026zI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9FWsZ2nAidRQcYspT5JLsmoqfBu2chMJyEWkhZyoVeV0tLyUpeD7LYzaQuYDE5Gdd16s+dtYGeHL5vq9GWhzNI0X7MhbQuoa9WqDZEdU78arTXWleNVvcxVcPFM9i4Varb/RZvybBEaq5axv2ueA1o/koAMV/kRSdA9sTZztVQnZfmvUKWidOfuPyBNsuzEKQhjSYvHs+MjHtIjpcxm0wEqJk63ID5xKN2jJZcw93lZgjxnrcWUP6DCdscngS8pKfJ6EN7+E3dS0Z+3BSJTqwNq/K6YCt27Fz8XRa5LUgB16ys4FE71ksjKn58+anwZClStWXJ1eck4O8TynLS63Y+MGsoFT+O+Ob+yki4hlTviMMUeZ1/8c0vKcBy+AmENJDWIec0l5cE9BUMOeiL2W4FDDVW/zKiEa/TfxKh0m/cS6JPdlv/WaoIIZ9A1KXZxVOfoG+sJ6OBO2EhBF9aQJrRhxWCShQ8CmzwXKqbOk4lmvW2j/xvyhT/aAavMs8IYn74r9hO4Sr4MCAnMZMF7gqCsFkOmDj0iJpv50VCxOGZ2Liob3H6yhrZXh82nwqW5yfWoVSpbR4LLv+ZlL0Aw79u+yBt6mjBO6M6DBHJXQTdaaHiPkBm19D1NPB3Gi1VPrBPeq/AJxSb4ahf3A7Vai25qfjFOAHHa0ahKlk6thrcciVCBPUEdopvOZpVBdGCrG1eRKrXlkDh90lGxYm1DTeOYnStVptnCCa/EFyiVjvHExP1G3it7bSVM669oiyxG3DFmd0qVnpmASdHFs0/I1QOj2aoyTDXXYEx2RQs/Z1U4HlIm9xLami9knqkDaQQZufXj+LGDdAnmwv9XN+CCQ==" } ] }, "finishReason": "MAX_TOKENS", "avgLogprobs": -8.212950519499952 } ], "usageMetadata": { "promptTokenCount": 64, "candidatesTokenCount": 16, "totalTokenCount": 560, "trafficType": "ON_DEMAND", "promptTokensDetails": [ { "modality": "TEXT", "tokenCount": 64 } ], "candidatesTokensDetails": [ { "modality": "TEXT", "tokenCount": 16 } ], "thoughtsTokenCount": 480 }, "modelVersion": "gemini-3.1-pro-preview", "createTime": "2026-04-17T00:58:22.165603Z", "responseId": "roXhaeONCsmApucP_8_n-Qc", "gatewayMetadata": { "keySource": "Unified" }}Creative Writing — Higher temperature for creative output
const response = await env.AI.run( 'google/gemini-3.1-pro', { contents: [ { role: 'user', parts: [ { text: 'Write a short story opening about a detective finding an unusual clue.', }, ], }, ], generationConfig: { temperature: 0.8, maxOutputTokens: 300, }, }, { gateway: { id: 'default' }, })console.log(response)The air in Elias Vance’s apartment smelled of stale copper
{ "candidates": [ { "content": { "role": "model", "parts": [ { "text": "The air in Elias Vance’s apartment smelled of stale copper", "thoughtSignature": "Cq4JAY89a182dWgWqxl+2ki63AHSyM5ZH2lCKULPaq6FwVzqU8cjzEuUMCW+PtvlWb4o8I43mjINtaopb+0gfW34S3B+T/ho11F45VvPlOtThgRHYzNW380UwBnoDc95tH/lYRrI05dWolDbmYq6VlbJBzyuXa4KSRkQsPdgsaRRylO8j738BXvyGMuiKcPRRtm+5ZL6M1oeqKrGGu1Z9ye9f1ZiO5bX105o2QZwnJ3muHcraACV86Hn11Au6iEnhpoN94OzVxn4b9Gun97TLdAHA4PSI0zmVuo1twzc3Ai9ELnr79qMrHzi1FL/E3WG+zh8pftb5kpQHGpIW4VCvUXr0nPaswhuCCBFMc7sGrTG/9FnreK5QPQKKU+C1F+WojRr3k9ReZ36VAib4CqW8Y23JsUhup3OjwoU++C5g2PeVZF5l38VqzJTvLYHp4RKzKr3fYUsg5l0Rl3o7eHQ+/BXU5mdNbEmlvDHzHbpayGSDhGlxDjBBAAwclf/XM+6kNGIg9p0EcOS8kOmw+PqrRF09uLiuVceXYflgMbUT2g314LC7Gzmfygtd9XCNrl6lnYPoZZirjGax+14OL+/m6+BIZPT/HXyyy6EZn9yHpSRWkIpR8mbmclANJDPB1RmM9M67YzeZ4aenNZV3V0Kh9vSHgimXjuz3FkwINi+wxpErzFHsnbGtuBJv6xjl9jKa0DAq4FU/V1u5hjv1Z6K2uLEUtx67Ol9ojrd5AECXhhw1U1ytmPz1Enly3kNciGIprAHFa3/eWT+maYFNMbCHKCULAwEVzb2m3H6fCnMRyEXMQCFcbZ+QXDN+zUd1Hc7xsRw7u2fZloeR6/KVVlqN//4mefFy4HFGFjqpTCIPuUtpLwDDExWWDQqZHwnJy5xQhgT1MxpugXaCFWMkQIO6mOZbBLd+4LP1VR2ObW4e0kiFcuriJbpg/z2gzd3aQB3bbj2ufBBm2QffRzdu6pqCGHw1UICot926fux2fzFRf8ReF3ZVdcA4QeJzVuQe68wNtsSB+6bjp8O0/G+opcgy5GpjDbtfcqOM3h2dTshksC9LULh8WFxzxUZ9WxNoyjcITHqm5xoU3fZw0vAbyTPDEI9GtqcxNFvuhs266Z5FPlqoCGBFGbjViesqZaP0juB9q4N+WWF34Od8igXBWwYs8My+WM5Zce0eKwWp47UY3wAmpjVKimsNzI5lSES3o+72mW8garA6O0Cv+1lVXyqPKC2QdOim+CLxJyjwY/NZWVYy5b5hMHI+LRwhOIk4HXMZHejry53BQCLCyPhfhg81fVykTiAcwr4cs74aHbXb8C5514wpJwFQ1MeU4z5cCfTp9t/4ot7PeQbC8+HCTpO57m4rRdNpoEwzOGNezElnvf4nNzK/E2dv3uHxevjTyR23OQbB9l9MzZbKWqidlfJfzP5/YwAfy1a+vi7bbqvLSeIVwKHl5Yz6qz7VV2kJEigbG8DNJg8RrAtV8nz8kLg/LZgrtlkqAn4AaeAwwKer0OH33c+rREg8XVSPAoFKZHluqICy7xqzx3mD9rhgg7WUrXJYrcfEdGUGHjOLW4mtyaYOFhkMf1AhtblZpQTrAHb9w==" } ] }, "finishReason": "MAX_TOKENS", "avgLogprobs": -7.339017173991171 } ], "usageMetadata": { "promptTokenCount": 13, "candidatesTokenCount": 12, "totalTokenCount": 309, "trafficType": "ON_DEMAND", "promptTokensDetails": [ { "modality": "TEXT", "tokenCount": 13 } ], "candidatesTokensDetails": [ { "modality": "TEXT", "tokenCount": 12 } ], "thoughtsTokenCount": 284 }, "modelVersion": "gemini-3.1-pro-preview", "createTime": "2026-04-17T00:58:27.814075Z", "responseId": "s4XhafvXMemVq8YPzcOY0Qg", "gatewayMetadata": { "keySource": "Unified" }}Parameters
arrayrequiredobjectobjectarrayarrayarrayobjectstring