Example usage

print(factorial(5)) # Output: 120


### How it works step by step:

factorial(5) ├── 5 * factorial(4) ├── 4 * factorial(3) ├── 3 * factorial(2) ├── 2 * factorial(1) └── returns 1 (base case) └── returns 2 * 1 = 2 └── returns 3 * 2 = 6 └── returns 4 * 6 = 24 └── returns 5 * 24 = 120


## Why Recursion Works

Each recursive call works on a **smaller version** of the original problem until it reaches the simplest case (base case). Then, the results bubble back up to build the final answer.

**Important**: Always ensure your recursive function has a proper base case, otherwise it will run infinitely and cause a stack overflow error!
````

```json
[
  {
    "choices": [
      {
        "delta": {
          "content": "",
          "role": "assistant"
        },
        "finish_reason": null,
        "index": 0,
        "logprobs": null
      }
    ],
    "created": 1776471081,
    "id": "chatcmpl-269e4881-6d79-91da-ad5b-a5d16443cade",
    "model": "qwen3-max",
    "object": "chat.completion.chunk",
    "system_fingerprint": null,
    "usage": null
  },
  {
    "choices": [
      {
        "delta": {
          "content": "**"
        },
        "finish_reason": null,
        "index": 0,
        "logprobs": null
      }
    ],
    "created": 1776471081,
    "id": "chatcmpl-269e4881-6d79-91da-ad5b-a5d16443cade",
    "model": "qwen3-max",
    "object": "chat.completion.chunk",
    "system_fingerprint": null,
    "usage": null
  },
  "... 74 more chunks omitted ...",
  {
    "choices": [],
    "created": 1776471081,
    "id": "chatcmpl-269e4881-6d79-91da-ad5b-a5d16443cade",
    "model": "qwen3-max",
    "object": "chat.completion.chunk",
    "system_fingerprint": null,
    "usage": {
      "completion_tokens": 422,
      "prompt_tokens": 19,
      "prompt_tokens_details": {
        "cached_tokens": 0
      },
      "total_tokens": 441
    }
  }
]

</details>

<details>

<summary>Web Search — Letting Qwen use DashScope's built-in web search via enable_search</summary>

const response = await env.AI.run(
  'alibaba/qwen3-max',
  {
    enable_search: true,
    max_tokens: 4096,
    messages: [
      {
        content:
          'What were the top news stories about Cloudflare this week? Summarise in three bullets.',
        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": "alibaba/qwen3-max",
  "enable_search": true,
  "max_tokens": 4096,
  "messages": [
    {
      "content": "What were the top news stories about Cloudflare this week? Summarise in three bullets.",
      "role": "user"
    }
  ]
}'
As of the week ending June 23, 2026, the top Cloudflare news stories include:

- **Acquisition of VoidZero**: On June 4, 2026, Cloudflare announced it acquired VoidZero to accelerate development of the AI-native web, enhancing its platform for next-generation agentic applications.

- **Secure Sandboxes for Claude Managed Agents**: On May 19, 2026, Cloudflare introduced secure, scalable sandboxes integrated with Anthropic’s Claude Managed Agents, strengthening runtime security for AI agents—a key update still resonating in early June coverage.

- **Industry Recognition and Strategic Momentum**: Throughout June, Cloudflare continued to be highlighted as a Leader in Edge Development Platforms (per an independent research firm report on May 5, widely cited in June) and maintained media visibility through its ongoing “Agents Week 2026” initiatives, reinforcing its position at the forefront of agentic AI infrastructure.
{
  "id": "chatcmpl-5860fcba-c7bc-9e5e-afd8-d32376b5a423",
  "object": "chat.completion",
  "created": 1782161284,
  "model": "qwen3-max",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "As of the week ending June 23, 2026, the top Cloudflare news stories include:\n\n- **Acquisition of VoidZero**: On June 4, 2026, Cloudflare announced it acquired VoidZero to accelerate development of the AI-native web, enhancing its platform for next-generation agentic applications.\n\n- **Secure Sandboxes for Claude Managed Agents**: On May 19, 2026, Cloudflare introduced secure, scalable sandboxes integrated with Anthropic’s Claude Managed Agents, strengthening runtime security for AI agents—a key update still resonating in early June coverage.\n\n- **Industry Recognition and Strategic Momentum**: Throughout June, Cloudflare continued to be highlighted as a Leader in Edge Development Platforms (per an independent research firm report on May 5, widely cited in June) and maintained media visibility through its ongoing “Agents Week 2026” initiatives, reinforcing its position at the forefront of agentic AI infrastructure."
      },
      "finish_reason": "stop",
      "logprobs": null
    }
  ],
  "usage": {
    "prompt_tokens": 3589,
    "completion_tokens": 196,
    "total_tokens": 3785,
    "prompt_tokens_details": {
      "cached_tokens": 0
    }
  },
  "system_fingerprint": null,
  "gatewayMetadata": {
    "keySource": "Unified"
  }
}

</details>

Parameters

Schema variant

Chat CompletionsResponses

▶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.

▶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

id

string

object

string

created

number

model

string

▶choices[]

array

▶usage{}

object

id

string

object

stringconst: response

created_at

number

model

string

▶output[]

array

output_text

string

status

stringenum: in_progress, completed, failed, incomplete

▶usage{}

object

API Schemas (Raw)

Input Open Download

Output Open Download

Was this helpful?

YesNo

On this page

Example usage - 图1Docs

{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/ai/models/alibaba/qwen3-max/#page","headline":"Qwen 3 Max","description":"Alibaba's Qwen 3 Max is a large language model with strong coding, reasoning, and multilingual capabilities, served via DashScope's OpenAI-compatible endpoint.","url":"https://developers.cloudflare.com/ai/models/alibaba/qwen3-max/","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: Alibaba's Qwen 3.5 is a 397B-parameter mixture-of-experts model with 17B active parameters, offering strong reasoning capabilities with efficient inference. title: Qwen 3.5 397B A17B 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.

Alibaba logo