GPT-5 mini

Text Generation • OpenAI

openai/gpt-5-mini

  • Third-party
  • Zero data retention

GPT-5 Mini is the lightweight, low-cost variant of GPT-5, well suited to high-volume coding and reasoning tasks.

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)$0.25</li><li>Output (per 1M tokens)$2.00</li><li>Cached input (per 1M tokens)$0.025</li></ul>

Usage

const response = await env.AI.run(
  'openai/gpt-5-mini',
  { 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-mini",
  "messages": [
    {
      "content": "What are the three laws of thermodynamics?",
      "role": "user"
    }
  ]
}'
Briefly, the fundamental laws are:

- Zeroth law (often counted separately): If system A is in thermal equilibrium with B, and B is in thermal equilibrium with C, then A is in thermal equilibrium with C. This justifies the concept of temperature and allows the use of thermometers.

- First law (conservation of energy): Energy is conserved. For a closed system,
  ΔU = Q − W,
  where ΔU is the change in internal energy, Q is heat added to the system, and W is work done by the system.

- Second law (direction of processes; entropy): Natural processes increase the total entropy of an isolated system. A standard mathematical statement:
  ΔS ≥ ∫ δQ_rev/T,
  and for an isolated system ΔS ≥ 0. Equivalent formulations: no cyclic engine can convert all heat into work (Kelvin–Planck), and heat cannot spontaneously flow from a colder to a hotter body (Clausius).

- Third law (zero‑temperature limit): As T → 0, the entropy of a perfect crystalline substance approaches a constant (often taken as zero). Consequences include the unattainability principle: absolute zero cannot be reached in a finite number of steps.

(Traditionally textbooks list the First, Second and Third laws; the Zeroth law was named later because it underpins the concept of temperature.)
{
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "message": {
        "annotations": [],
        "content": "Briefly, the fundamental laws are:\n\n- Zeroth law (often counted separately): If system A is in thermal equilibrium with B, and B is in thermal equilibrium with C, then A is in thermal equilibrium with C. This justifies the concept of temperature and allows the use of thermometers.\n\n- First law (conservation of energy): Energy is conserved. For a closed system,\n  ΔU = Q − W,\n  where ΔU is the change in internal energy, Q is heat added to the system, and W is work done by the system.\n\n- Second law (direction of processes; entropy): Natural processes increase the total entropy of an isolated system. A standard mathematical statement:\n  ΔS ≥ ∫ δQ_rev/T,\n  and for an isolated system ΔS ≥ 0. Equivalent formulations: no cyclic engine can convert all heat into work (Kelvin–Planck), and heat cannot spontaneously flow from a colder to a hotter body (Clausius).\n\n- Third law (zero‑temperature limit): As T → 0, the entropy of a perfect crystalline substance approaches a constant (often taken as zero). Consequences include the unattainability principle: absolute zero cannot be reached in a finite number of steps.\n\n(Traditionally textbooks list the First, Second and Third laws; the Zeroth law was named later because it underpins the concept of temperature.)",
        "refusal": null,
        "role": "assistant"
      }
    }
  ],
  "created": 1777320124,
  "gatewayMetadata": {
    "keySource": "Unified"
  },
  "id": "chatcmpl-DZMRYPDmQAXQ6d6GeOKrgb8jeCPgK",
  "model": "gpt-5-mini-2025-08-07",
  "object": "chat.completion",
  "service_tier": "default",
  "system_fingerprint": null,
  "usage": {
    "completion_tokens": 673,
    "completion_tokens_details": {
      "accepted_prediction_tokens": 0,
      "audio_tokens": 0,
      "reasoning_tokens": 384,
      "rejected_prediction_tokens": 0
    },
    "prompt_tokens": 15,
    "prompt_tokens_details": {
      "audio_tokens": 0,
      "cached_tokens": 0
    },
    "total_tokens": 688
  }
}

Examples

<details>

<summary>With System Message — Using a system message to set context</summary>

