GPT-5.4 nano·续1

</details>

<details>

<summary>Creative Writing — Longer completion for creative output</summary>

const response = await env.AI.run(
  'openai/gpt-5.4-nano',
  {
    max_completion_tokens: 8192,
    messages: [
      {
        content: 'Write a short story opening about a detective finding an unusual clue.',
        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": "Write a short story opening about a detective finding an unusual clue.",
      "role": "user"
    }
  ]
}'
The rain had been falling long enough to turn the city’s neon into smeared watercolor, but it hadn’t softened the edges of the crime scene.

Detective Mara Kincaid stood just inside the taped perimeter, her coat dark with moisture and her mind sharper than the puddles gathering at her feet. The victim’s apartment sat above a shuttered bakery, its windows fogged from the inside, its hallway smelling faintly of citrus cleaner and burnt copper.

A uniform officer hovered nearby, eager to be useful. “No signs of forced entry, Detective. The husband—” He stopped, corrected himself. “The occupant. He found them like this.”

Mara didn’t look up. She was kneeling by the threshold, letting her flashlight sweep the floorboards the way some people read scripture—slow, patient, searching for the lines that didn’t belong.

Something glittered against the worn grain of wood.

It wasn’t glass. It wasn’t glitter from a spilled drink. It didn’t catch the light like coins or broken jewelry. It caught it like… breath.

A thin, translucent flake—no bigger than a fingernail clipping—lay half-buried in the seam between two planks. When Mara tilted her beam, the flake didn’t reflect so much as *remember*. The light seemed to sink into it and come back altered, as if the material were holding a picture just out of reach.

“Don’t touch it,” she said automatically, though she hadn’t realized she’d spoken until the officer flinched.

Mara held her breath. The flake had a faint curve, like the edge of a leaf, and a delicate pattern of lines that didn’t resemble any natural vein. Under the flashlight, the pattern looked almost… intentional.

She lifted her gloved hand, stopped millimeters above it, and felt a temperature difference. The wood around it was cold with night air. The flake was warmer, as though it had just been pressed there.

On instinct, she slid a small evidence marker beside it without moving the flake itself. Then she leaned closer and listened—because in her line of work, some things weren’t just seen.

At first there was only the rain and the distant rumble of traffic.

Then—barely audible beneath it—a soft, rhythmic *tick… tick… tick*, like a clock inside something too small to be a clock.

Mara straightened slowly, her stomach tightening. The unusual clue wasn’t just out of place.

It was *alive* in a way she couldn’t explain.

Behind her, the officer cleared his throat. “Detective? Should we—uh—call for your tech?”

Mara didn’t answer right away. She stared at the flake until her eyes began to ache, watching the light tremble within it like it was trying to form a message.

Finally, she said, “Yeah. And bring two sets of gloves.”

She stood, turning toward the apartment interior where the air felt heavy with everything that had already happened.

Whatever left this behind didn’t want to be caught.

But it had made sure she’d look—down at the seam between boards—at the moment her flashlight found it.

As if it knew exactly where her curiosity would go next.
{
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "message": {
        "annotations": [],
        "content": "The rain had been falling long enough to turn the city’s neon into smeared watercolor, but it hadn’t softened the edges of the crime scene.\n\nDetective Mara Kincaid stood just inside the taped perimeter, her coat dark with moisture and her mind sharper than the puddles gathering at her feet. The victim’s apartment sat above a shuttered bakery, its windows fogged from the inside, its hallway smelling faintly of citrus cleaner and burnt copper.\n\nA uniform officer hovered nearby, eager to be useful. “No signs of forced entry, Detective. The husband—” He stopped, corrected himself. “The occupant. He found them like this.”\n\nMara didn’t look up. She was kneeling by the threshold, letting her flashlight sweep the floorboards the way some people read scripture—slow, patient, searching for the lines that didn’t belong.\n\nSomething glittered against the worn grain of wood.\n\nIt wasn’t glass. It wasn’t glitter from a spilled drink. It didn’t catch the light like coins or broken jewelry. It caught it like… breath.\n\nA thin, translucent flake—no bigger than a fingernail clipping—lay half-buried in the seam between two planks. When Mara tilted her beam, the flake didn’t reflect so much as *remember*. The light seemed to sink into it and come back altered, as if the material were holding a picture just out of reach.\n\n“Don’t touch it,” she said automatically, though she hadn’t realized she’d spoken until the officer flinched.\n\nMara held her breath. The flake had a faint curve, like the edge of a leaf, and a delicate pattern of lines that didn’t resemble any natural vein. Under the flashlight, the pattern looked almost… intentional.\n\nShe lifted her gloved hand, stopped millimeters above it, and felt a temperature difference. The wood around it was cold with night air. The flake was warmer, as though it had just been pressed there.\n\nOn instinct, she slid a small evidence marker beside it without moving the flake itself. Then she leaned closer and listened—because in her line of work, some things weren’t just seen.\n\nAt first there was only the rain and the distant rumble of traffic.\n\nThen—barely audible beneath it—a soft, rhythmic *tick… tick… tick*, like a clock inside something too small to be a clock.\n\nMara straightened slowly, her stomach tightening. The unusual clue wasn’t just out of place.\n\nIt was *alive* in a way she couldn’t explain.\n\nBehind her, the officer cleared his throat. “Detective? Should we—uh—call for your tech?”\n\nMara didn’t answer right away. She stared at the flake until her eyes began to ache, watching the light tremble within it like it was trying to form a message.\n\nFinally, she said, “Yeah. And bring two sets of gloves.”\n\nShe stood, turning toward the apartment interior where the air felt heavy with everything that had already happened.\n\nWhatever left this behind didn’t want to be caught.\n\nBut it had made sure she’d look—down at the seam between boards—at the moment her flashlight found it.\n\nAs if it knew exactly where her curiosity would go next.",
        "refusal": null,
        "role": "assistant"
      }
    }
  ],
  "created": 1776470691,
  "gatewayMetadata": {
    "keySource": "Unified"
  },
  "id": "chatcmpl-DVnT1SUtcOln0seA0LbQDeFgl1Mdf",
  "model": "gpt-5.4-nano-2026-03-17",
  "object": "chat.completion",
  "service_tier": "default",
  "system_fingerprint": null,
  "usage": {
    "completion_tokens": 666,
    "completion_tokens_details": {
      "accepted_prediction_tokens": 0,
      "audio_tokens": 0,
      "reasoning_tokens": 0,
      "rejected_prediction_tokens": 0
    },
    "prompt_tokens": 19,
    "prompt_tokens_details": {
      "audio_tokens": 0,
      "cached_tokens": 0
    },
    "total_tokens": 685
  }
}

