Grok 4.20 Reasoning
Text Generation • xAI
xai/grok-4.20-0309-reasoning
- Third-party
- Zero data retention
xAI's Grok 4.20 reasoning model. Uses extended thinking to work through complex problems, returning a reasoning trace alongside the final answer.
| Model Info | |
|---|---|
| Context Window ↗ | 2,000,000 tokens |
| Terms and License | link ↗ |
| More information | link ↗ |
| Zero data retention | Yes |
| Request formats | Chat Completions |
| Pricing | <ul><li>Input (per 1M tokens)$2.00</li><li>Output (per 1M tokens)$6.00</li><li>Cached input (per 1M tokens)$0.20</li></ul> |
Usage
const response = await env.AI.run(
'xai/grok-4.20-0309-reasoning',
{ messages: [{ content: 'What are the three laws of thermodynamics?', role: 'user' }] },
)
console.log(response)
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/v1/chat/completions \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "xai/grok-4.20-0309-reasoning",
"messages": [
{
"content": "What are the three laws of thermodynamics?",
"role": "user"
}
]
}'
**The Three Laws of Thermodynamics** (in plain language):
### 1. First Law (Conservation of Energy)
**Energy cannot be created or destroyed — only converted from one form to another.**
- In equation form: **ΔU = Q − W**
- ΔU = change in the system’s internal energy
- Q = heat added to the system
- W = work done *by* the system
This is basically the law of conservation of energy applied to thermodynamic systems. If you add heat to a gas, that energy has to go somewhere — it can increase the gas’s temperature (internal energy) or be used to push a piston (work).
### 2. Second Law (Entropy and Directionality)
**The entropy (disorder) of an isolated system always increases over time.**
Key implications:
- Heat flows spontaneously from hot to cold, never the reverse.
- It is impossible to build a perfectly efficient heat engine (some energy is always “wasted” as heat).
- Processes have a natural direction; time has an arrow.
Popular statement: “You can’t even break even.” Every real process increases the total entropy of the universe.
### 3. Third Law (Absolute Zero)
**As the temperature of a system approaches absolute zero (0 K or −273.15 °C), its entropy approaches a minimum value (often zero for a perfect crystal).**
Key consequences:
- It is impossible to reach absolute zero in a finite number of steps.
- Many materials exhibit strange quantum behaviors near 0 K (superconductivity, superfluidity, etc.).
---
### Bonus: The Zeroth Law (The “Temperature Law”)
Although not one of the original three, it’s so fundamental it was named *after* them:
**If two systems are each in thermal equilibrium with a third system, they are in thermal equilibrium with each other.**
This is what allows us to define temperature and use thermometers.
Would you like a more technical/deep-dive version of any of these laws?
{
"choices": [
{
"finish_reason": "stop",
"index": 0,
"message": {
"content": "**The Three Laws of Thermodynamics** (in plain language):\n\n### 1. First Law (Conservation of Energy)\n**Energy cannot be created or destroyed — only converted from one form to another.**\n\n- In equation form: **ΔU = Q − W**\n - ΔU = change in the system’s internal energy\n - Q = heat added to the system\n - W = work done *by* the system\n\nThis is basically the law of conservation of energy applied to thermodynamic systems. If you add heat to a gas, that energy has to go somewhere — it can increase the gas’s temperature (internal energy) or be used to push a piston (work).\n\n### 2. Second Law (Entropy and Directionality)\n**The entropy (disorder) of an isolated system always increases over time.**\n\nKey implications:\n- Heat flows spontaneously from hot to cold, never the reverse.\n- It is impossible to build a perfectly efficient heat engine (some energy is always “wasted” as heat).\n- Processes have a natural direction; time has an arrow.\n\nPopular statement: “You can’t even break even.” Every real process increases the total entropy of the universe.\n\n### 3. Third Law (Absolute Zero)\n**As the temperature of a system approaches absolute zero (0 K or −273.15 °C), its entropy approaches a minimum value (often zero for a perfect crystal).**\n\nKey consequences:\n- It is impossible to reach absolute zero in a finite number of steps.\n- Many materials exhibit strange quantum behaviors near 0 K (superconductivity, superfluidity, etc.).\n\n---\n\n### Bonus: The Zeroth Law (The “Temperature Law”)\nAlthough not one of the original three, it’s so fundamental it was named *after* them:\n\n**If two systems are each in thermal equilibrium with a third system, they are in thermal equilibrium with each other.**\n\nThis is what allows us to define temperature and use thermometers.\n\nWould you like a more technical/deep-dive version of any of these laws?",
"reasoning_content": "The question is: \"What are the three laws of thermodynamics?\"\nI know the three laws of thermodynamics are key principles in physics that govern energy, heat, and work in systems. The first law is about conservation of energy, stating that energy can't be created or destroyed, only transformed.",
"refusal": null,
"role": "assistant"
}
}
],
"created": 1777675707,
"gatewayMetadata": {
"keySource": "Unified"
},
"id": "7725e484-a7ee-ce42-45e7-89022b16e9ac",
"model": "grok-4.20-0309-reasoning",
"object": "chat.completion",
"system_fingerprint": "fp_7be90dd558",
"usage": {
"completion_tokens": 411,
"completion_tokens_details": {
"accepted_prediction_tokens": 0,
"audio_tokens": 0,
"reasoning_tokens": 382,
"rejected_prediction_tokens": 0
},
"cost_in_usd_ticks": 20803000,
"num_sources_used": 0,
"prompt_tokens": 132,
"prompt_tokens_details": {
"audio_tokens": 0,
"cached_tokens": 64,
"image_tokens": 0,
"text_tokens": 132
},
"total_tokens": 925
}
}
Examples
<details>
<summary>With System Message — Using a system message to set context</summary>
const response = await env.AI.run(
'xai/grok-4.20-0309-reasoning',
{
messages: [
{ content: 'You are a helpful coding assistant specializing in Python.', role: 'system' },
{ content: 'How do I read a JSON file in Python?', role: 'user' },
],
},
)
console.log(response)
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/v1/chat/completions \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "xai/grok-4.20-0309-reasoning",
"messages": [
{
"content": "You are a helpful coding assistant specializing in Python.",
"role": "system"
},
{
"content": "How do I read a JSON file in Python?",
"role": "user"
}
]
}'
```` Best way to read a JSON file in Python:
Method 1: Using json.load() (Recommended)
```python import json from pathlib import Path
