GPT-5.4 nano

Text Generation • OpenAI

openai/gpt-5.4-nano

  • Third-party
  • Zero data retention

GPT-5.4 nano is OpenAI's smallest and fastest model, optimized for edge and low-latency use cases.

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.20</li><li>Output (per 1M tokens)$1.25</li><li>Cached input (per 1M tokens)$0.02</li></ul>

Usage

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

1. **Zeroth Law (thermal equilibrium):**  
   If system A is in thermal equilibrium with system B, and system B is in thermal equilibrium with system C, then A is in thermal equilibrium with C.  
   *This law justifies the concept of temperature.*

2. **First Law (conservation of energy):**  
   Energy cannot be created or destroyed. It can only be transferred or transformed.  
   *In thermodynamics:* the change in internal energy of a system equals heat added to the system minus work done by the system.

3. **Second Law (entropy and direction of processes):**  
   Natural processes occur in a direction that increases the **total entropy** of the universe (or, equivalently, they tend to go from more ordered to less ordered forms).  
   It also implies that **not all heat can be converted into work** in a cyclical process.

*(There is also a “Third Law,” often presented alongside these as the third in the series.)*

4. **Third Law (absolute zero):**  
   As temperature approaches absolute zero (0 K), the entropy of a perfect crystal approaches a constant minimum value (typically zero).  
   It is impossible to reach absolute zero in a finite number of steps.
{
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "message": {
        "annotations": [],
        "content": "The three laws of thermodynamics are:\n\n1. **Zeroth Law (thermal equilibrium):**  \n   If system A is in thermal equilibrium with system B, and system B is in thermal equilibrium with system C, then A is in thermal equilibrium with C.  \n   *This law justifies the concept of temperature.*\n\n2. **First Law (conservation of energy):**  \n   Energy cannot be created or destroyed. It can only be transferred or transformed.  \n   *In thermodynamics:* the change in internal energy of a system equals heat added to the system minus work done by the system.\n\n3. **Second Law (entropy and direction of processes):**  \n   Natural processes occur in a direction that increases the **total entropy** of the universe (or, equivalently, they tend to go from more ordered to less ordered forms).  \n   It also implies that **not all heat can be converted into work** in a cyclical process.\n\n*(There is also a “Third Law,” often presented alongside these as the third in the series.)*\n\n4. **Third Law (absolute zero):**  \n   As temperature approaches absolute zero (0 K), the entropy of a perfect crystal approaches a constant minimum value (typically zero).  \n   It is impossible to reach absolute zero in a finite number of steps.",
        "refusal": null,
        "role": "assistant"
      }
    }
  ],
  "created": 1776470688,
  "gatewayMetadata": {
    "keySource": "Unified"
  },
  "id": "chatcmpl-DVnSyLOilRNmNr3S4HVuxEV3o73CA",
  "model": "gpt-5.4-nano-2026-03-17",
  "object": "chat.completion",
  "service_tier": "default",
  "system_fingerprint": null,
  "usage": {
    "completion_tokens": 269,
    "completion_tokens_details": {
      "accepted_prediction_tokens": 0,
      "audio_tokens": 0,
      "reasoning_tokens": 0,
      "rejected_prediction_tokens": 0
    },
    "prompt_tokens": 15,
    "prompt_tokens_details": {
      "audio_tokens": 0,
      "cached_tokens": 0
    },
    "total_tokens": 284
  }
}

Examples

<details>

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

const response = await env.AI.run(
  'openai/gpt-5.4-nano',
  {
    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.4-nano",
  "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"
    }
  ]
}'
You can read a JSON file in Python using the built-in `json` module.

```python
import json

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

print(data)  # data is now a Python dict/list depending on the JSON
```

**Notes:**
- Use `json.load(f)` to read from a file object.
- If your JSON file is an array at the top level, `data` will be a `list`; if it’s an object, it’ll be a `dict`.

