Now 'data' is a Python dictionary (or li·续

</details>

<details>

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

const response = await env.AI.run(
  'alibaba/qwen3.7-plus',
  {
    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": "alibaba/qwen3.7-plus",
  "messages": [
    {
      "content": "Explain the concept of recursion with a simple example.",
      "role": "user"
    }
  ],
  "stream": true,
  "stream_options": {
    "include_usage": true
  }
}'
At its core, **recursion** is a programming concept where a function calls *itself* in order to solve a problem.

Instead of attacking a massive problem all at once, recursion breaks the problem down into smaller, simpler versions of the *exact same problem*, until it reaches a point that is easy to solve.

To understand it, let's look at a real-world analogy, followed by a simple coding example.

---

### The Real-World Analogy: The Line
Imagine you are standing in a long line, and you want to know what number you are in the line.

Instead of counting everyone from the front, you use **recursion**:
1. **The Recursive Step:** You tap the person in front of you and ask, *"What number are you in the line?"*
2. That person doesn't know either, so they tap the person in front of *them* and ask the same question.
3. This continues down the line until it reaches the very first person.
4. **The Base Case:** The first person knows exactly where they are. They say, *"I am number 1."* They don't ask anyone else.
5. The answer gets passed back down the line. The second person adds 1 (so they are 2), the third person adds 1 (they are 3), and so on, until the answer finally reaches you.

In programming, the **Base Case** is the condition that tells the function to stop calling itself (the person at the front of the line). Without a base case, the function would loop forever!

---

### The Coding Example: Factorial
The most classic example of recursion is calculating a **factorial**. 
The factorial of 3 (written as `3!`) means multiplying 3 by every whole number below it: 
**`3! = 3 × 2 × 1 = 6`**

Here is how we write that using recursion in Python:

```python
def factorial(n):
    # 1. The Base Case (When do we stop?)
    if n == 1:
        return 1

    # 2. The Recursive Case (The function calls itself)
    else:
        return n * factorial(n - 1)
```

### How it works step-by-step
Let's trace what happens when we ask the computer for `factorial(3)`:

**Phase 1: The Calls (Going down the line)**
* `factorial(3)` sees that `n` is not 1. It returns `3 * factorial(2)`. *(Wait, we need to know what factorial(2) is!)*
* `factorial(2)` sees that `n` is not 1. It returns `2 * factorial(1)`. *(Wait, we need to know what factorial(1) is!)*
* `factorial(1)` hits the **Base Case**. It simply returns `1`.

**Phase 2: The Returns (Passing the answer back up the line)**
* Now the computer replaces `factorial(1)` with `1`. 
  * The previous step was `2 * factorial(1)`, which becomes `2 * 1 = 2`.
* Now the computer replaces `factorial(2)` with `2`.
  * The very first step was `3 * factorial(2)`, which becomes `3 * 2 = 6`.

The final answer is **6**.

---

### The Two Golden Rules of Recursion
Every recursive function **must** have these two parts, or your program will crash (usually resulting in a "Stack Overflow" error):
1. **The Base Case:** The condition where the function stops calling itself (e.g., `if n == 1`).
2. **The Recursive Case:** The part where the function calls itself, but with a modified input that moves *closer* to the base case (e.g., `n - 1`).

### Why use it?
While a simple `for` loop can calculate a factorial, recursion is incredibly powerful for problems that involve branching structures, like navigating through folders on your computer, searching through a family tree, or sorting complex data. It allows you to write clean, elegant code for problems that would otherwise require massive, confusing loops.
[
  {
    "model": "qwen3.7-plus",
    "id": "chatcmpl-29158f9e-a9f4-9c08-9d9e-96bc58a68c5e",
    "created": 1785165376,
    "object": "chat.completion.chunk",
    "usage": null,
    "choices": [
      {
        "logprobs": null,
        "index": 0,
        "delta": {
          "content": "",
          "role": "assistant",
          "reasoning_content": ""
        },
        "finish_reason": null
      }
    ]
  },
  {
    "model": "qwen3.7-plus",
    "id": "chatcmpl-29158f9e-a9f4-9c08-9d9e-96bc58a68c5e",
    "choices": [
      {
        "delta": {
          "content": "",
          "reasoning_content": "Here"
        },
        "index": 0,
        "finish_reason": null,
        "logprobs": null
      }
    ],
    "created": 1785165376,
    "object": "chat.completion.chunk",
    "usage": null
  },
  "... 598 more chunks omitted ...",
  {
    "choices": [],
    "created": 1785165376,
    "id": "chatcmpl-29158f9e-a9f4-9c08-9d9e-96bc58a68c5e",
    "model": "qwen3.7-plus",
    "object": "chat.completion.chunk",
    "usage": {
      "completion_tokens": 2114,
      "completion_tokens_details": {
        "reasoning_tokens": 1194,
        "text_tokens": 2114
      },
      "prompt_tokens": 21,
      "prompt_tokens_details": {
        "cached_tokens": 0,
        "text_tokens": 21
      },
      "total_tokens": 2135
    }
  }
]

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

Now 'data' is a Python dictionary (or li·续 - 图1Docs

{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/ai/models/alibaba/qwen3.7-plus/#page","headline":"Qwen 3.7 Plus","description":"Alibaba's Qwen 3.7 Plus is the cost-effective member of the Qwen3.7 series, pairing strong text capabilities with image and video understanding and full-stack agent-level intelligence for coding, tool use, and GUI-based automation, served via DashScope's OpenAI-compatible endpoint.","url":"https://developers.cloudflare.com/ai/models/alibaba/qwen3.7-plus/","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.8 Max is a 2.4-trillion-parameter MoE flagship built for professional-grade coding and long-horizon autonomous work, capable of delivering complete, production-grade projects spanning 10+ days across legal, financial, design, and other specialized domains. Native visual understanding of images and extended video runs through the full plan-execute-verify cycle, served via DashScope's OpenAI-compatible endpoint. title: Qwen 3.8 Max 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