const response = await env.AI.run(
  'openai/gpt-5-mini',
  {
    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-mini",
  "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 usual way. Use json.load() to parse a file object into Python objects (dicts, lists, strings, numbers, booleans, None).

Basic example:
```python
import json

with open("data.json", "r", encoding="utf-8") as f:
    data = json.load(f)

print(type(data))  # usually dict or list
print(data)
```

Read from a JSON string:
```python
s = '{"name": "Alice", "age": 30}'
obj = json.loads(s)
```

Common extras

- 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("Invalid JSON:", e)
```

- Newline-delimited JSON (NDJSON / JSON Lines):
```python
import json

with open("lines.jsonl", "r", encoding="utf-8") as f:
    for line in f:
        if line.strip():
            obj = json.loads(line)
            # process obj
```

- Large files (streaming): for very large JSON arrays, use a streaming parser like ijson to avoid loading everything into memory:
```python
import ijson

with open("big.json", "rb") as f:
    for item in ijson.items(f, "item"):  # "item" is path for array elements
        # process item
```

- Compressed JSON:
```python
import gzip, json

with gzip.open("data.json.gz", "rt", encoding="utf-8") as f:
    data = json.load(f)
```

- Convert Python back to JSON:
```python
with open("out.json", "w", encoding="utf-8") as f:
    json.dump(data, f, ensure_ascii=False, indent=2)
```

If your JSON maps naturally to tabular data, pandas.read_json can be convenient:
```python
import pandas as pd
df = pd.read_json("data.json")
```

That covers the usual ways — if you share the structure of your JSON or constraints (huge file, NDJSON, custom types), I can give a more specific example.
{
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "message": {
        "annotations": [],
        "content": "The built‑in json module is the usual way. Use json.load() to parse a file object into Python objects (dicts, lists, strings, numbers, booleans, None).\n\nBasic example:\n```python\nimport json\n\nwith open(\"data.json\", \"r\", encoding=\"utf-8\") as f:\n    data = json.load(f)\n\nprint(type(data))  # usually dict or list\nprint(data)\n```\n\nRead from a JSON string:\n```python\ns = '{\"name\": \"Alice\", \"age\": 30}'\nobj = json.loads(s)\n```\n\nCommon extras\n\n- 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(\"Invalid JSON:\", e)\n```\n\n- Newline-delimited JSON (NDJSON / JSON Lines):\n```python\nimport json\n\nwith open(\"lines.jsonl\", \"r\", encoding=\"utf-8\") as f:\n    for line in f:\n        if line.strip():\n            obj = json.loads(line)\n            # process obj\n```\n\n- Large files (streaming): for very large JSON arrays, use a streaming parser like ijson to avoid loading everything into memory:\n```python\nimport ijson\n\nwith open(\"big.json\", \"rb\") as f:\n    for item in ijson.items(f, \"item\"):  # \"item\" is path for array elements\n        # process item\n```\n\n- Compressed JSON:\n```python\nimport gzip, json\n\nwith gzip.open(\"data.json.gz\", \"rt\", encoding=\"utf-8\") as f:\n    data = json.load(f)\n```\n\n- Convert Python back to JSON:\n```python\nwith open(\"out.json\", \"w\", encoding=\"utf-8\") as f:\n    json.dump(data, f, ensure_ascii=False, indent=2)\n```\n\nIf your JSON maps naturally to tabular data, pandas.read_json can be convenient:\n```python\nimport pandas as pd\ndf = pd.read_json(\"data.json\")\n```\n\nThat covers the usual ways — if you share the structure of your JSON or constraints (huge file, NDJSON, custom types), I can give a more specific example.",
        "refusal": null,
        "role": "assistant"
      }
    }
  ],
  "created": 1777320141,
  "gatewayMetadata": {
    "keySource": "Unified"
  },
  "id": "chatcmpl-DZMRprAcSRmcAdqafyZx3VJbKyz1M",
  "model": "gpt-5-mini-2025-08-07",
  "object": "chat.completion",
  "service_tier": "default",
  "system_fingerprint": null,
  "usage": {
    "completion_tokens": 754,
    "completion_tokens_details": {
      "accepted_prediction_tokens": 0,
      "audio_tokens": 0,
      "reasoning_tokens": 256,
      "rejected_prediction_tokens": 0
    },
    "prompt_tokens": 30,
    "prompt_tokens_details": {
      "audio_tokens": 0,
      "cached_tokens": 0
    },
    "total_tokens": 784
  }
}

</details>

<details>

<summary>Multi-turn Conversation — Continuing a conversation with context</summary>

const response = await env.AI.run(
  'openai/gpt-5-mini',
  {
    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-mini",
  "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 — here are several good stop options and a few sample itineraries depending on how much time you have and which route you take (PCH/Highway 1 for scenery, US‑101 for a balance of speed and towns, I‑5 if you want the fastest drive).

High-level route choices - Pacific Coast Highway (CA‑1 / PCH): Most scenic — cliffs, beaches, Big Sur. Slow, can be winding and has occasional closures/traffic. - US‑101: Faster than CA‑1 and still scenic through coastal towns, wine country, and beaches. - I‑5: Fastest (about 5–6 hours), but mostly inland and not scenic. Good if you want to minimize driving time.

Useful tip: check Caltrans for road conditions and CA‑1/Big Sur closures before you go; plan around LA rush hour (avoid entering LA 3–7 pm) and leaving SF early to beat Bay Area traffic.

Stops (north → south) — highlights by route

Common coastal highlights (CA‑1 & 101 overlap in places) - Half Moon Bay (30–45 min from SF) - Quick beach walk, pastries (Local bakeries), coastal trail views. - Santa Cruz (1–1.5 hr from SF) - Boardwalk, surf spots, downtown restaurants. - Capitola (near Santa Cruz) - Colorful seaside village good for a short stroll and lunch.

Monterey/Carmel area (great for families/couples) - Monterey Bay Aquarium (Monterey) - World-class aquarium, Cannery Row dining. - 17‑Mile Drive / Pebble Beach (Carmel/Monterey) - Scenic loop with coastal viewpoints and Lone Cypress. - Carmel-by-the-Sea - Charming village, galleries, beach.

Big Sur (must-see if you have time) - Bixby Creek Bridge (iconic photo stop) - Pfeiffer Big Sur State Park (hiking) - Pfeiffer Beach (purple sand, limited parking) - McWay Falls / Julia Pfeiffer Burns State Park (waterfall onto beach) - Note: limited services and cell coverage — fuel up in Monterey or Carmel.

San Simeon / Cambria / Hearst Castle - Piedras Blancas elephant seal rookery (near San Simeon) - Hearst Castle tour (advance tickets recommended) - Cambria — quaint village for dinner/overnight.

San Luis Obispo / Pismo Beach / Morro Bay - San Luis Obispo (downtown, bubblegum alley) - Pismo Beach (cliffs, monarch butterflies seasonally) - Morro Bay (Morro Rock, kayaking)

Santa Ynez Valley / Solvang (inland detour off PCH/101) - Danish-style Solvang, wineries in Santa Ynez and Los Olivos — great for wine tasting and a slower afternoon.

Santa Barbara (the “American Riviera”) - State Street, waterfront, mission, good dining and beaches.

Last stretch into Los Angeles (via US‑101 or PCH) - Ventura (surf, harbor) - Malibu (beaches, Zuma, Point Dume) - Santa Monica / Venice (pier, boardwalk, restaurants) before heading to downtown LA or other neighborhoods.