</details>

<details>

<summary>Streaming Response — Enable streaming for real-time output</summary>

const response = await env.AI.run(
  'openai/gpt-5.4-nano',
  {
    messages: [{ content: 'Explain the concept of recursion with a simple example.', role: 'user' }],
    stream: true,
    stream_options: { include_usage: true },
  },
)
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": "Explain the concept of recursion with a simple example.",
      "role": "user"
    }
  ],
  "stream": true,
  "stream_options": {
    "include_usage": true
  }
}'
Recursion is a programming technique where a function solves a problem by calling itself on smaller versions of the same problem.

A key idea is that recursion usually needs:
1. **A base case** (when to stop).
2. **A recursive case** (the problem broken into a smaller subproblem).

### Simple Example: Factorial
The factorial of a number *n* (written `n!`) is:
- `n! = n × (n-1)!`
- with the base case `0! = 1`

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

#### What happens for `factorial(4)`?
- `factorial(4) = 4 * factorial(3)`
- `factorial(3) = 3 * factorial(2)`
- `factorial(2) = 2 * factorial(1)`
- `factorial(1) = 1 * factorial(0)`
- `factorial(0) = 1`

So: `4 * 3 * 2 * 1 = 24`

If you want, I can also show a recursion example like summing a list or traversing a tree.
[
  {
    "choices": [
      {
        "delta": {
          "content": "",
          "refusal": null,
          "role": "assistant"
        },
        "finish_reason": null,
        "index": 0
      }
    ],
    "created": 1776470696,
    "id": "chatcmpl-DVnT6eFAFifz1GeXTi6RbmQUsrFn2",
    "model": "gpt-5.4-nano-2026-03-17",
    "obfuscation": "Vug",
    "object": "chat.completion.chunk",
    "service_tier": "default",
    "system_fingerprint": null,
    "usage": null
  },
  {
    "choices": [
      {
        "delta": {
          "content": "Rec"
        },
        "finish_reason": null,
        "index": 0
      }
    ],
    "created": 1776470696,
    "id": "chatcmpl-DVnT6eFAFifz1GeXTi6RbmQUsrFn2",
    "model": "gpt-5.4-nano-2026-03-17",
    "obfuscation": "l1",
    "object": "chat.completion.chunk",
    "service_tier": "default",
    "system_fingerprint": null,
    "usage": null
  },
  "... 279 more chunks omitted ...",
  {
    "choices": [],
    "created": 1776470696,
    "id": "chatcmpl-DVnT6eFAFifz1GeXTi6RbmQUsrFn2",
    "model": "gpt-5.4-nano-2026-03-17",
    "obfuscation": "1Z",
    "object": "chat.completion.chunk",
    "service_tier": "default",
    "system_fingerprint": null,
    "usage": {
      "completion_tokens": 282,
      "completion_tokens_details": {
        "accepted_prediction_tokens": 0,
        "audio_tokens": 0,
        "reasoning_tokens": 0,
        "rejected_prediction_tokens": 0
      },
      "prompt_tokens": 16,
      "prompt_tokens_details": {
        "audio_tokens": 0,
        "cached_tokens": 0
      },
      "total_tokens": 298
    }
  }
]

