Grok 4.5
Text Generation • xAI
xai/grok-4.5
- Third-party
- Zero data retention
xAI's Grok 4.5, a frontier model built for coding, agentic tasks, and knowledge work. Accepts text and image inputs, and supports function calling, structured outputs, and configurable reasoning effort (low, medium, high).
| Model Info | |
|---|---|
| Context Window ↗ | 500,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.30</li><li>Output <200k (per 1M)$6.00</li><li>Input >=200k (per 1M)$4.00</li><li>Cached input >=200k (per 1M)$0.60</li><li>Output >=200k (per 1M)$12.00</li></ul> |
Usage
const response = await env.AI.run(
'xai/grok-4.5',
{ 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.5",
"messages": [
{
"content": "What are the three laws of thermodynamics?",
"role": "user"
}
]
}'
**First Law (Conservation of Energy):**
The total energy of an isolated system is constant. Energy can be transformed from one form to another (e.g., heat into work) but cannot be created or destroyed. For a closed thermodynamic system this is commonly expressed as
\[
\Delta U = Q - W
\]
(where \(\Delta U\) is the change in internal energy, \(Q\) is heat added to the system, and \(W\) is work done by the system; sign conventions can vary).
**Second Law (Entropy / Direction of Processes):**
The entropy of an isolated system never decreases; spontaneous processes increase the total entropy of the universe. Equivalent classical statements include:
- Heat does not spontaneously flow from a colder body to a hotter body (Clausius).
- It is impossible to convert heat completely into work in a cyclic process without other effects (Kelvin–Planck).
This law introduces the thermodynamic arrow of time and the concept of irreversible processes.
**Third Law (Nernst Heat Theorem / Absolute Zero):**
As the temperature of a system approaches absolute zero (0 K), the entropy approaches a minimum value (commonly taken as zero for a perfect crystalline substance). A practical consequence is that absolute zero is unattainable in a finite number of thermodynamic processes.
(Note: A “zeroth” law is also recognized—systems in thermal equilibrium with a third system are in equilibrium with each other, defining temperature—but it is not counted among the classical three laws.)
These laws form the foundation of classical thermodynamics and constrain all macroscopic energy-conversion processes.
{
"id": "02cf6d3a-3354-9195-bdb5-199a2c5a88b2",
"object": "chat.completion",
"created": 1784118519,
"model": "grok-4.5",
"choices": [
{
"index": 0,
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": "**First Law (Conservation of Energy):** \nThe total energy of an isolated system is constant. Energy can be transformed from one form to another (e.g., heat into work) but cannot be created or destroyed. For a closed thermodynamic system this is commonly expressed as \n\\[\n\\Delta U = Q - W\n\\] \n(where \\(\\Delta U\\) is the change in internal energy, \\(Q\\) is heat added to the system, and \\(W\\) is work done by the system; sign conventions can vary).\n\n**Second Law (Entropy / Direction of Processes):** \nThe entropy of an isolated system never decreases; spontaneous processes increase the total entropy of the universe. Equivalent classical statements include: \n- Heat does not spontaneously flow from a colder body to a hotter body (Clausius). \n- It is impossible to convert heat completely into work in a cyclic process without other effects (Kelvin–Planck). \n\nThis law introduces the thermodynamic arrow of time and the concept of irreversible processes.\n\n**Third Law (Nernst Heat Theorem / Absolute Zero):** \nAs the temperature of a system approaches absolute zero (0 K), the entropy approaches a minimum value (commonly taken as zero for a perfect crystalline substance). A practical consequence is that absolute zero is unattainable in a finite number of thermodynamic processes.\n\n(Note: A “zeroth” law is also recognized—systems in thermal equilibrium with a third system are in equilibrium with each other, defining temperature—but it is not counted among the classical three laws.)\n\nThese laws form the foundation of classical thermodynamics and constrain all macroscopic energy-conversion processes.",
"reasoning_content": "The question is: \"What are the three laws of thermodynamics?\"\nThe three laws of thermodynamics are:\n\n1. **First Law**: Energy is conserved. In any process, the total energy of an isolated system remains constant; it can only change form (e.g., heat to work).",
"refusal": null
}
}
],
"service_tier": "default",
"system_fingerprint": "fp_a39489019fa99b6e",
"usage": {
"prompt_tokens": 214,
"completion_tokens": 323,
"total_tokens": 924,
"prompt_tokens_details": {
"text_tokens": 214,
"audio_tokens": 0,
"image_tokens": 0,
"cached_tokens": 128
},
"completion_tokens_details": {
"reasoning_tokens": 387,
"audio_tokens": 0,
"accepted_prediction_tokens": 0,
"rejected_prediction_tokens": 0
},
"cost_in_usd_ticks": 44960000,
"num_sources_used": 0
},
"gatewayMetadata": {
"keySource": "Unified"
}
}
Examples
<details>
<summary>With System Message — Using a system message to set context</summary>
const response = await env.AI.run(
'xai/grok-4.5',
{
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.5",
"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"
}
]
}'
To read a JSON file in Python, use the built-in `json` module:
```python
import json
with open("data.json", "r", encoding="utf-8") as f:
data = json.load(f)
print(data)
```
### Notes
- `json.load(f)` reads from a file object and returns a Python object (`dict`, `list`, etc.).
- Prefer `with open(...)` so the file is closed automatically.
- Use `encoding="utf-8"` for reliable handling of non-ASCII text.
### If you already have a JSON string
```python
import json
json_string = '{"name": "Alice", "age": 30}'
data = json.loads(json_string)
```
### Basic error handling
```python
import json
try:
with open("data.json", "r", encoding="utf-8") as f:
data = json.load(f)
except FileNotFoundError:
print("File not found")
except json.JSONDecodeError as e:
print(f"Invalid JSON: {e}")
```
{
"id": "e5c0b732-b377-9257-a707-558da370c135",
"object": "chat.completion",
"created": 1784118525,
"model": "grok-4.5",
"choices": [
{
"index": 0,
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": "To read a JSON file in Python, use the built-in `json` module:\n\n```python\nimport json\n\nwith open(\"data.json\", \"r\", encoding=\"utf-8\") as f:\n data = json.load(f)\n\nprint(data)\n```\n\n### Notes\n- `json.load(f)` reads from a file object and returns a Python object (`dict`, `list`, etc.).\n- Prefer `with open(...)` so the file is closed automatically.\n- Use `encoding=\"utf-8\"` for reliable handling of non-ASCII text.\n\n### If you already have a JSON string\n```python\nimport json\n\njson_string = '{\"name\": \"Alice\", \"age\": 30}'\ndata = json.loads(json_string)\n```\n\n### Basic error handling\n```python\nimport json\n\ntry:\n with open(\"data.json\", \"r\", encoding=\"utf-8\") as f:\n data = json.load(f)\nexcept FileNotFoundError:\n print(\"File not found\")\nexcept json.JSONDecodeError as e:\n print(f\"Invalid JSON: {e}\")\n```",
"reasoning_content": "The user is asking how to read a JSON file in Python. This is a straightforward coding question. I should provide a clear, helpful answer with code examples.\n",
"refusal": null
}
}
],
"service_tier": "default",
"system_fingerprint": "fp_a39489019fa99b6e",
"usage": {
"prompt_tokens": 229,
"completion_tokens": 237,
"total_tokens": 570,
"prompt_tokens_details": {
"text_tokens": 229,
"audio_tokens": 0,
"image_tokens": 0,
"cached_tokens": 128
},
"completion_tokens_details": {
"reasoning_tokens": 104,
"audio_tokens": 0,
"accepted_prediction_tokens": 0,
"rejected_prediction_tokens": 0
},
"cost_in_usd_ticks": 23120000,
"num_sources_used": 0
},
"gatewayMetadata": {
"keySource": "Unified"
}
}
</details>
<details>
<summary>Multi-turn Conversation — Continuing a conversation with context</summary>
const response = await env.AI.run(
'xai/grok-4.5',
{
max_completion_tokens: 8192,
messages: [
{
content: 'I need help planning a road trip from San Francisco to Los Angeles.',
role: 'user',
},
{
content:
"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: 'assistant',
},
{ content: 'Yes, what are some good places to stop?', 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.5",
"max_completion_tokens": 8192,
"messages": [
{
"content": "I need help planning a road trip from San Francisco to Los Angeles.",
"role": "user"
},
{
"content": "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": "assistant"
},
{
"content": "Yes, what are some good places to stop?",
"role": "user"
}
]
}'
``` Great choice—there are tons of excellent stops depending on whether you take the faster inland route (I-5, ~5–6 hours) or the scenic coastal route (Highway 1 / Pacific Coast Highway, ~8–10+ hours with stops).
Most people planning a fun road trip prefer the coastal route for the views and variety. Here are some of the best places to stop (roughly north to south):
Top Recommended Stops (Coastal Route via Hwy 1)
- Monterey / Carmel-by-the-Sea (about 2 hours from SF)
-
Walk Cannery Row, visit the Monterey Bay Aquarium, or stroll the charming village of Carmel. Great for a coffee, lunch, or short hike.
-
Big Sur (highlight of the drive)
-
Iconic stops: Bixby Creek Bridge viewpoint, McWay Falls (waterfall onto the beach), and pullouts for dramatic ocean cliffs. Allow extra time—roads can be winding and parking limited. Pfeiffer Beach or Julia Pfeiffer Burns State Park are worth it if you have time.
-
Hearst Castle (San Simeon)
-
Tour the opulent hilltop estate of William Randolph Hearst. Book tickets ahead if possible. Nearby elephant seal viewing at Piedras Blancas is free and fascinating.
-
San Luis Obispo / Pismo Beach / Avila Beach
-
SLO has a fun downtown, bubblegum alley, and good food. Pismo is classic California beach vibes (dunes, pier). Great mid-trip stretch and meal stop.
-
Santa Barbara
- Beautiful Spanish-style downtown, State Street, waterfront, and nearby wine tasting in the Santa Ynez Valley if you detour a bit. Perfect last major stop before LA (about 1.5–2 hours remaining).
Other Solid Options
- Santa Cruz (early stop) – Boardwalk, surfing vibe, or nearby redwoods.
- Paso Robles (if you cut inland a bit via Hwy 46) – Excellent wine country for tastings.
- Solvang (near Santa Barbara) – Quaint Danish-themed town with bakeries and windmills.
- Quick nature hits: Point Lobos State Natural Reserve (near Carmel) or Elephant Seal Rookery.
Practical Tips
- Timing: Start early from SF to enjoy daylight in Big Sur. The full coastal drive with a few stops easily fills a full day (or make it overnight in SLO/Pismo/Santa Barbara).
- Food: Fresh seafood in Monterey, burgers or farm-to-table in SLO, tacos or wine-country bites farther south.
- Gas & rest: Fill up before Big Sur (limited services). Traffic can build near LA, especially weekends.
- Alternatives: Pure I-5 is faster but boring (mostly Central Valley farmland). A hybrid (I-5 partway then cut over to the coast) works if you’re short on time.
- Check road conditions—Hwy 1 in Big Sur occasionally has closures due to slides.