If you want to read a JSON string instead (not a file), use `json.loads(s)`.
{
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "message": {
        "annotations": [],
        "content": "You can read a JSON file in Python using 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)  # data is now a Python dict/list depending on the JSON\n```\n\n**Notes:**\n- Use `json.load(f)` to read from a file object.\n- If your JSON file is an array at the top level, `data` will be a `list`; if it’s an object, it’ll be a `dict`.\n\nIf you want to read a JSON string instead (not a file), use `json.loads(s)`.",
        "refusal": null,
        "role": "assistant"
      }
    }
  ],
  "created": 1776470689,
  "gatewayMetadata": {
    "keySource": "Unified"
  },
  "id": "chatcmpl-DVnSzJVB6hEuloVcaDknzODqh082f",
  "model": "gpt-5.4-nano-2026-03-17",
  "object": "chat.completion",
  "service_tier": "default",
  "system_fingerprint": null,
  "usage": {
    "completion_tokens": 144,
    "completion_tokens_details": {
      "accepted_prediction_tokens": 0,
      "audio_tokens": 0,
      "reasoning_tokens": 0,
      "rejected_prediction_tokens": 0
    },
    "prompt_tokens": 30,
    "prompt_tokens_details": {
      "audio_tokens": 0,
      "cached_tokens": 0
    },
    "total_tokens": 174
  }
}

</details>

<details>

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

const response = await env.AI.run(
  'openai/gpt-5.4-nano',
  {
    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.4-nano",
  "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"
    }
  ]
}'
Absolutely—here are some great stop ideas on a typical San Francisco → Los Angeles road trip (assuming you’ll mostly take **I‑5 or US‑101**). I’ll list them by region so you can mix and match based on time and interests.

## Best quick stops (easy to add)
### Along/near the coast (great views)
- **Half Moon Bay** – beaches, scenic overlooks, quick coffee/food stops.
- **Santa Cruz (if you take/near US‑101)** – boardwalk area, viewpoints; fun even for a short stop.
- **Monterey Bay / Cannery Row** – aquarium area and coastal scenery.
- **Big Sur viewpoints (if you do the coastal route)**  
  - Common highlights: **Bixby Bridge**, **McWay Falls (if open)**, scenic pullouts along Highway 1.

> Note: Big Sur can be slower and is weather-dependent (and Highway 1 sections can close occasionally), so plan with current conditions if you choose this.

### Classic “Hollywood-adjacent” vibes
- **Santa Barbara** – charming downtown, good food, beach walk.
- **Solvang** – Danish-style village theme; silly/fun stop for snacks and photos.

## Major “worth it” detours (more time, bigger payoff)
### Wine country (if you like food + views)
- **Santa Rosa / Healdsburg (Sonoma County)** – wineries, farm stands, tastings.
- **Napa Valley (if you want a big wine day)** – mostly if you’re okay with a longer detour.

### Redwood / nature stops
- **Henry Cowell Redwoods State Park (near Santa Cruz)** – redwood trails without a huge detour.
- **Giant redwoods near Monterey area / Big Basin (depending on route)** – more forest time.

### Route/landscape highlights on inland routes
If you go more inland (often faster, less coastline):
- **Gilroy** – quick stop for garlic-themed food or outlets.
- **Central Valley roadside stops** – quick lunch breaks, but fewer “must-see” landmarks.

## A few “choose based on your route” suggestions
- **If you take US‑101 (often prettier / more towns):** Half Moon Bay → Santa Cruz → Monterey → Santa Barbara → LA.
- **If you take I‑5 (usually faster):** San Jose area → Paso Robles (good mid-way option) → Santa Barbara → LA.
- **If you want the iconic scenery:** prioritize **Highway 1 / Big Sur** (best views, slower, more planning).

---

### Quick questions so I can tailor a perfect stop list + itinerary
1. What month (or approximate dates) are you going?
2. Do you prefer **coastal views (slower, scenic)** or **faster/inland (more driving, fewer views)**?
3. How many days do you want (e.g., 1 long day vs 2–3 days)?
4. Any interests: beaches, hiking, wine, kitschy towns, food stops, museums?

