Skip to content
OpenAI logo

GPT-5 Chat

Text GenerationOpenAI

GPT-5 Chat is the chat-tuned variant of GPT-5, optimised for back-and-forth conversation and instruction following.

Model Info
Context Window128,000 tokens
Terms and Licenselink
More informationlink
PricingView pricing in the Cloudflare dashboard

Usage

TypeScript
const response = await env.AI.run(
'openai/gpt-5-chat',
{ messages: [{ content: 'What are the three laws of thermodynamics?', role: 'user' }] },
)
console.log(response)
The **three laws of thermodynamics** (often including the Zeroth Law as well) describe the fundamental principles governing energy, heat, and entropy in physical systems.

Here they are summarized:

1. **Zeroth Law of Thermodynamics (Thermal Equilibrium Law):**  
   If two systems are each in thermal equilibrium with a third system, then they are in thermal equilibrium with each other.  
   *This establishes the concept of temperature.*

2. **First Law of Thermodynamics (Law of Energy Conservation):**  
   Energy cannot be created or destroyed in an isolated system; it can only change form.  
   Mathematically:  
   \[
   \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.

3. **Second Law of Thermodynamics (Law of Entropy):**  
   The total entropy of an isolated system can never decrease over time; it tends to increase, approaching a maximum at equilibrium.  
   *This introduces the concept of irreversibility and the arrow of time.*

4. **Third Law of Thermodynamics (Law of Absolute Zero):**  
   As the temperature of a system approaches absolute zero (0 K), the entropy of a perfect crystal approaches zero.  
   *It implies that absolute zero is unattainable in a finite number of steps.*

Would you like a brief explanation of how these laws apply to real-world systems (like engines or refrigerators)?

Examples

With System Message — Using a system message to set context
TypeScript
const response = await env.AI.run(
'openai/gpt-5-chat',
{
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)
You can read a JSON file in Python using the built-in `json` module. Here’s a simple example:

```python
import json

# Open the JSON file for reading
with open('data.json', 'r') as file:
    data = json.load(file)

# Now 'data' is a Python dictionary (or list, depending on the JSON)
print(data)
```

### Explanation
- `import json` — imports Python’s JSON library.
- `open('data.json', 'r')` — opens the file in read mode.
- `json.load(file)` — parses the JSON content into a Python object (usually a `dict` or `list`).
- You can then work with `data` like any normal Python variable.

### Example JSON file (`data.json`)
```json
{
    "name": "Alice",
    "age": 30,
    "languages": ["English", "Spanish"]
}
```

After reading it, `data` would be:
```python
{'name': 'Alice', 'age': 30, 'languages': ['English', 'Spanish']}
```

If you already have a JSON string (not a file), you can parse it directly with:
```python
data = json.loads(json_string)
```

Would you like me to show how to handle errors (e.g., file not found or invalid JSON)?
Multi-turn Conversation — Continuing a conversation with context
TypeScript
const response = await env.AI.run(
'openai/gpt-5-chat',
{
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)
Great! You’ve got two main options for your drive from San Francisco to Los Angeles—**the scenic coastal route (Highway 1)** and **the faster inland route (Highway 101 or I‑5)**.  

Here’s a breakdown of both, with suggested stops:

---

### 🌊 **Coastal Route (Highway 1 / Pacific Coast Highway)**
**Total drive time:** ~8–10 hours (best enjoyed over 2–3 days)

**Highlights:**
1. **Half Moon Bay** – Pretty beaches and coastal trails. Great for a coffee stop and a short walk along the cliffs.  
2. **Santa Cruz** – Beach Boardwalk, surf culture, and Wharf area.  
3. **Monterey & Carmel-by-the-Sea** – Visit the Monterey Bay Aquarium, Cannery Row, or take the famous **17‑Mile Drive** for stunning coastal views.  
4. **Big Sur** – The star of the route: Bixby Bridge, McWay Falls, Pfeiffer Beach. Great hiking and photo opportunities.  
5. **San Simeon** – Stop at Hearst Castle or see the elephant seals along the coast.  
6. **Cambria / Morro Bay** – Chill small towns, excellent seafood, and beachside motels.  
7. **San Luis Obispo** – Charming downtown, Mission San Luis Obispo, and nearby wine tasting.  
8. **Pismo Beach** – A classic beach town—enjoy the pier or ATV rides on the dunes.  
9. **Santa Barbara** – Mediterranean-style city, State Street shopping, wineries, and beaches.  
10. **Malibu** – Beautiful beaches and coastal views as you approach LA.

This route offers breathtaking scenery but is winding and slower—ideal if you want a leisurely, scenic trip.

---

### 🛣️ **Inland Route (US‑101 or I‑5)**
**Total drive time:** ~5–6 hours (faster, less scenic)

**Highlights on 101:**
- **Gilroy** – “Garlic capital,” good for a snack stop.
- **Paso Robles** – Wine tasting region, great for food and overnight stays.
- **Santa Barbara** – A nice stop even on the inland 101 route before heading into LA.

**Highlights on I‑5:**
- **Kettleman City** – Good rest stop between SF and LA (gas, food).
- **Buttonwillow / Lost Hills** – Standard stops but not particularly scenic.

---

### 🏨 Suggested Overnight Stops (if splitting the trip)
- **Monterey, San Simeon, or San Luis Obispo** on the coastal route.  
- **Paso Robles** if taking Hwy 101.

---

Would you like me to suggest a **2-day or 3-day itinerary** for the coastal route, with where to stay and what to see each day?
Creative Writing — Longer completion for creative output
TypeScript
const response = await env.AI.run(
'openai/gpt-5-chat',
{
max_completion_tokens: 8192,
messages: [
{
content: 'Write a short story opening about a detective finding an unusual clue.',
role: 'user',
},
],
},
)
console.log(response)
Detective Mara Devlin crouched beside the body, the flickering streetlight above her painting everything in a jaundiced glow. It wasn’t the scene that held her still—the empty alley, the neat hole chewed through her victim’s watchband—but what had been left in the man’s stiffened hand. A chess pawn, small and carved from translucent glass, glimmered faintly in the light. Someone had taken the trouble to place it there after death.  

Mara turned it over gently in her latexed fingers. It was cold, far colder than anything else in the damp night air, and beneath the pawn’s base a single word had been etched deep into the glass: *Again.*
Streaming Response — Enable streaming for real-time output
TypeScript
const response = await env.AI.run(
'openai/gpt-5-chat',
{
messages: [{ content: 'Explain the concept of recursion with a simple example.', role: 'user' }],
stream: true,
stream_options: { include_usage: true },
},
)
console.log(response)
Recursion is a programming concept where a function calls **itself** in order to solve a problem. The idea is to break a big problem down into smaller, similar subproblems until you reach a point where the solution is simple — this point is called the **base case**.

### Example: Factorial

Let’s take the factorial of a number `n`, written as `n!`, which is defined as:

\[
n! = n × (n-1) × (n-2) × \dots × 1
\]
By definition, `1! = 1`.

We can define this **recursively**:

- **Base case**: if `n == 1`, return `1`
- **Recursive case**: return `n × factorial(n - 1)`

In Python-like pseudocode:
```python
def factorial(n):
    if n == 1:          # base case
        return 1
    else:
        return n * factorial(n - 1)  # recursive case
```

**How it works:**  
If you call `factorial(4)`, the calls and returns look like this:

```
factorial(4)
→ 4 * factorial(3)
     → 3 * factorial(2)
          → 2 * factorial(1)
               → 1  (base case)
```

Now the calls resolve in reverse:
```
factorial(2) = 2 * 1 = 2
factorial(3) = 3 * 2 = 6
factorial(4) = 4 * 6 = 24
```

So `factorial(4)` returns **24**.

---

**Key ideas about recursion:**
1. Each recursive call should bring you closer to the base case.
2. A base case is necessary to stop infinite recursion.
3. Recursion is particularly useful for problems that can be divided into similar subproblems — like traversing trees, working with nested structures, or solving mathematical sequences.

Parameters

frequency_penalty
numbermaximum: 2minimum: -2
max_completion_tokens
numberexclusiveMinimum: 0
max_tokens
numberexclusiveMinimum: 0
presence_penalty
numbermaximum: 2minimum: -2
response_format
stream
boolean
temperature
numbermaximum: 2minimum: 0
tool_choice
top_p
numbermaximum: 1minimum: 0

API Schemas (Raw)

Input
Output