Gemini 3.1 Flash Lite
Text Generation • Google
google/gemini-3.1-flash-lite
- Third-party
- Zero data retention
Google's lightest and most cost-efficient Gemini model for high-throughput tasks.
| 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)$0.25</li><li>Cached input <=200k (per 1M)$0.03</li><li>Output <=200k (per 1M)$1.50</li><li>Input >200k (per 1M)$0.25</li><li>Cached input >200k (per 1M)$0.03</li><li>Output >200k (per 1M)$1.50</li></ul> |
Usage
const response = await env.AI.run(
'google/gemini-3.1-flash-lite',
{ 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-flash-lite",
"input": {
"contents": [
{
"parts": [
{
"text": "What are the three laws of thermodynamics?"
}
],
"role": "user"
}
]
}
}'
The three laws of thermodynamics (along with the "zeroth" law, which is foundational) describe how energy moves, transforms, and behaves in physical systems.
Here is a breakdown of the laws:
### 0. The Zeroth Law (The Law of Equilibrium)
Before the first three were established, scientists realized there needed to be a rule about temperature.
* **The Law:** If two systems are each in thermal equilibrium with a third system, they are in thermal equilibrium with each other.
* **What it means:** This is the scientific basis for the thermometer. It allows us to define "temperature" as a measurable property.
---
### 1. The First Law (The Law of Conservation of Energy)
* **The Law:** Energy cannot be created or destroyed in an isolated system; it can only be transferred or converted from one form to another.
* **What it means:** The total amount of energy in the universe is constant. If you put energy into a system (as heat or work), it must either increase the system's internal energy or be released as work. You cannot get more energy out of a system than you put into it (this rules out "perpetual motion machines of the first kind").
---
### 2. The Second Law (The Law of Entropy)
* **The Law:** The total entropy (disorder) of an isolated system can never decrease over time; it can only remain constant or increase.
* **What it means:** Heat always flows naturally from a hotter object to a colder object, never the other way around unless external work is performed. Because energy spreads out and becomes less "useful" (it degrades into heat), no process is 100% efficient. This law provides an "arrow of time," explaining why things break down rather than spontaneously putting themselves back together.
---
### 3. The Third Law (The Law of Absolute Zero)
* **The Law:** As the temperature of a system approaches absolute zero (0 Kelvin), the entropy of a perfect crystal approaches zero.
* **What it means:** It is impossible to reach absolute zero through any finite number of processes. At absolute zero, all atomic motion stops, and the system reaches its state of minimum possible energy and perfect order.
***
### Summary for easy memory:
* **Zeroth Law:** You have to play by the rules (there is such a thing as temperature).
* **First Law:** You can't win (you can't create energy).
* **Second Law:** You can't break even (you always lose some energy to entropy).
* **Third Law:** You can't get out of the game (you can't reach absolute zero).
{
"candidates": [
{
"content": {
"role": "model",
"parts": [
{
"text": "The three laws of thermodynamics (along with the \"zeroth\" law, which is foundational) describe how energy moves, transforms, and behaves in physical systems.\n\nHere is a breakdown of the laws:\n\n### 0. The Zeroth Law (The Law of Equilibrium)\nBefore the first three were established, scientists realized there needed to be a rule about temperature.\n* **The Law:** If two systems are each in thermal equilibrium with a third system, they are in thermal equilibrium with each other.\n* **What it means:** This is the scientific basis for the thermometer. It allows us to define \"temperature\" as a measurable property.\n\n---\n\n### 1. The First Law (The Law of Conservation of Energy)\n* **The Law:** Energy cannot be created or destroyed in an isolated system; it can only be transferred or converted from one form to another.\n* **What it means:** The total amount of energy in the universe is constant. If you put energy into a system (as heat or work), it must either increase the system's internal energy or be released as work. You cannot get more energy out of a system than you put into it (this rules out \"perpetual motion machines of the first kind\").\n\n---\n\n### 2. The Second Law (The Law of Entropy)\n* **The Law:** The total entropy (disorder) of an isolated system can never decrease over time; it can only remain constant or increase.\n* **What it means:** Heat always flows naturally from a hotter object to a colder object, never the other way around unless external work is performed. Because energy spreads out and becomes less \"useful\" (it degrades into heat), no process is 100% efficient. This law provides an \"arrow of time,\" explaining why things break down rather than spontaneously putting themselves back together.\n\n---\n\n### 3. The Third Law (The Law of Absolute Zero)\n* **The Law:** As the temperature of a system approaches absolute zero (0 Kelvin), the entropy of a perfect crystal approaches zero.\n* **What it means:** It is impossible to reach absolute zero through any finite number of processes. At absolute zero, all atomic motion stops, and the system reaches its state of minimum possible energy and perfect order.\n\n***\n\n### Summary for easy memory:\n* **Zeroth Law:** You have to play by the rules (there is such a thing as temperature).\n* **First Law:** You can't win (you can't create energy).\n* **Second Law:** You can't break even (you always lose some energy to entropy).\n* **Third Law:** You can't get out of the game (you can't reach absolute zero).",
"thoughtSignature": "AY89a19nds/5ZNrEilIoIIOsW4vmEKmo5R0rba/I6ZZTI9ml+6YrCI65LXveEZ/d/f0="
}
]
},
"finishReason": "STOP"
}
],
"usageMetadata": {
"promptTokenCount": 8,
"candidatesTokenCount": 579,
"totalTokenCount": 587,
"trafficType": "ON_DEMAND",
"promptTokensDetails": [
{
"modality": "TEXT",
"tokenCount": 8
}
],
"candidatesTokensDetails": [
{
"modality": "TEXT",
"tokenCount": 579
}
]
},
"modelVersion": "gemini-3.1-flash-lite",
"createTime": "2026-07-21T16:29:03.710695Z",
"responseId": "T55faqewK4Wq8sYPycj20Q0",
"gatewayMetadata": {
"keySource": "Unified"
}
}
Examples
<details>
<summary>With System Instruction — Using a system instruction to set context</summary>
const response = await env.AI.run(
'google/gemini-3.1-flash-lite',
{
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-flash-lite",
"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 use the built-injson` module.
Here is the standard way to do it:
The Basic Approach
```python import json