Answer those and I’ll propose a specific route with 6–12 stops, estimated timing, and backup options.
{
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "message": {
        "annotations": [],
        "content": "Absolutely—here are some great stop ideas on a typical San Francisco → Los Angeles road trip (assuming you’ll mostly take **I‑5 or US‑101**). I’ll list them by region so you can mix and match based on time and interests.\n\n## Best quick stops (easy to add)\n### Along/near the coast (great views)\n- **Half Moon Bay** – beaches, scenic overlooks, quick coffee/food stops.\n- **Santa Cruz (if you take/near US‑101)** – boardwalk area, viewpoints; fun even for a short stop.\n- **Monterey Bay / Cannery Row** – aquarium area and coastal scenery.\n- **Big Sur viewpoints (if you do the coastal route)**  \n  - Common highlights: **Bixby Bridge**, **McWay Falls (if open)**, scenic pullouts along Highway 1.\n\n> Note: Big Sur can be slower and is weather-dependent (and Highway 1 sections can close occasionally), so plan with current conditions if you choose this.\n\n### Classic “Hollywood-adjacent” vibes\n- **Santa Barbara** – charming downtown, good food, beach walk.\n- **Solvang** – Danish-style village theme; silly/fun stop for snacks and photos.\n\n## Major “worth it” detours (more time, bigger payoff)\n### Wine country (if you like food + views)\n- **Santa Rosa / Healdsburg (Sonoma County)** – wineries, farm stands, tastings.\n- **Napa Valley (if you want a big wine day)** – mostly if you’re okay with a longer detour.\n\n### Redwood / nature stops\n- **Henry Cowell Redwoods State Park (near Santa Cruz)** – redwood trails without a huge detour.\n- **Giant redwoods near Monterey area / Big Basin (depending on route)** – more forest time.\n\n### Route/landscape highlights on inland routes\nIf you go more inland (often faster, less coastline):\n- **Gilroy** – quick stop for garlic-themed food or outlets.\n- **Central Valley roadside stops** – quick lunch breaks, but fewer “must-see” landmarks.\n\n## A few “choose based on your route” suggestions\n- **If you take US‑101 (often prettier / more towns):** Half Moon Bay → Santa Cruz → Monterey → Santa Barbara → LA.\n- **If you take I‑5 (usually faster):** San Jose area → Paso Robles (good mid-way option) → Santa Barbara → LA.\n- **If you want the iconic scenery:** prioritize **Highway 1 / Big Sur** (best views, slower, more planning).\n\n---\n\n### Quick questions so I can tailor a perfect stop list + itinerary\n1. What month (or approximate dates) are you going?\n2. Do you prefer **coastal views (slower, scenic)** or **faster/inland (more driving, fewer views)**?\n3. How many days do you want (e.g., 1 long day vs 2–3 days)?\n4. Any interests: beaches, hiking, wine, kitschy towns, food stops, museums?\n\nAnswer those and I’ll propose a specific route with 6–12 stops, estimated timing, and backup options.",
        "refusal": null,
        "role": "assistant"
      }
    }
  ],
  "created": 1776470691,
  "gatewayMetadata": {
    "keySource": "Unified"
  },
  "id": "chatcmpl-DVnT1xz56ah5Px0VXmp40Yxy793fo",
  "model": "gpt-5.4-nano-2026-03-17",
  "object": "chat.completion",
  "service_tier": "default",
  "system_fingerprint": null,
  "usage": {
    "completion_tokens": 665,
    "completion_tokens_details": {
      "accepted_prediction_tokens": 0,
      "audio_tokens": 0,
      "reasoning_tokens": 0,
      "rejected_prediction_tokens": 0
    },
    "prompt_tokens": 76,
    "prompt_tokens_details": {
      "audio_tokens": 0,
      "cached_tokens": 0
    },
    "total_tokens": 741
  }
}