3. Now data is a normal Python dict/li·续

Recursion is a technique where a function (or routine) calls itself in order to break a problem down into smaller, more manageable pieces. Every recursive solution has two essential parts:

1. Base Case  
    – A condition under which the function returns a result directly, without making any further recursive calls.  
2. Recursive Case  
    – The part of the function that calls itself with a smaller or simpler input, moving the overall problem toward the base case.

Simple Example: Computing Factorial

The factorial of a non-negative integer n (written n!) is the product of all positive integers up to n.  
  – 0! is defined as 1 (this will be our base case).  
  – For n > 0, n! = n × (n – 1)!

Here’s how you could write it in Python:

```
def factorial(n):
    # Base case
    if n == 0:
        return 1
    # Recursive case
    else:
        return n * factorial(n - 1)
```

How it works for factorial(4):
 1. factorial(4)  
    → 4 * factorial(3)  
 2. factorial(3)  
    → 3 * factorial(2)  
 3. factorial(2)  
    → 2 * factorial(1)  
 4. factorial(1)  
    → 1 * factorial(0)  
 5. factorial(0)  
    → 1   (base case reached)

Then the calls “unwind”:
  – factorial(1) returns 1 × 1 = 1  
  – factorial(2) returns 2 × 1 = 2  
  – factorial(3) returns 3 × 2 = 6  
  – factorial(4) returns 4 × 6 = 24

Key points to remember:
- Always define a clear base case, or the recursion will never stop.  
- Each recursive call should make progress toward that base case (e.g. decreasing n by 1).  
- Recursion is especially handy for problems that naturally split into similar subproblems (tree traversals, divide-and-conquer algorithms, combinatorial searches, etc.).
[
  {
    "choices": [
      {
        "delta": {
          "content": "",
          "refusal": null,
          "role": "assistant"
        },
        "finish_reason": null,
        "index": 0
      }
    ],
    "created": 1776470992,
    "id": "chatcmpl-DVnXsdpE8VJOrtvNaSXE4EEPhwEuq",
    "model": "o4-mini-2025-04-16",
    "obfuscation": "3Y9X9fW8",
    "object": "chat.completion.chunk",
    "service_tier": "default",
    "system_fingerprint": null,
    "usage": null
  },
  {
    "choices": [
      {
        "delta": {
          "content": "Rec"
        },
        "finish_reason": null,
        "index": 0
      }
    ],
    "created": 1776470992,
    "id": "chatcmpl-DVnXsdpE8VJOrtvNaSXE4EEPhwEuq",
    "model": "o4-mini-2025-04-16",
    "obfuscation": "bNp9XsA",
    "object": "chat.completion.chunk",
    "service_tier": "default",
    "system_fingerprint": null,
    "usage": null
  },
  "... 470 more chunks omitted ...",
  {
    "choices": [],
    "created": 1776470992,
    "id": "chatcmpl-DVnXsdpE8VJOrtvNaSXE4EEPhwEuq",
    "model": "o4-mini-2025-04-16",
    "obfuscation": "EcvXn",
    "object": "chat.completion.chunk",
    "service_tier": "default",
    "system_fingerprint": null,
    "usage": {
      "completion_tokens": 680,
      "completion_tokens_details": {
        "accepted_prediction_tokens": 0,
        "audio_tokens": 0,
        "reasoning_tokens": 192,
        "rejected_prediction_tokens": 0
      },
      "prompt_tokens": 16,
      "prompt_tokens_details": {
        "audio_tokens": 0,
        "cached_tokens": 0
      },
      "total_tokens": 696
    }
  }
]

