Gemini 3.1 Pro

Text Generation • Google

google/gemini-3.1-pro

  • 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 <ul><li>Input <=200k (per 1M)$2.00</li><li>Cached input <=200k (per 1M)$0.20</li><li>Output <=200k (per 1M)$12.00</li><li>Input >200k (per 1M)$4.00</li><li>Cached input >200k (per 1M)$0.40</li><li>Output >200k (per 1M)$18.00</li></ul>

Usage

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 describe how energy moves and changes form within physical systems. While the prompt asks for the "three" laws, there are actually four (scientists realized later that they needed a foundational law, which they named the "Zeroth" law). 

Here are the three main laws of thermodynamics, explained simply:

### **1. The First Law: The Law of Conservation of Energy**
* **The Concept:** Energy cannot be created or destroyed; it can only change forms or be transferred from one object to another.
* **What it means:** The total amount of energy in the universe is constant. For example, a car engine doesn't "create" energy to move the car; it converts the chemical energy stored in gasoline into mechanical energy (motion) and thermal energy (heat). 
* **The famous summary:** *"You can't get something for nothing."* (You cannot create energy out of thin air).

### **2. The Second Law: The Law of Entropy**
* **The Concept:** In any isolated system, the total **entropy** (disorder or randomness) will always increase over time. 
* **What it means:** Energy naturally disperses. This is why a hot cup of coffee will always cool down in a room, but a cold cup of coffee will never spontaneously absorb heat from the room to boil. Furthermore, because energy disperses, no energy transfer is 100% efficient. Whenever you convert energy from one form to another, some of it is always "lost" as unusable waste heat. 
* **The famous summary:** *"You can't even break even."* (Because of entropy, you will always lose some usable energy in any process).

### **3. The Third Law: Absolute Zero**
* **The Concept:** As the temperature of a system approaches **absolute zero** (0 Kelvin, or -273.15°C), the entropy of the system approaches a constant, minimum value. 
* **What it means:** Absolute zero is the theoretical point where all thermal energy is gone and the atoms stop moving entirely. The third law dictates that while we can get extremely close to absolute zero, it is physically impossible to actually reach it. 
* **The famous summary:** *"You can't get out of the game."* (You can never reach absolute zero, so there will always be *some* heat and entropy).

***

