Example usage (2)

result = factorial(5) # This will compute 5 * 4 * 3 * 2 * 1 print(result) # Output: 120


### Explanation:

1. **When `factorial(5)` is called**:
   - It checks if `n` is 0 (which it isn't).
   - It computes `5 * factorial(4)`.

2. **Next, `factorial(4)` is called**:
   - Again, it checks if `n` is 0 (which it isn't).
   - It computes `4 * factorial(3)`.

3. This process continues until `factorial(0)` is reached, which hits the base case and returns 1.

4. The function then unwinds:
   - `factorial(1)` returns `1 * 1 = 1`
   - `factorial(2)` returns `2 * 1 = 2`
   - `factorial(3)` returns `3 * 2 = 6`
   - `factorial(4)` returns `4 * 6 = 24`
   - `factorial(5)` returns `5 * 24 = 120`

Thus, the factorial of 5 is computed to be 120, demonstrating how recursion can break down a complex problem into simpler subproblems.
````

```json
[
  {
    "choices": [
      {
        "delta": {
          "content": "",
          "refusal": null,
          "role": "assistant"
        },
        "finish_reason": null,
        "index": 0,
        "logprobs": null
      }
    ],
    "created": 1777319565,
    "id": "chatcmpl-DZMIXJtgYyfytjeCEUmk1Yhm8o5XO",
    "model": "gpt-4o-mini-2024-07-18",
    "obfuscation": "a9jF6VOdC",
    "object": "chat.completion.chunk",
    "service_tier": "default",
    "system_fingerprint": "fp_6042092f77",
    "usage": null
  },
  {
    "choices": [
      {
        "delta": {
          "content": "Rec"
        },
        "finish_reason": null,
        "index": 0,
        "logprobs": null
      }
    ],
    "created": 1777319565,
    "id": "chatcmpl-DZMIXJtgYyfytjeCEUmk1Yhm8o5XO",
    "model": "gpt-4o-mini-2024-07-18",
    "obfuscation": "K0QlI2xz",
    "object": "chat.completion.chunk",
    "service_tier": "default",
    "system_fingerprint": "fp_6042092f77",
    "usage": null
  },
  "... 485 more chunks omitted ...",
  {
    "choices": [],
    "created": 1777319565,
    "id": "chatcmpl-DZMIXJtgYyfytjeCEUmk1Yhm8o5XO",
    "model": "gpt-4o-mini-2024-07-18",
    "obfuscation": "8alXGeDK",
    "object": "chat.completion.chunk",
    "service_tier": "default",
    "system_fingerprint": "fp_6042092f77",
    "usage": {
      "completion_tokens": 485,
      "completion_tokens_details": {
        "accepted_prediction_tokens": 0,
        "audio_tokens": 0,
        "reasoning_tokens": 0,
        "rejected_prediction_tokens": 0
      },
      "prompt_tokens": 17,
      "prompt_tokens_details": {
        "audio_tokens": 0,
        "cached_tokens": 0
      },
      "total_tokens": 502
    }
  }
]

</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

Example usage (2) - 图1Docs

{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/ai/models/openai/gpt-4o-mini/#page","headline":"GPT-4o mini","description":"GPT-4o Mini is the lightweight, low-cost variant of GPT-4o, well suited to high-volume tasks with multimodal inputs.","url":"https://developers.cloudflare.com/ai/models/openai/gpt-4o-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: A speech-to-text model that uses GPT-4o to transcribe audio with improved word error rate and better language recognition compared to original Whisper models. title: GPT-4o Transcribe 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