</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/o4-mini',
  {
    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/o4-mini",
  "input": "What were the top news stories about Cloudflare this week? Summarise in three bullets.",
  "max_output_tokens": 4096,
  "tools": [
    {
      "type": "web_search_preview"
    }
  ]
}'
- On June 18, Cloudflare unveiled a new “Cloudflare One Design Partner” designation within its PowerUP Partner Program and introduced an AI-powered toolkit to streamline migrations to its Cloudflare One platform, helping organizations modernize legacy security architectures and accelerate adoption of secure access service edge (SASE) solutions; the initial cohort includes partners such as Arctiq, Consortium, CMT, Presidio, and The Missing Link ([itpro.com](https://www.itpro.com/technology/artificial-intelligence/cloudflare-launches-new-partner-initiative-to-support-ai-and-sase-adoption?utm_source=openai))

- On June 17, Cloudflare strengthened its AI agent ecosystem by open-sourcing Flue 1.0 Beta—an extensible framework for deploying production-grade AI agents—and expanding its Agents SDK with durable execution primitives, making it easier for developers to build, run, and maintain long-running AI-driven workflows on the edge ([spyingbee.com](https://spyingbee.com/updates/cloudflare/2026-06))

- Between June 16 and June 22, Cloudflare investigated and resolved a dashboard bug that caused paid invoices to appear as unpaid for customers; the issue, which affected payments made since June 11, was fully remediated by June 22 following identification of the root cause and deployment of a fix ([cloudflarestatus.com](https://www.cloudflarestatus.com/))
{
  "id": "resp_0f41967bfc550c15016a399cbfa0ac819b80994a339b9c1547",
  "object": "response",
  "created_at": 1782160575,
  "model": "o4-mini-2025-04-16",
  "output": [
    {
      "id": "rs_0f41967bfc550c15016a399cc07a14819ba4e5122ca57d8119",
      "type": "reasoning",
      "content": [],
      "summary": []
    },
    {
      "id": "ws_0f41967bfc550c15016a399cc2d864819bb451de59ff6791f5",
      "type": "web_search_call",
      "status": "completed",
      "action": {
        "type": "search",
        "queries": [
          "Cloudflare news June 2026"
        ],
        "query": "Cloudflare news June 2026"
      }
    },
    {
      "id": "rs_0f41967bfc550c15016a399cc41770819b81de6f54fba4e7d8",
      "type": "reasoning",
      "content": [],
      "summary": []
    },
    {
      "id": "ws_0f41967bfc550c15016a399cc57694819b89c557cbcb3db307",
      "type": "web_search_call",
      "status": "completed",
      "action": {
        "type": "search",
        "queries": [
          "Cloudflare June 15 2026 press release Cloudflare Jun 2026",
          "site:cloudflare.com June 2026 Cloudflare news June 15 Jun 21"
        ],
        "query": "Cloudflare June 15 2026 press release Cloudflare Jun 2026"
      }
    },
    {
      "id": "rs_0f41967bfc550c15016a399cc7885c819b9c95fdeffec9914e",
      "type": "reasoning",
      "content": [],
      "summary": []
    },
    {
      "id": "ws_0f41967bfc550c15016a399cc8b4f8819bb841eb34accab156",
      "type": "web_search_call",
      "status": "completed",
      "action": {
        "type": "search",
        "queries": [
          "Cloudflare outage June 2026 Cloudflare service degraded"
        ],
        "query": "Cloudflare outage June 2026 Cloudflare service degraded"
      }
    },
    {
      "id": "rs_0f41967bfc550c15016a399ccc3b8c819ba4eb3d2bd8ece5f9",
      "type": "reasoning",
      "content": [],
      "summary": []
    },
    {
      "id": "ws_0f41967bfc550c15016a399ccd17a4819bb264ac00b2e3351e",
      "type": "web_search_call",
      "status": "completed",
      "action": {
        "type": "search",
        "queries": [
          "Immerse Seattle Cloudflare June 18 2026"
        ],
        "query": "Immerse Seattle Cloudflare June 18 2026"
      }
    },
    {
      "id": "rs_0f41967bfc550c15016a399ccfab90819ba3ec10fb21ec44bb",
      "type": "reasoning",
      "content": [],
      "summary": []
    },
    {
      "id": "ws_0f41967bfc550c15016a399cd1b3c8819b9d9e53b2bce8a04f",
      "type": "web_search_call",
      "status": "completed",
      "action": {
        "type": "open_page",
        "url": "https://www.cloudflarestatus.com/"
      }
    },
    {
      "id": "rs_0f41967bfc550c15016a399cd2aeec819b9ff03483519c6a50",
      "type": "reasoning",
      "content": [],
      "summary": []
    },
    {
      "id": "ws_0f41967bfc550c15016a399cd51788819bb3b37aaed05a1246",
      "type": "web_search_call",
      "status": "completed",
      "action": {
        "type": "open_page",
        "url": "https://spyingbee.com/updates/cloudflare/2026-06"
      }
    },
    {
      "id": "rs_0f41967bfc550c15016a399cd66aa8819ba3f7172a1f2d2d5b",
      "type": "reasoning",
      "content": [],
      "summary": []
    },
    {
      "id": "msg_0f41967bfc550c15016a399cdebf8c819ba14e3d49fcd5ec12",
      "type": "message",
      "status": "completed",
      "content": [
        {
          "type": "output_text",
          "annotations": [
            {
              "type": "url_citation",
              "end_index": 612,
              "start_index": 448,
              "title": "Cloudflare launches new partner initiative to support AI and SASE adoption",
              "url": "https://www.itpro.com/technology/artificial-intelligence/cloudflare-launches-new-partner-initiative-to-support-ai-and-sase-adoption?utm_source=openai"
            },
            {
              "type": "url_citation",
              "end_index": 1009,
              "start_index": 942,
              "title": "Cloudflare: 153 product updates in June 2026 | Spyingbee",
              "url": "https://spyingbee.com/updates/cloudflare/2026-06"
            },
            {
              "type": "url_citation",
              "end_index": 1371,
              "start_index": 1312,
              "title": "Cloudflare Status",
              "url": "https://www.cloudflarestatus.com/"
            }
          ],
          "logprobs": [],
          "text": "- On June 18, Cloudflare unveiled a new “Cloudflare One Design Partner” designation within its PowerUP Partner Program and introduced an AI-powered toolkit to streamline migrations to its Cloudflare One platform, helping organizations modernize legacy security architectures and accelerate adoption of secure access service edge (SASE) solutions; the initial cohort includes partners such as Arctiq, Consortium, CMT, Presidio, and The Missing Link ([itpro.com](https://www.itpro.com/technology/artificial-intelligence/cloudflare-launches-new-partner-initiative-to-support-ai-and-sase-adoption?utm_source=openai))  \n\n- On June 17, Cloudflare strengthened its AI agent ecosystem by open-sourcing Flue 1.0 Beta—an extensible framework for deploying production-grade AI agents—and expanding its Agents SDK with durable execution primitives, making it easier for developers to build, run, and maintain long-running AI-driven workflows on the edge ([spyingbee.com](https://spyingbee.com/updates/cloudflare/2026-06))  \n\n- Between June 16 and June 22, Cloudflare investigated and resolved a dashboard bug that caused paid invoices to appear as unpaid for customers; the issue, which affected payments made since June 11, was fully remediated by June 22 following identification of the root cause and deployment of a fix ([cloudflarestatus.com](https://www.cloudflarestatus.com/))"
        }
      ],
      "role": "assistant"
    }
  ],
  "status": "completed",
  "usage": {
    "input_tokens": 29004,
    "output_tokens": 3661,
    "total_tokens": 32665,
    "input_tokens_details": {
      "cached_tokens": 0
    },
    "output_tokens_details": {
      "reasoning_tokens": 3200
    }
  },
  "background": false,
  "billing": {
    "payer": "developer"
  },
  "completed_at": 1782160608,
  "error": null,
  "frequency_penalty": 0,
  "incomplete_details": null,
  "instructions": null,
  "max_output_tokens": 4096,
  "max_tool_calls": null,
  "moderation": null,
  "parallel_tool_calls": true,
  "presence_penalty": 0,
  "previous_response_id": null,
  "prompt_cache_key": null,
  "prompt_cache_retention": "in_memory",
  "reasoning": {
    "context": "current_turn",
    "effort": "medium",
    "summary": null
  },
  "safety_identifier": null,
  "service_tier": "default",
  "store": false,
  "temperature": 1,
  "text": {
    "format": {
      "type": "text"
    },
    "verbosity": "medium"
  },
  "tool_choice": "auto",
  "tools": [
    {
      "type": "web_search_preview",
      "search_content_types": [
        "text"
      ],
      "search_context_size": "medium",
      "user_location": {
        "type": "approximate",
        "city": null,
        "country": "US",
        "region": null,
        "timezone": null
      }
    }
  ],
  "top_logprobs": 0,
  "top_p": 1,
  "truncation": "disabled",
  "user": null,
  "metadata": {},
  "gatewayMetadata": {
    "keySource": "Unified"
  }
}

</details>

Parameters

Schema variant

ResponsesChat Completions

▶input

one ofrequired

instructions

string

temperature

numberminimum: 0maximum: 2

max_output_tokens

numberexclusiveMinimum: 0

top_p

numberminimum: 0maximum: 1

stream

boolean

▶tools[]

array

tool_choice

▶text{}

object

▶reasoning{}

object

▶messages[]

arrayrequired

temperature

numberminimum: 0maximum: 2

max_tokens

numberexclusiveMinimum: 0

max_completion_tokens

numberexclusiveMinimum: 0

top_p

numberminimum: 0maximum: 1

frequency_penalty

numberminimum: -2maximum: 2

presence_penalty

numberminimum: -2maximum: 2

stream

boolean

▶stream_options{}

object

▶tools[]

array

tool_choice

response_format

▶modalities[]

array

▶audio{}

object

reasoning_effort

stringOptional reasoning control; availability and accepted values are model-dependent.

id

string

object

stringconst: response

created_at

number

model

string

▶output[]

array

output_text

string

status

stringenum: in_progress, completed, failed, incomplete

▶usage{}

object

id

string

object

string

created

number

model

string

▶choices[]

array

▶usage{}

object

API Schemas (Raw)

Input Open Download

Output Open Download

Was this helpful?

YesNo

On this page

3. Now `data` is a normal Python dict/li·续 - 图1Docs

{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/ai/models/openai/o4-mini/#page","headline":"o4-mini","description":"OpenAI's fast, lightweight reasoning model optimized for multi-step problem solving at lower cost.","url":"https://developers.cloudflare.com/ai/models/openai/o4-mini/","inLanguage":"en","image":"https://developers.cloudflare.com/og-docs.png","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}


description: OpenAI's text-to-speech model optimized for real-time use with low latency. title: TTS-1 image: https://developers.cloudflare.com/og-docs.png


Skip to content

Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/llms.txt
Use this file to discover all available pages before exploring further.

OpenAI logo