Skip to content
OpenAI logo

GPT-5.4 pro

Text GenerationOpenAI

GPT-5.4 pro uses OpenAI's Responses API with built-in tools, improved reasoning, and stateful context management.

Model Info
Context Window1,000,000 tokens
Terms and Licenselink
More informationlink
Zero data retentionYes
Request formatsResponses
PricingView pricing in the Cloudflare dashboard

Usage

TypeScript
const response = await env.AI.run(
'openai/gpt-5.4-pro',
{ input: 'What are the three laws of thermodynamics?' },
)
console.log(response)
The **three laws of thermodynamics** usually mean:

1. **First Law — Conservation of Energy**  
   Energy cannot be created or destroyed, only transferred or transformed.  
   - In thermodynamics: the change in a system’s internal energy equals heat added to the system minus work done by the system.

2. **Second Law — Entropy Increases**  
   In any natural process, the total entropy of an isolated system tends to increase.  
   - This means energy spontaneously spreads out, and no heat engine can be 100% efficient.
   - Heat naturally flows from hot objects to cold ones, not the reverse without input of work.

3. **Third Law — Entropy at Absolute Zero**  
   As temperature approaches **absolute zero** (0 K), the entropy of a perfect crystal approaches zero.  
   - A consequence is that absolute zero cannot be reached in a finite number of steps.

Small note: thermodynamics also has a **Zeroth Law**, which is often listed before these:
- 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 is the basis for the concept of **temperature**.

If you want, I can also give a **one-line intuitive version** of each law.

Examples

With Instructions — Using instructions to set context
TypeScript
const response = await env.AI.run(
'openai/gpt-5.4-pro',
{
input: 'How do I read a JSON file in Python?',
instructions: 'You are a helpful coding assistant specializing in Python.',
},
)
console.log(response)
Use Python’s built-in `json` module.

### Read a JSON file into a Python object
```python
import json

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

print(data)
```

### What you get back
`json.load()` converts JSON into normal Python types:

- JSON object → `dict`
- JSON array → `list`
- JSON string → `str`
- JSON number → `int` / `float`
- JSON true/false → `True` / `False`
- JSON null → `None`

### Example
If `data.json` contains:
```json
{
  "name": "Alice",
  "age": 30,
  "skills": ["Python", "SQL"]
}
```

Then:
```python
import json

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

print(data["name"])    # Alice
print(data["skills"])  # ['Python', 'SQL']
```

### Handle errors safely
```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:
    print("Invalid JSON.")
```

### If you already have JSON as a string
Use `json.loads()` instead:
```python
import json

text = '{"name": "Alice", "age": 30}'
data = json.loads(text)
print(data)
```

If you want, I can also show how to **write JSON back to a file**.
Multi-turn Conversation — Continuing a conversation with message array
TypeScript
const response = await env.AI.run(
'openai/gpt-5.4-pro',
{
input: [
{
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, name three good stops in one short sentence each.', role: 'user' },
],
max_output_tokens: 16000,
},
)
console.log(response)
- Monterey is great for the aquarium, Cannery Row, and ocean views.  
- San Luis Obispo is a fun lunch stop with a charming downtown and Mission Plaza.  
- Santa Barbara offers beaches, palm-lined streets, and an easy coastal break.
Temperature Control — Using temperature for creative responses
TypeScript
const response = await env.AI.run(
'openai/gpt-5.4-pro',
{ input: 'Write a haiku about artificial intelligence', temperature: 1 },
)
console.log(response)
Silent circuits dream  
Learning patterns in the dark  
Dawn wakes metal minds
With Reasoning — Using reasoning effort for complex problems
TypeScript
const response = await env.AI.run(
'openai/gpt-5.4-pro',
{
input:
'Solve this problem step by step: A train leaves Chicago at 60mph heading east. Another train leaves New York at 80mph heading west. They are 900 miles apart. When do they meet?',
reasoning: { effort: 'medium' },
},
)
console.log(response)
Step 1: Find their combined speed since they are moving toward each other.

- Train from Chicago: **60 mph**
- Train from New York: **80 mph**

Combined speed:

**60 + 80 = 140 mph**

Step 2: Use the distance formula:

\[
\text{time}=\frac{\text{distance}}{\text{speed}}
\]

\[
\text{time}=\frac{900}{140}
\]

\[
\text{time}=6.428571\text{ hours}
\]

Step 3: Convert the decimal part to minutes.

\[
0.428571 \times 60 \approx 25.7 \text{ minutes}
\]

So they meet after about:

**6 hours 26 minutes**

Final answer: **The trains meet about 6 hours 26 minutes after they leave.**

Parameters

instructions
string
temperature
numberminimum: 0maximum: 2
max_output_tokens
numberexclusiveMinimum: 0
top_p
numberminimum: 0maximum: 1
stream
boolean
tool_choice

API Schemas (Raw)

Input
Output