### **Bonus: The "Zeroth" Law**
Formulated after the first three laws were already established, scientists realized they needed a law to define temperature itself. Since it was the most fundamental, they called it the "Zeroth" Law.
* **The Concept:** 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 and System C must also be the same temperature.
* **What it means:** This seems obvious, but it is the foundational rule that allows thermometers to work!
{
  "candidates": [
    {
      "content": {
        "role": "model",
        "parts": [
          {
            "text": "The laws of thermodynamics describe how energy moves and changes form within physical systems. While the prompt asks for the \"three\" laws, there are actually four (scientists realized later that they needed a foundational law, which they named the \"Zeroth\" law). \n\nHere are the three main laws of thermodynamics, 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 change forms or be transferred from one object to another.\n* **What it means:** The total amount of energy in the universe is constant. For example, a car engine doesn't \"create\" energy to move the car; it converts the chemical energy stored in gasoline into mechanical energy (motion) and thermal energy (heat). \n* **The famous summary:** *\"You can't get something for nothing.\"* (You cannot create energy out of thin air).\n\n### **2. The Second Law: The Law of Entropy**\n* **The Concept:** In any isolated system, the total **entropy** (disorder or randomness) will always increase over time. \n* **What it means:** Energy naturally disperses. This is why a hot cup of coffee will always cool down in a room, but a cold cup of coffee will never spontaneously absorb heat from the room to boil. Furthermore, because energy disperses, no energy transfer is 100% efficient. Whenever you convert energy from one form to another, some of it is always \"lost\" as unusable waste heat. \n* **The famous summary:** *\"You can't even break even.\"* (Because of entropy, you will always lose some usable energy in any process).\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), the entropy of the system approaches a constant, minimum value. \n* **What it means:** Absolute zero is the theoretical point where all thermal energy is gone and the atoms stop moving entirely. The third law dictates that while we can get extremely close to absolute zero, it is physically impossible to actually reach it. \n* **The famous summary:** *\"You can't get out of the game.\"* (You can never reach absolute zero, so there will always be *some* heat and entropy).\n\n***\n\n### **Bonus: The \"Zeroth\" Law**\nFormulated after the first three laws were already established, scientists realized they needed a law to define temperature itself. Since it was the most fundamental, they called it the \"Zeroth\" Law.\n* **The Concept:** 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 and System C must also be the same temperature.\n* **What it means:** This seems obvious, but it is the foundational rule that allows thermometers to work!",
            "thoughtSignature": "AY89a197GECnMwUlM7wtji6/asWPmDOw31IcboL2qXHjETlhZBJfD5iMStj+z9+vySalZtJ1NQYfQF8JpOU7SnXTCMwSHOnVB4Ldz/M2rubkfi11yR+XetAYveyWbs12yboQ4Q2IuojZuBWhHcv5oW3XWzaw/d4xiCdrnmDaqN2BY3xHEaaXQuhVvGqsMJZcQoHGBmoOMupngIq1CGjIrpqVcDXKQ5d2ib99wWnr6zbkcuO9MlSnZQ5N9/9h5lXX62se9hIAiN9dXB5XAjbTfpudRIHsZick+tsJ19B3QF6opQQzTtVxwmuJviFAQMe3QA4CIfqQUhBkCdqs/dYMQ9TeYCUnpFOVDEh6a9qeXhmnPt1YspA3Uur942oQ6EB1uvFAoOMTjKFn/JvsP0+4Ip0/MuULcgfIGPLYo5pgtVa3eS4B9yBaaIq/RAUK2g8lgvjSZI7h7bshhHbIjL5IVExxGegnhy1dqOf/X1tWaRVydvAEQCNrF1wqDfxcUut0xPNVBtFOFMvDUOjiWbrxecTjLDfHe6XiLBQpzaSsAxIqiQFs1qobbqPwaghCHzkdFM5A8CMlG68d1R4P6uxgo7rQzwik1D4Yy4iwCDS9IX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hBN/D2r1VCA3GnQBz2NcqTSBMWtOqME2OVh6MgoYqM5WjkQXmuuMnR4PahMLBbmjS/DSy9VYlTZza8Ybz5sQB/6SxhX09CvpsBPyNpjG4/HZiJOFbzxd1uEbKV9BY9+X6uOJ+Fz60Lp0fG37idVqfzzkJ8pRd6eIf8q+Z5KFobTQWe+ZRd7PvmugPt3j7atAPU+MxgkH1su2jwShATGIvmLqwIwTMHa2v3Uuen0qo+9nD/JzKnzUY3SqIofbkqHsRi5SFvHu/swt3OxBkYmM2v2ajT1TI8kcaseI5EWOMpcvsHDSK23sV6dLEJWG54/hi87aEWABhW1DhRXupusCUwA3Tdgq4W12E3r1l4wP/WoKDzBjRu4juaYEtpq4mWdkTQchivrr+6sOqdi4QTiATX4+mdaQGzVcjMs+54zRC62OkYEokJ0SPSOtUPYJZWwUn2JzyeGBspGhKiywJr6aGI35yneGMDS6FvjMCtG+4V2H23oQovfRO1P1DGasDsbBORnw6vSCqibHIkvBdqTBbIK3ANYRvfgP+vuaFqaVwmNsd9LfEEuHNoxFqq9TtLDxbLmvzOVGdRGQ2XbgPbZwUsEsKVd+g3gbj8GcfXunnlvCKhIdGeHTsiYBX+ZX9nHQeGnZcfGTsyIscqZ2bPs7lT+cjm2GttZJZdSzAN+t6qCgyPmSOngDeY30ptMt47KRhg9mZutg8mFRkJH4hJPBXtqxW71+kF5CcPBBEfl9yi1fcnOcwjkAlT7NBg4eM+bbBTFgtJYio7QulEgQTbgHkJ/xVtMPJ5UtbjDnMot8f/VxmaemUJqr1m8o4gxtllh+RMy8cimG0Me53F+htJxqBRZh3RwEZxAfDcfxXLYxt7R42UNC++UammCA+HEjMr56jDXz9EP5kiuPucms3aG7OOD1MSg261udCCfa29pkQvulvwqCCkjBGlx02lwpPkxq49JX3mw7UjpODb3YA=="
          }
        ]
      },
      "finishReason": "STOP"
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 8,
    "candidatesTokenCount": 626,
    "totalTokenCount": 1489,
    "trafficType":
... response truncated ...

Examples

<details>

<summary>With System Instruction — Using a system instruction to set context</summary>

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 most standard and recommended way to do it:

```python import json