- Third-party
- Zero data retention
Google'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 ↗ |
| Zero data retention | Yes |
| Request formats | Chat Completions |
| Pricing | View pricing in the Cloudflare dashboard ↗ |
const response = await env.AI.run(
'google/gemini-3.1-pro',
{ contents: [{ parts: [{ text: 'What are the three laws of thermodynamics?' }], role: 'user' }] },
)
console.log(response)curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "google/gemini-3.1-pro",
"input": {
"contents": [
{
"parts": [
{
"text": "What are the three laws of thermodynamics?"
}
],
"role": "user"
}
]
}
}'The laws of thermodynamics are fundamental principles in physics that describe how energy moves, changes form, and interacts with matter in the universe. Here is a breakdown of the three laws (plus a "bonus" law) explained simply: ### 1. The First Law: The Law of Conservation of Energy * **The Concept:** Energy cannot be created or destroyed; it can only be transferred or changed from one form to another. The total amount of energy in the universe is constant. * **In Simple Terms:** You can’t get something for nothing. * **Everyday Example:** When you eat an apple, your body doesn't "destroy" the calories (chemical energy). It transforms them into kinetic energy (when you move) and thermal energy (body heat). Similarly, a lightbulb doesn't create light out of nowhere; it converts electrical energy into light and heat. ### 2. The Second Law: The Law of Entropy * **The Concept:** The total **entropy** (a measure of disorder or randomness) of an isolated system always increases over time. Because of this, heat will always naturally flow from a hotter object to a colder one, never the reverse. Energy transfers are never 100% efficient; some energy is always lost as unusable heat. * **In Simple Terms:** Things naturally get messier over time, and you can't even "break even" when transferring energy. * **Everyday Example:** If you leave a hot cup of coffee on a table, it will eventually cool down until it matches room temperature. The heat spreads out and dissipates. You will never see a cold cup of coffee spontaneously absorb heat from the room and start boiling. ### 3. The Third Law: Absolute Zero * **The Concept:** As the temperature of a system approaches **absolute zero** (0 Kelvin, or -273.15°C / -459.67°F), the entropy (disorder) of the system approaches a constant minimum. At absolute zero, all atomic and molecular movement essentially stops. * **In Simple Terms:** Things stop moving when it gets as cold as physically possible. * **Everyday Example:** It is practically impossible to reach absolute zero, but scientists use this law to understand how materials behave at extreme extremes. For instance, creating superconductors (materials with zero electrical resistance) requires cooling them to near absolute zero so that atomic vibrations don't interfere with the flow of electricity. --- ### *Bonus: The Zeroth Law* Wait, a zeroth law? Yes! Scientists realized later that there was a foundational rule they assumed to be true but never formally stated. Because the 1st, 2nd, and 3rd laws were already established, they named this the "Zeroth" law so it would logically come first. * **The Concept:** If System A and System B are both the same temperature as System C, then System A and System B must be the same temperature as each other. (This law establishes the basis for how thermometers work!). --- ### The Famous "Gambler's Analogy" To make these laws easy to remember, physicists sometimes summarize them like a rigged game of cosmic poker: * **1st Law:** You can't win; you can only break even. *(Energy is conserved).* * **2nd Law:** You can't even break even; you will always lose. *(Entropy increases; energy is lost as heat).* * **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 fundamental principles in physics that describe how energy moves, changes form, and interacts with matter in the universe. \n\nHere is a breakdown of the three laws (plus a \"bonus\" law) explained simply:\n\n### 1. The First Law: The Law of Conservation of Energy\n* **The Concept:** Energy cannot be created or destroyed; it can only be transferred or changed from one form to another. The total amount of energy in the universe is constant.\n* **In Simple Terms:** You can’t get something for nothing. \n* **Everyday Example:** When you eat an apple, your body doesn't \"destroy\" the calories (chemical energy). It transforms them into kinetic energy (when you move) and thermal energy (body heat). Similarly, a lightbulb doesn't create light out of nowhere; it converts electrical energy into light and heat.\n\n### 2. The Second Law: The Law of Entropy\n* **The Concept:** The total **entropy** (a measure of disorder or randomness) of an isolated system always increases over time. Because of this, heat will always naturally flow from a hotter object to a colder one, never the reverse. Energy transfers are never 100% efficient; some energy is always lost as unusable heat.\n* **In Simple Terms:** Things naturally get messier over time, and you can't even \"break even\" when transferring energy.\n* **Everyday Example:** If you leave a hot cup of coffee on a table, it will eventually cool down until it matches room temperature. The heat spreads out and dissipates. You will never see a cold cup of coffee spontaneously absorb heat from the room and start boiling. \n\n### 3. The Third Law: Absolute Zero\n* **The Concept:** As the temperature of a system approaches **absolute zero** (0 Kelvin, or -273.15°C / -459.67°F), the entropy (disorder) of the system approaches a constant minimum. At absolute zero, all atomic and molecular movement essentially stops.\n* **In Simple Terms:** Things stop moving when it gets as cold as physically possible. \n* **Everyday Example:** It is practically impossible to reach absolute zero, but scientists use this law to understand how materials behave at extreme extremes. For instance, creating superconductors (materials with zero electrical resistance) requires cooling them to near absolute zero so that atomic vibrations don't interfere with the flow of electricity.\n\n---\n\n### *Bonus: The Zeroth Law*\nWait, a zeroth law? Yes! Scientists realized later that there was a foundational rule they assumed to be true but never formally stated. Because the 1st, 2nd, and 3rd laws were already established, they named this the \"Zeroth\" law so it would logically come first.\n* **The Concept:** If System A and System B are both the same temperature as System C, then System A and System B must be the same temperature as each other. (This law establishes the basis for how thermometers work!).\n\n---\n\n### The Famous \"Gambler's Analogy\"\nTo make these laws easy to remember, physicists sometimes summarize them like a rigged game of cosmic poker:\n* **1st Law:** You can't win; you can only break even. *(Energy is conserved).*\n* **2nd Law:** You can't even break even; you will always lose. *(Entropy increases; energy is lost as heat).*\n* **3rd Law:** You can't quit the game. *(You can never reach absolute zero).*",
"thoughtSignature": "AY89a1/mzPPEB3bA2mYWlkUG2i6xMLFvYsFyQGy7S3UQZOmS1FzmQMYcVF8snadCQSwKEDNyaDvL0fME2MO+2Qdr1P1sybyvpRXP1n7wyNoQ7Vo87CA3r2rXwgf5DHYsbHGacpWDke8JehjP2AvszzRTxATnCJjOpEGpm34Zu1CZ9JVoofl9x9OrwR7NcDG58zxfReldaXXeWDxiIzu6A40GZTL5bjLD4U1+EGFB22Y9h2ZE1zbkE56Sp7svRNexbEYAZMsFxj5AUStb7ZQ5ymBrTLjHQ+AS7040NWzfzsfuJaRJ1TWjJO3W8hnCj7fqY9OsHivvFHgtKV5wNtWnqY4j9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AXZWnpJ8FwK1umnQwtJRrkIwHlunQXlBrZ5FK5FiZDFTDB6NohFetM3U="
}
]
},
"finishReason": "STOP"
}
],
"usageMetadata": {
"promptTokenCount": 8,
"candidatesTokenCount": 750,
"totalTokenCount": 1778,
"trafficType": "ON_DEMAND",
"promptTokensDetails": [
{
"modality": "TEXT",
"tokenCount": 8
}
],
"candidatesTokensDetails": [
{
"modality": "TEXT",
"tokenCount": 750
}
],
"thoughtsTokenCount": 1020
},
"modelVersion": "gemini-3.1-pro-preview",
"createTime": "2026-07-14T02:13:05.948743Z",
"responseId": "MZtVaof0Of-w3dAPzO-q6Qk",
"gatewayMetadata": {
"keySource": "Unified"
}
}With System Instruction — Using a system instruction to set context
const response = await env.AI.run(
'google/gemini-3.1-pro',
{
contents: [{ parts: [{ text: 'How do I read a JSON file in Python?' }], role: 'user' }],
generationConfig: { temperature: 0.3 },
systemInstruction: {
parts: [{ text: 'You are a helpful coding assistant specializing in Python.' }],
},
},
)
console.log(response)curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "google/gemini-3.1-pro",
"input": {
"contents": [
{
"parts": [
{
"text": "How do I read a JSON file in Python?"
}
],
"role": "user"
}
],
"generationConfig": {
"temperature": 0.3
},
"systemInstruction": {
"parts": [
{
"text": "You are a helpful coding assistant specializing in Python."
}
]
}
}
}'To read a JSON file in Python, you can use the built-in **`json`** module.
Here is the standard and safest way to do 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)
```
### Breakdown of the code:
1. **`import json`**: Imports Python's built-in JSON library.
2. **`with open(...) as file:`**: This is the best practice for opening files. It ensures that the file is automatically closed after you are done with it, even if an error occurs.
3. **`encoding='utf-8'`**: It is highly recommended to specify the encoding to prevent errors if your JSON file contains special characters or emojis.
4. **`json.load(file)`**: This function reads the file and converts the JSON data into a Python object (usually a dictionary or a list).
---
### Best Practice: Adding Error Handling
If you are writing code for a real application, it's a good idea to handle potential errors, such as the file not existing or the JSON being formatted incorrectly:
```python
import json
try:
with open('data.json', 'r', encoding='utf-8') as file:
data = json.load(file)
print(data)
except FileNotFoundError:
print("The file was not found.")
except json.JSONDecodeError:
print("The file does not contain valid JSON.")
```
### 💡 Pro Tip: `load()` vs `loads()`
It is easy to confuse these two functions in the `json` module:
* Use **`json.load()`** (no 's') when reading directly from a **file**.
* Use **`json.loads()`** (with an 's' for **s**tring) when reading JSON data from a **Python string**.{
"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 standard and safest way to do 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### Breakdown of the code:\n1. **`import json`**: Imports Python's built-in JSON library.\n2. **`with open(...) as file:`**: This is the best practice for opening files. It ensures that the file is automatically closed after you are done with it, even if an error occurs.\n3. **`encoding='utf-8'`**: It is highly recommended to specify the encoding to prevent errors if your JSON file contains special characters or emojis.\n4. **`json.load(file)`**: This function reads the file and converts the JSON data into a Python object (usually a dictionary or a list).\n\n---\n\n### Best Practice: Adding Error Handling\nIf you are writing code for a real application, it's 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\ntry:\n with open('data.json', 'r', encoding='utf-8') as file:\n data = json.load(file)\n print(data)\n \nexcept FileNotFoundError:\n print(\"The file was not found.\")\nexcept json.JSONDecodeError:\n print(\"The file does not contain valid JSON.\")\n```\n\n### 💡 Pro Tip: `load()` vs `loads()`\nIt is easy to confuse these two functions in the `json` module:\n* Use **`json.load()`** (no 's') when reading directly from a **file**.\n* Use **`json.loads()`** (with an 's' for **s**tring) when reading JSON data from a **Python string**.",
"thoughtSignature": "AY89a1+k76zp6wgdt8PwBfqbBrrTyd89P+CSMhvvzO6jVdHN+9W6IXkpPQR82khPPZ6cUQKvYZHkLUdbE20ocz2nd2whCscMSOCx4+FP4q/SvWCu0JOS3KE7pSxRPkCJd2u5EVvrygv3PMAz8BtBbbaUHVUgqZKkLqyq8GVpNTT4MvTMoHhSTHX1T+exTsXSZgakf88+NcpHU/jUzEOori4IT7MMwMVTxO3V4lcabFpYVh7YoVpMWApznyglWb0IQp3MlO+j9NrmAVR+SQmu+qwQjqU23rtrl05WWkfr/CFHaZA3qoTIsTpSRBbry6YfHT4xCrRoZOcQdsDnsiZtGxZxmYXOeDnA8l63flHfUxAKYkHwGEo7BtDtUkNOHyKbdPJLhHl1FJ4adssEfCowI2kbzCal4n25i9hDwmnriJ/TozF41URFwPDA3z7FvGXG1rXb8PY6e9e/JKQXWaOjER5wnb0QOzkPOVArP8EV6ZsldT1QnfhDu9Xm0j8g4Y4aoFW5rJIB9AaiAsIFTFud6HPR9daPUDVs85xqOcyn/ug58mYHdH31FMKl6K8epxYB7GnZRztc4gQWGpkNJDYB3m8wbfvo9Fw1XMo53uWdErQALbA0z6EM/LR6wfctmhPrXjI0o/IEezVEl8mVQzMHQqltcrOtAIiP8bI/jQzLwLvzB5oYNdyKqCqaGIVlbuMSJaXE8Ro56/vwQv43xL5v3oKuOeSZEdkNwJCRGNmt9RKOpN8YhgKdN9mupoCnnR3XXVh0DEo5N5QurcQ1Z1qH0xWBRr4WAiNvcNBu+c+rArifUlpANDAWPf51vHfAkXGvnMVdxUBFg6lkJT0KRSSSeKNYPOdvl/6T8OYnwnqGpu00MnzM91bmSsXE/1/8e0g6qSJnib1BmTr8X6WWa0h2JmCSpXecJstY9cVmExy9rDg8A43N1yzZFjdtb7RP7DfH9W3UX91gTVou7r+P5SXmYfhic/cO9vH3o6mwNw5JRSzoCjy2WIQlXRPBOWvdRDOVCBDoyFtMS91ZHVkh5jr1+lx+VRx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/B75rXs+7C1uEPrcomYa0CV4ExkDDN8QNzZTG4u3lTmGiTWoeipdoMUQOWuPo536MFs64Wuc4Qd0bE92SBBuiKUYZMecGqVLHJqhT7+j8e4vpr+2+ZyramNbybltMl7pTLffcBiKHs7kaoSBQKe2f4v7tn6ap3P3VqN1JwOCnFrvVu3FNkC2Cz//nqjBp/3ssKwRjqybKBG0yME+isdrgZLU48gLFYAgrYuIKCt3cXmhccPmUk1eMpfbcSE5FC8gZMz0KPAP8QJBHLL3pajRXWCRutjHi+cHgad/mqN4On1vZjCXQekSp3vHO0MMlnzObR/xG66cjgkn76tPoJLuksWzd8P5WS5qWMvvKLzOaeGLWMQglFOd88uzAYQAAGmBXtRxVQHXZXhyzsnZST675KceJO3S/rZ4fofaNIaEVqqXCDgUmZLeDX6P3wEATHUqV3dZIlNy3DuqiWuvBuQqoR/1bdWbBcodbSF+gT90XbSOf7IERGWxzKBTsaSsTUdFp4Lr9K7Cq9LY4JKG1foiuIyf2RVF2GRE+Ig6T7az+vuxLsjrSoO4P48NgqWTHy+gGrbMgZGtZVeUE9X0ckR8JvfwkL6wLhB1/ATqqDBU7Cy4L52mkQR/mU2p7w+OShDTHTcZxRlwArrIGm/8TUb1GbYdde2fhm+ft8VQseU98KwoZvIL2n4gIa9/NDY2crNh/dV+JkrDoEA+RnHGD6QKAdNy2l+AG0UzKJEqbnHLgmwOlNe7zcA6C9tJ7oOGesPxKc0LdsObRspLcZMOsf7B0h64C3geT2rM+6ua2fPhC1glqsly55TOLRbHgu2P4P44Yu/3+bh/bXXzaP/xt2Wwq3kkGWTn6ohZsYTGZ0PdHDSLrHGgJsi18XGNA=="
}
]
},
"finishReason": "STOP"
}
],
"usageMetadata": {
"promptTokenCount": 20,
"candidatesTokenCount": 462,
"totalTokenCount": 1060,
"trafficType": "ON_DEMAND",
"promptTokensDetails": [
{
"modality": "TEXT",
"tokenCount": 20
}
],
"candidatesTokensDetails": [
{
"modality": "TEXT",
"tokenCount": 462
}
],
"thoughtsTokenCount": 578
},
"modelVersion": "gemini-3.1-pro-preview",
"createTime": "2026-07-14T02:13:22.321177Z",
"responseId": "QptVapnNE8WW3dAP2MmH4Aw",
"gatewayMetadata": {
"keySource": "Unified"
}
}Multi-turn Conversation — Continuing a conversation with context
const response = await env.AI.run(
'google/gemini-3.1-pro',
{
contents: [
{
parts: [{ text: 'I need help planning a road trip from San Francisco to Los Angeles.' }],
role: 'user',
},
{
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: 'model',
},
{ parts: [{ text: 'Yes, what are some good places to stop?' }], role: 'user' },
],
generationConfig: { maxOutputTokens: 2048 },
},
)
console.log(response)curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "google/gemini-3.1-pro",
"input": {
"contents": [
{
"parts": [
{
"text": "I need help planning a road trip from San Francisco to Los Angeles."
}
],
"role": "user"
},
{
"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": "model"
},
{
"parts": [
{
"text": "Yes, what are some good places to stop?"
}
],
"role": "user"
}
],
"generationConfig": {
"maxOutputTokens": 2048
}
}
}'The best places to stop really depend on which route you decide to take. The 5-6 hour drive I mentioned earlier is via the fastest route (Interstate 5), but if you have more time, the coastal routes are world-famous. Here are the three main routes and the best stops for each: **1. The Fast Route (Interstate 5)** *Time: ~5.5 to 6 hours (pure driving)* This route cuts straight through the central valley. It's not very scenic, but it's efficient. * **Harris Ranch (Coalinga):** About halfway between SF and LA, this is a famous steakhouse, BBQ spot, and hotel. It’s the ultimate I-5 pit stop for a good meal. * **Kettleman City:** A major rest area with tons of fast food options (including a popular In-N-Out Burger) and gas stations. * **Tejon Ranch Outlets:** Located right before you hit the mountains into LA, it's a good place to stretch your legs, use the restroom, and do some shopping. **2. The Best of Both Worlds (US Highway 101)** *Time: ~6.5 to 7.5 hours (pure driving)* This route rolls through beautiful farmland, oak hills, wine country, and touches the coast towards the end. * **Paso Robles:** A fantastic halfway point. It’s a slightly more laid-back (and affordable) wine country compared to Napa, with a great downtown square full of restaurants. * **San Luis Obispo (SLO):** A charming college town. Stop by the famously quirky, hot-pink **Madonna Inn** for a slice of cake, or visit the historic downtown. * **Santa Barbara:** Known as the "American Riviera." It features gorgeous Spanish-style architecture, a beautiful palm-lined beach, and great seafood on Stearns Wharf. **3. The Ultimate Scenic Route (Highway 1 / Pacific Coast Highway)** *Time: 9-10+ hours (Best done over 2 days)* This is the famous coastal drive. *(Note: Always check Caltrans for road closures before taking this route, as landslides occasionally close portions of the road in Big Sur).* * **Monterey & Carmel-by-the-Sea:** Visit the world-class Monterey Bay Aquarium, drive the scenic "17-Mile Drive," and grab coffee in the fairytale-like village of Carmel. * **Big Sur:** The most dramatic coastline in the US. Must-stops include the **Bixby Creek Bridge** (you'll recognize it from a million photos) and **McWay Falls**, a waterfall that drops right onto the beach. * **San Simeon:** Home to the extravagant **Hearst Castle** (book tickets in advance) and a massive, noisy, and entertaining Elephant Seal rookery right on the beach. * **Morro Bay:** Famous for the massive "Morro Rock" sitting in the harbor. Great spot for clam chowder. **How to decide:** * Are you trying to do this drive in a single day, or do you have time to stay overnight somewhere? * What are you most interested in: beaches, food, wine, or weird roadside attractions? Let me know and we can narrow it down to the perfect itinerary!
{
"candidates": [
{
"content": {
"role": "model",
"parts": [
{
"text": "The best places to stop really depend on which route you decide to take. The 5-6 hour drive I mentioned earlier is via the fastest route (Interstate 5), but if you have more time, the coastal routes are world-famous. \n\nHere are the three main routes and the best stops for each:\n\n**1. The Fast Route (Interstate 5)**\n*Time: ~5.5 to 6 hours (pure driving)*\nThis route cuts straight through the central valley. It's not very scenic, but it's efficient. \n* **Harris Ranch (Coalinga):** About halfway between SF and LA, this is a famous steakhouse, BBQ spot, and hotel. It’s the ultimate I-5 pit stop for a good meal.\n* **Kettleman City:** A major rest area with tons of fast food options (including a popular In-N-Out Burger) and gas stations.\n* **Tejon Ranch Outlets:** Located right before you hit the mountains into LA, it's a good place to stretch your legs, use the restroom, and do some shopping.\n\n**2. The Best of Both Worlds (US Highway 101)**\n*Time: ~6.5 to 7.5 hours (pure driving)*\nThis route rolls through beautiful farmland, oak hills, wine country, and touches the coast towards the end.\n* **Paso Robles:** A fantastic halfway point. It’s a slightly more laid-back (and affordable) wine country compared to Napa, with a great downtown square full of restaurants.\n* **San Luis Obispo (SLO):** A charming college town. Stop by the famously quirky, hot-pink **Madonna Inn** for a slice of cake, or visit the historic downtown. \n* **Santa Barbara:** Known as the \"American Riviera.\" It features gorgeous Spanish-style architecture, a beautiful palm-lined beach, and great seafood on Stearns Wharf. \n\n**3. The Ultimate Scenic Route (Highway 1 / Pacific Coast Highway)**\n*Time: 9-10+ hours (Best done over 2 days)*\nThis is the famous coastal drive. *(Note: Always check Caltrans for road closures before taking this route, as landslides occasionally close portions of the road in Big Sur).*\n* **Monterey & Carmel-by-the-Sea:** Visit the world-class Monterey Bay Aquarium, drive the scenic \"17-Mile Drive,\" and grab coffee in the fairytale-like village of Carmel.\n* **Big Sur:** The most dramatic coastline in the US. Must-stops include the **Bixby Creek Bridge** (you'll recognize it from a million photos) and **McWay Falls**, a waterfall that drops right onto the beach.\n* **San Simeon:** Home to the extravagant **Hearst Castle** (book tickets in advance) and a massive, noisy, and entertaining Elephant Seal rookery right on the beach.\n* **Morro Bay:** Famous for the massive \"Morro Rock\" sitting in the harbor. Great spot for clam chowder.\n\n**How to decide:**\n* Are you trying to do this drive in a single day, or do you have time to stay overnight somewhere? \n* What are you most interested in: beaches, food, wine, or weird roadside attractions? \n\nLet me know and we can narrow it down to the perfect itinerary!",
"thoughtSignature": "AY89a18mpueAH0ufyXN4NhH9ESNaVR39mazkibsTbHc4Pxpwg0or4AWocZ2AoAlLwVfkoLvFFoiIYlLDokQ+EaNg2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4p3hQS6du6r2aKGWo9UsXDkjpI2lqNcNmymv+vo9V8o3QeJ8zGXq5c5XikmPjrQ4bEPhoED4wkgt0blkFWvciCnBH7K+U7pwn30Gofsa7r0ge+QUpPwKT26pQS2zATMXQxsL19qVpCEA1hjO0R4u8+Qwuy7ldd3LfGvUyuo5AUIYWnp8iyV0Wqc9ONp6EamlL9G7lkvq1hoejlW8gUgdWhFAKSTbD3587sR3oSuJS0QQb7FQk9XHBDsNjqqTWlwrHQp1xXjg6hkI2gRSLIZNxge1B4UhZv6tRCtbYKeU"
}
]
},
"finishReason": "STOP"
}
],
"usageMetadata": {
"promptTokenCount": 64,
"candidatesTokenCount": 725,
"totalTokenCount": 1726,
"trafficType": "ON_DEMAND",
"promptTokensDetails": [
{
"modality": "TEXT",
"tokenCount": 64
}
],
"candidatesTokensDetails": [
{
"modality": "TEXT",
"tokenCount": 725
}
],
"thoughtsTokenCount": 937
},
"modelVersion": "gemini-3.1-pro-preview",
"createTime": "2026-07-14T02:13:32.346531Z",
"responseId": "TJtVaqOTFYSNu-gPqLui2AY",
"gatewayMetadata": {
"keySource": "Unified"
}
}Creative Writing — Higher temperature for creative output
const response = await env.AI.run(
'google/gemini-3.1-pro',
{
contents: [
{
parts: [{ text: 'Write a short story opening about a detective finding an unusual clue.' }],
role: 'user',
},
],
generationConfig: { maxOutputTokens: 1500, temperature: 0.8 },
},
)
console.log(response)curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "google/gemini-3.1-pro",
"input": {
"contents": [
{
"parts": [
{
"text": "Write a short story opening about a detective finding an unusual clue."
}
],
"role": "user"
}
],
"generationConfig": {
"maxOutputTokens": 1500,
"temperature": 0.8
}
}
}'▶contents[]
arrayrequired▶systemInstruction{}
object▶generationConfig{}
object▶safetySettings[]
array▶tools[]
arraytoolConfig
▶messages[]
arrayrequiredtemperature
numberminimum: 0maximum: 2max_tokens
numberexclusiveMinimum: 0max_completion_tokens
numberexclusiveMinimum: 0top_p
numberminimum: 0maximum: 1frequency_penalty
numberminimum: -2maximum: 2presence_penalty
numberminimum: -2maximum: 2stream
boolean▶stream_options{}
object▶tools[]
arraytool_choice
response_format
▶modalities[]
array▶audio{}
object▶candidates[]
array▶usageMetadata{}
objectmodelVersion
stringid
stringobject
stringcreated
numbermodel
string▶choices[]
array▶usage{}
object