GPT-5
Text Generation • OpenAI
openai/gpt-5
- Third-party
- Zero data retention
OpenAI's model excelling at coding, writing, and reasoning.
| Model Info | |
|---|---|
| Context Window ↗ | 128,000 tokens |
| Terms and License | link ↗ |
| More information | link ↗ |
| Zero data retention | Yes |
| Request formats | Responses, Chat Completions |
| Pricing | <ul><li>Input (per 1M tokens)$1.25</li><li>Output (per 1M tokens)$10.00</li><li>Cached input (per 1M tokens)$0.125</li></ul> |
Usage
const response = await env.AI.run(
'openai/gpt-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": "openai/gpt-5",
"messages": [
{
"content": "What are the three laws of thermodynamics?",
"role": "user"
}
]
}'
- First law (energy conservation): The change in a system’s internal energy equals the heat added to the system minus the work done by the system. In symbols: ΔU = Q − W (with W defined as work done by the system).
- Second law (entropy increase): In any real process, the total entropy of an isolated system never decreases (ΔS ≥ 0). Equivalently, heat flows spontaneously from hot to cold and no heat engine can be 100% efficient.
- Third law (absolute zero/entropy): As temperature approaches 0 K, the entropy of a perfect crystalline substance approaches zero, and absolute zero cannot be reached in a finite number of steps.
Note: There is also a “zeroth law,” which defines temperature via thermal equilibrium.
{
"id": "chatcmpl-DpLAeLKqEscvTBF6Cy8PzvroAyj7Q",
"object": "chat.completion",
"created": 1781128480,
"model": "gpt-5-2025-08-07",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "- First law (energy conservation): The change in a system’s internal energy equals the heat added to the system minus the work done by the system. In symbols: ΔU = Q − W (with W defined as work done by the system).\n\n- Second law (entropy increase): In any real process, the total entropy of an isolated system never decreases (ΔS ≥ 0). Equivalently, heat flows spontaneously from hot to cold and no heat engine can be 100% efficient.\n\n- Third law (absolute zero/entropy): As temperature approaches 0 K, the entropy of a perfect crystalline substance approaches zero, and absolute zero cannot be reached in a finite number of steps.\n\nNote: There is also a “zeroth law,” which defines temperature via thermal equilibrium.",
"refusal": null,
"annotations": []
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 15,
"completion_tokens": 550,
"total_tokens": 565,
"prompt_tokens_details": {
"cached_tokens": 0,
"audio_tokens": 0
},
"completion_tokens_details": {
"reasoning_tokens": 384,
"audio_tokens": 0,
"accepted_prediction_tokens": 0,
"rejected_prediction_tokens": 0
}
},
"service_tier": "default",
"system_fingerprint": null,
"gatewayMetadata": {
"keySource": "Unified"
}
}
Examples
<details>
<summary>With System Message — Using a system message to set context</summary>
const response = await env.AI.run(
'openai/gpt-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": "openai/gpt-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"
}
]
}'
The built-in json module is the standard way.
Basic: read an entire JSON file into a Python object (dict/list)
import json
with open('data.json', 'r', encoding='utf-8') as f:
data = json.load(f)
# Use it
# e.g., if data is a dict:
# print(data['some_key'])
From a JSON string instead of a file
import json
s = '{"a": 1, "b": [1, 2, 3]}'
data = json.loads(s)
Robust version with error handling
import json
from pathlib import Path
path = Path('data.json')
try:
with path.open('r', encoding='utf-8') as f:
data = json.load(f)
except FileNotFoundError:
print(f"File not found: {path}")
except json.JSONDecodeError as e:
print(f"Bad JSON at line {e.lineno}, col {e.colno}: {e.msg}")
Notes and variants:
- Encoding: JSON is UTF-8 by default; specify encoding='utf-8' to be explicit.
- Large files: json.load reads the whole file into memory. For very large JSON, consider streaming parsers like ijson:
import ijson
with open('big.json', 'r', encoding='utf-8') as f:
for item in ijson.items(f, 'items.item'): # adjust prefix to your structure
process(item)
- JSON Lines (NDJSON): one JSON object per line
import json
with open('data.jsonl', 'r', encoding='utf-8') as f:
for line in f:
line = line.strip()
if line:
obj = json.loads(line)
process(obj)
- With pathlib without json.load (alternative style)
from pathlib import Path
import json
data = json.loads(Path('data.json').read_text(encoding='utf-8'))
- Pandas (tabular data)
import pandas as pd
df = pd.read_json('data.json') # for array-of-objects
# or for JSON Lines:
df = pd.read_json('data.jsonl', lines=True)
Common pitfalls:
- Trailing commas or comments are not valid JSON. If you must handle commented JSON, look at json5 or commentjson.
{
"id": "chatcmpl-DpLApEjnJrCwFeYGPMnwKoqO9Xpby",
"object": "chat.completion",
"created": 1781128491,
"model": "gpt-5-2025-08-07",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The built-in json module is the standard way.\n\nBasic: read an entire JSON file into a Python object (dict/list)\nimport json\n\nwith open('data.json', 'r', encoding='utf-8') as f:\n data = json.load(f)\n\n# Use it\n# e.g., if data is a dict:\n# print(data['some_key'])\n\nFrom a JSON string instead of a file\nimport json\n\ns = '{\"a\": 1, \"b\": [1, 2, 3]}'\ndata = json.loads(s)\n\nRobust version with error handling\nimport json\nfrom pathlib import Path\n\npath = Path('data.json')\ntry:\n with path.open('r', encoding='utf-8') as f:\n data = json.load(f)\nexcept FileNotFoundError:\n print(f\"File not found: {path}\")\nexcept json.JSONDecodeError as e:\n print(f\"Bad JSON at line {e.lineno}, col {e.colno}: {e.msg}\")\n\nNotes and variants:\n- Encoding: JSON is UTF-8 by default; specify encoding='utf-8' to be explicit.\n- Large files: json.load reads the whole file into memory. For very large JSON, consider streaming parsers like ijson:\n import ijson\n with open('big.json', 'r', encoding='utf-8') as f:\n for item in ijson.items(f, 'items.item'): # adjust prefix to your structure\n process(item)\n- JSON Lines (NDJSON): one JSON object per line\n import json\n with open('data.jsonl', 'r', encoding='utf-8') as f:\n for line in f:\n line = line.strip()\n if line:\n obj = json.loads(line)\n process(obj)\n- With pathlib without json.load (alternative style)\n from pathlib import Path\n import json\n data = json.loads(Path('data.json').read_text(encoding='utf-8'))\n- Pandas (tabular data)\n import pandas as pd\n df = pd.read_json('data.json') # for array-of-objects\n # or for JSON Lines:\n df = pd.read_json('data.jsonl', lines=True)\n\nCommon pitfalls:\n- Trailing commas or comments are not valid JSON. If you must handle commented JSON, look at json5 or commentjson.",
"refusal": null,
"annotations": []
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 30,
"completion_tokens": 1143,
"total_tokens": 1173,
"prompt_tokens_details": {
"cached_tokens": 0,
"audio_tokens": 0
},
"completion_tokens_details": {
"reasoning_tokens": 640,
"audio_tokens": 0,
"accepted_prediction_tokens": 0,
"rejected_prediction_tokens": 0
}
},
"service_tier": "default",
"system_fingerprint": null,
"gatewayMetadata": {
"keySource": "Unified"
}
}
</details>
<details>
<summary>Multi-turn Conversation — Continuing a conversation with context</summary>
const response = await env.AI.run(
'openai/gpt-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": "openai/gpt-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 question! There are three main ways to go from SF to LA, each with different types of stops. Here are top picks by route, plus a couple sample itineraries.
Fastest (I-5)
- Harris Ranch (Coalinga): Classic steakhouse, big rest stop, EV chargers.
- Kettleman City: Food options (In-N-Out, Bravo Farms), large restrooms, EV superchargers.
- Fort Tejon State Historic Park (near Lebec): Stretch your legs among oak woodlands and historic barracks.
- Pyramid Lake Vista Point (north of Santa Clarita): Quick scenic stop before the final stretch.
Balanced coastal (US-101)
- San Luis Obispo: Charming downtown; Madonna Inn for a quirky snack/photo stop.
- Pismo Beach: Pier, clams, Monarch Butterfly Grove (seasonal: late Oct–Feb).
- Edna Valley or Paso Robles: Easy-access wineries for tastings (designate a driver).
- Solvang: Danish village vibes, pastries, windmills; Pea Soup Andersen’s in nearby Buellton.
- Santa Barbara: Mission, Funk Zone wineries/breweries, waterfront and Stearns Wharf.
- Ventura/Carpinteria: Carpinteria Bluffs and Tar Pits Park; mellow beaches.
Most scenic (Highway 1 / Pacific Coast Highway)
- Half Moon Bay or Santa Cruz: Coffee/beach walk to kick off the coast route.
- Monterey & Pacific Grove: Cannery Row, Monterey Bay Aquarium, 17‑Mile Drive, Lovers Point.
- Point Lobos State Natural Reserve: Short world‑class coastal hikes; arrive early for parking.
- Big Sur highlights: Bixby Creek Bridge overlook; Garrapata State Park pullouts; Pfeiffer Big Sur State Park (valley trails); Pfeiffer Beach (purple sand/keyhole rock, narrow access road); Nepenthe or Big Sur Bakery for views/food.
- Julia Pfeiffer Burns SP: McWay Falls overlook (iconic).
- San Simeon & Cambria: Elephant Seal Vista Point at Piedras Blancas; Hearst Castle (reserve tours); Moonstone Beach boardwalk.
- Morro Bay: Embarcadero and Morro Rock; sea otters often visible.
- Pismo/Oceano: Dunes, beach towns.
- Santa Barbara and Malibu: Finish with beaches like El Matador, Point Dume.
Sample one-day coastal highlight (long day)
- SF → Monterey (breakfast + quick 17‑Mile Drive/Point Lobos) → Big Sur (Bixby, McWay Falls, lunch) → Elephant seals → Santa Barbara (dinner) → LA.
Relaxed two-day coastal trip
- Day 1: SF → Monterey/Carmel → Big Sur hikes/lookouts → Overnight in Cambria, San Simeon, or San Luis Obispo.
- Day 2: Pismo → Solvang pastry stop → Santa Barbara lunch/beach → Malibu sunset → LA.
Tips
- Check Highway 1 conditions (landslides/closures are common in Big Sur): Caltrans QuickMap before you go.
- Start early for parking at Point Lobos/Big Sur stops; cell service is spotty in Big Sur.
- Book Hearst Castle tours and Big Sur/SLO lodging ahead, especially weekends/holidays.
- Bring layers; coastal weather changes fast. Fuel up before Big Sur—few gas stations.
If you tell me:
- Which route you prefer (I-5 speed, 101 balance, or Hwy 1 scenery),
- How many days you have,
- Interests (hikes, food/wine, beaches, kid-friendly, pet-friendly),
I’ll map a tailored stop-by-stop plan with drive times.
{
"id": "chatcmpl-DpLBM7b0Zf6BIFOThPdIAnUziVmcV",
"object": "chat.completion",
"created": 1781128524,
"model": "gpt-5-2025-08-07",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Great question! There are three main ways to go from SF to LA, each with different types of stops. Here are top picks by route, plus a couple sample itineraries.\n\nFastest (I-5)\n- Harris Ranch (Coalinga): Classic steakhouse, big rest stop, EV chargers.\n- Kettleman City: Food options (In-N-Out, Bravo Farms), large restrooms, EV superchargers.\n- Fort Tejon State Historic Park (near Lebec): Stretch your legs among oak woodlands and historic barracks.\n- Pyramid Lake Vista Point (north of Santa Clarita): Quick scenic stop before the final stretch.\n\nBalanced coastal (US-101)\n- San Luis Obispo: Charming downtown; Madonna Inn for a quirky snack/photo stop.\n- Pismo Beach: Pier, clams, Monarch Butterfly Grove (seasonal: late Oct–Feb).\n- Edna Valley or Paso Robles: Easy-access wineries for tastings (designate a driver).\n- Solvang: Danish village vibes, pastries, windmills; Pea Soup Andersen’s in nearby Buellton.\n- Santa Barbara: Mission, Funk Zone wineries/breweries, waterfront and Stearns Wharf.\n- Ventura/Carpinteria: Carpinteria Bluffs and Tar Pits Park; mellow beaches.\n\nMost scenic (Highway 1 / Pacific Coast Highway)\n- Half Moon Bay or Santa Cruz: Coffee/beach walk to kick off the coast route.\n- Monterey & Pacific Grove: Cannery Row, Monterey Bay Aquarium, 17‑Mile Drive, Lovers Point.\n- Point Lobos State Natural Reserve: Short world‑class coastal hikes; arrive early for parking.\n- Big Sur highlights: Bixby Creek Bridge overlook; Garrapata State Park pullouts; Pfeiffer Big Sur State Park (valley trails); Pfeiffer Beach (purple sand/keyhole rock, narrow access road); Nepenthe or Big Sur Bakery for views/food.\n- Julia Pfeiffer Burns SP: McWay Falls overlook (iconic).\n- San Simeon & Cambria: Elephant Seal Vista Point at Piedras Blancas; Hearst Castle (reserve tours); Moonstone Beach boardwalk.\n- Morro Bay: Embarcadero and Morro Rock; sea otters often visible.\n- Pismo/Oceano: Dunes, beach towns.\n- Santa Barbara and Malibu: Finish with beaches like El Matador, Point Dume.\n\nSample one-day coastal highlight (long day)\n- SF → Monterey (breakfast + quick 17‑Mile Drive/Point Lobos) → Big Sur (Bixby, McWay Falls, lunch) → Elephant seals → Santa Barbara (dinner) → LA.\n\nRelaxed two-day coastal trip\n- Day 1: SF → Monterey/Carmel → Big Sur hikes/lookouts → Overnight in Cambria, San Simeon, or San Luis Obispo.\n- Day 2: Pismo → Solvang pastry stop → Santa Barbara lunch/beach → Malibu sunset → LA.\n\nTips\n- Check Highway 1 conditions (landslides/closures are common in Big Sur): Caltrans QuickMap before you go.\n- Start early for parking at Point Lobos/Big Sur stops; cell service is spotty in Big Sur.\n- Book Hearst Castle tours and Big Sur/SLO lodging ahead, especially weekends/holidays.\n- Bring layers; coastal weather changes fast. Fuel up before Big Sur—few gas stations.\n\nIf you tell me:\n- Which route you prefer (I-5 speed, 101 balance, or Hwy 1 scenery),\n- How many days you have,\n- Interests (hikes, food/wine, beaches, kid-friendly, pet-friendly),\nI’ll map a tailored stop-by-stop plan with drive times.",
"refusal": null,
"annotations": []
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 76,
"completion_tokens": 1926,
"total_tokens": 2002,
"prompt_tokens_details": {
"cached_tokens": 0,
"audio_tokens": 0
},
"completion_tokens_details": {
"reasoning_tokens": 1152,
"audio_tokens": 0,
"accepted_prediction_tokens": 0,
"rejected_prediction_tokens": 0
}
},
"service_tier": "default",
"system_fingerprint": null,
"gatewayMetadata": {
"keySource": "Unified"
}
}