</details>

<details>

<summary>Web Search — Letting the model use OpenAI's built-in web search tool to answer with current information</summary>

const response = await env.AI.run(
  'openai/gpt-5.4-nano',
  {
    input: 'What were the top news stories about Cloudflare this week? Summarise in three bullets.',
    max_output_tokens: 4096,
    tools: [{ type: 'web_search_preview' }],
  },
)
console.log(response)
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/v1/responses \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
  "model": "openai/gpt-5.4-nano",
  "input": "What were the top news stories about Cloudflare this week? Summarise in three bullets.",
  "max_output_tokens": 4096,
  "tools": [
    {
      "type": "web_search_preview"
    }
  ]
}'
- **New Cloudflare One partner initiative for AI + SASE migrations:** Cloudflare announced a new “Cloudflare One Design Partner” designation (via its PowerUP program) and an AI-powered toolkit aimed at helping organizations modernize security/networking to SASE-style architectures. ([itpro.com](https://www.itpro.com/technology/artificial-intelligence/cloudflare-launches-new-partner-initiative-to-support-ai-and-sase-adoption?utm_source=openai))  
- **Acquisition to expand Cloudflare’s AI-native dev tooling:** Cloudflare said it’s buying **VoidZero** (behind the Vite ecosystem and related tools like Vitest), with plans to integrate those assets into **Cloudflare Workers** and keep key parts open source. ([itpro.com](https://www.itpro.com/business/acquisition/cloudflare-snaps-up-voidzero-to-expand-ai-native-developer-tools?utm_source=openai))  
- **Operational / reliability chatter around recent Cloudflare issues:** Multiple outlets and community reports during the last week pointed to **service problems affecting customer traffic** (including discussions referencing Cloudflare’s status/incident activity). ([cloudflarestatus.com](https://www.cloudflarestatus.com/uptime?utm_source=openai))