# Streaming card updates

The streaming update capability of Feishu cards refers to the continuous, real-time or near-real-time updating of Feishu card content, achieving a progressive rendering effect. This document introduces how to get started with the streaming update capability of cards.

## Demo

The [Open Platform Intelligent Assistant](https://app.feishu.cn/app/cli_a608a6e07cf95013?visit_from=search) application utilizes the streaming update capability of cards.

## Use cases

In AI Bot scenarios, you can leverage the streaming update capability of cards to provide end-users with a smoother and more real-time interactive experience. Specific scenarios are as follows:

- **Scenario 1**: Output the text content returned by the AI model to the Feishu card with a "typewriter effect".
- **Scenario 2**: After the text streaming output is completed, operate the card through card and component-level OpenAPIs, such as appending a dropdown component below the text component to provide an entry for evaluating the AI's response, and updating the component after user feedback.

## Capabilities

You can call [card-level and component-level interfaces](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/cardkit-v1/feishu-card-resource-overview#791c8e74) to continuously and repeatedly modify the content, including two update methods:
- **Typewriter effect output for text components**: In streaming update mode, continuously push full text content to plain text elements (tag as plain_text) or rich text components (tag as markdown) in the card. The platform will automatically calculate the incremental part and render it character by character with a typewriter effect.
- **Component-level partial updates**: Whether the streaming update mode is enabled or not, you can perform fine-grained operations on components within the card, including adding, deleting, updating component content or attributes, such as updating charts or modifying button icons.

## Notes

- During the streaming update mode of the card, when the server receives the card's callback request during user interaction with the card, it will not be able to update the card immediately.
- To use the streaming update capability of Feishu cards and related interfaces, you need to construct the card based on the [card JSON 2.0 structure](https://open.feishu.cn/document/uAjLw4CM/ukzMukzMukzM/feishu-cards/card-json-v2-structure).
- The card JSON 2.0 structure supports Feishu client version 7.20 and later. When a card using the JSON 2.0 structure is sent to a client version lower than 7.20, the card title will be displayed normally, but the content will show a fallback upgrade prompt.

- For a single card entity, the frequency limit for using card and component-level OpenAPIs to operate the card is 10 times per second.

## Prerequisites

- You have created an application in the [Feishu Developer Console](https://open.feishu.cn/app) and added Bot capabilities and enabled the following permissions for the application. For details, refer to [Create and Configure an Application](https://open.feishu.cn/document/home/develop-a-bot-in-5-minutes/step-1-create-app-and-enable-robot-capabilities).
    - Send messages as the application (im:message:send_as_bot)
    - Get and send single chat and group messages (im:message)
    - Create and update cards (cardkit:card:write)
- You have constructed the card JSON based on the [card JSON 2.0 structure](https://open.feishu.cn/document/uAjLw4CM/ukzMukzMukzM/feishu-cards/card-json-v2-structure).

## Steps

This section describes how to implement the streaming update of the card by calling the card OpenAPI, including the streaming update of text and the partial update of components.

### Step 1: Enable Streaming Update Mode

If the card entity has not been created, you can enable the streaming update when creating the card entity. If the card entity already exists, you can directly call the [Update Card Configuration](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/cardkit-v1/card/settings) API to enable the streaming update mode. Details are as follows.

#### **Method 1: Enable Streaming Update Mode When Creating the Card**

1. In the card JSON, set the `streaming_mode` field to `true`. Additionally, you can use the `streaming_config` field to specify the frequency, step size, and update strategy for the streaming update. The field descriptions and JSON example are as follows.

Field Name | Type | Required | Description
---|---|---|---
streaming_mode | boolean | No | Whether the card is in streaming update mode. In streaming update mode, developers can call card and component APIs to continuously perform full updates, partial updates, and text streaming updates on the card, without triggering the API frequency limit (QPS).
streaming_config | object | No | Parameter configuration for streaming update text.<br>**Note**:<br>- In Feishu versions 7.20 - 7.22, the streaming update feature uses the default update frequency, step size, and update strategy for streaming rendering. Custom parameters are not supported. In Feishu version 7.23 and above, the streaming update feature supports custom parameters for frequency, step size, and strategy.<br>- Default parameters may vary depending on client type, version, device model, etc. If precise control over streaming update behavior is required, it is recommended to manually specify streaming parameters.<br>- To ensure consistency in the streaming effect, it is recommended to specify streaming update parameters in advance and keep them unchanged throughout the streaming update process.
print_frequency_ms | object | No | The frequency of streaming updates, i.e., the interval between two streaming updates. Default is 70 ms. Supports configuration for different platforms.<br>**Tip**:<br>- To configure unified streaming parameters for all platforms, only specify the value of `default`.<br>- To specify different streaming parameters for different platforms, in addition to filling in the `default` parameter, you can optionally add parameters for Android/iOS/PC platforms.
default | number | Yes | Unified frequency for all platforms.
android | number | No | Frequency for Android platform.
ios | number | No | Frequency for iOS platform.
pc | number | No | Frequency for PC platform.
print_step | object | No | The step size of streaming updates, i.e., the number of incremental characters printed in each streaming update. Default is 1. Supports configuration for different platforms.<br>**Tip**:<br>- To configure unified streaming parameters for all platforms, only specify the value of `default`.<br>- To specify different streaming parameters for different platforms, in addition to filling in the `default` parameter, you can optionally add parameters for Android/iOS/PC platforms.
default | number | Yes | Unified step size for all platforms.
android | number | No | Step size for Android platform.
ios | number | No | Step size for iOS platform.
pc | number | No | Step size for PC platform.
print_strategy | enum | No | The streaming update strategy for a single text element (tag as plain_text) or rich text component. The optional values are as follows. The default is `fast`, which means quick rendering. For example effects, refer to the following description.<br>- **fast**: Quick rendering. This is the default strategy for Feishu versions 7.20 - 7.22. After calling the [Streaming Update Text](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/cardkit-v1/card-element/content) API, if the historical text has not been fully rendered, the unrendered part will be immediately rendered, and then the new content will start rendering.<br>- **delay**: Delayed rendering. After calling the [Streaming Update Text](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/cardkit-v1/card-element/content) API, if the historical text has not been fully rendered, the unrendered part will continue to be rendered with the typewriter effect until it is fully rendered, and then the new content will start rendering.

Here is an example configuration:

```json
{
    "schema": "2.0",
    "header": {
        "title": {
            "content": "Card Title",
            "tag": "plain_text"
        }
    },
    "config": {
        "streaming_mode": true, // Whether the card is in streaming update mode. Default is false.
        "summary": {
            "content": "" // Card summary. You can customize the preview text in the client chat bar. When streaming update mode is enabled, the summary will default to "[Generating...]".
        },
        "streaming_config": {
            // Streaming update frequency, in milliseconds
            "print_frequency_ms": {
                "default": 70,
                "android": 70,
                "ios": 70,
                "pc": 70
            },
            // Streaming update step size, in characters
            "print_step": {
                "default": 1,
                "android": 1,
                "ios": 1,
                "pc": 1
            },
            // Streaming update strategy. Enum values: fast/delay
            "print_strategy": "fast"
        }
    },
    "body": {
        "elements": [
            {
                "tag": "markdown",
                "content": "Card Content",
                "element_id": "markdown_1" // Unique identifier for the component. Used for subsequent operations such as adding or deleting components. This attribute must be globally unique within the card.
            }
        ]
    }
}
```

2. Call the [Create Card Entity](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/cardkit-v1/card/create) API, and pass the card JSON code from the previous step (remove comments and compress it into a string) in the `data` field to obtain the card entity ID, which is used to send the streaming card.

Here is an example request body for creating a card entity. You can directly click the API documentation link to debug in the API Explorer:

```json
    {
      "type": "card_json",
      "data": "{\"schema\":\"2.0\",\"header\":{\"title\":{\"content\":\"Card Title\",\"tag\":\"plain_text\"}},\"config\":{\"streaming_mode\":true,\"summary\":{\"content\":\"\"},\"streaming_config\":{\"print_frequency_ms\":{\"default\":70,\"android\":70,\"ios\":70,\"pc\":70},\"print_step\":{\"default\":1,\"android\":1,\"ios\":1,\"pc\":1},\"print_strategy\":\"fast\"}},\"body\":{\"elements\":[{\"tag\":\"markdown\",\"content\":\"Card Content\",\"element_id\":\"markdown_1\"}]}}"
    }
    ```

3. Call the [Send Message](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/message/create) API, and pass the card entity ID in the `content` field of the request body to send the card entity.warning
**Note**
- A card entity can only be sent once.
- The application sending the card entity must be the one that created the card entity.

Here is an example request body for sending a card entity:

```json
{
    "receive_id": "ou_449b53ad6aee526f7ed311b216aabcef",
    "msg_type": "interactive",
    "content": "{\"type\":\"card\",\"data\":{\"card_id\":\"7371713483664506900\"}}"
}
```

The structure of the `content` field is as follows:

```json
{
    "type": "card",   // Fixed value, indicating the message type is a card.
    "data": {
        "card_id": "7371713483664506900"  // The card entity ID obtained from the previous step.
    }
}
```

#### **Method 2: Enable Streaming Update Mode for an Existing Card**

If the card entity already exists, you can directly call the [Update Card Configuration](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/cardkit-v1/card/settings) API to enable the streaming update mode. The `streaming_mode` and `streaming_config` fields are consistent with the parameters described in Method 1.

Field Name | Type | Required | Description
---|---|---|---
streaming_mode | boolean | No | Whether the card is in streaming update mode. In streaming update mode, developers can call card and component APIs to continuously perform full updates, partial updates, and text streaming updates on the card, without triggering the API frequency limit (QPS).
streaming_config | object | No | Parameter configuration for streaming update text.<br>**Note**:<br>- In Feishu versions 7.20 - 7.22, the streaming update feature uses the default update frequency, step size, and update strategy for streaming rendering. Custom parameters are not supported. In Feishu version 7.23 and above, the streaming update feature supports custom parameters for frequency, step size, and strategy.<br>- Default parameters may vary depending on client type, version, device model, etc. If precise control over streaming update behavior is required, it is recommended to manually specify streaming parameters.<br>- To ensure consistency in the streaming effect, it is recommended to specify streaming update parameters in advance and keep them unchanged throughout the streaming update process.
print_frequency_ms | object | No | The frequency of streaming updates, i.e., the interval between two streaming updates. Default is 70 ms. Supports configuration for different platforms.<br>**Tip**:<br>- To configure unified streaming parameters for all platforms, only specify the value of `default`.<br>- To specify different streaming parameters for different platforms, in addition to filling in the `default` parameter, you can optionally add parameters for Android/iOS/PC platforms.
default | number | Yes | Unified frequency for all platforms.
android | number | No | Frequency for Android platform.
ios | number | No | Frequency for iOS platform.
pc | number | No | Frequency for PC platform.
print_step | object | No | The step size of streaming updates, i.e., the number of incremental characters printed in each streaming update. Default is 1. Supports configuration for different platforms.<br>**Tip**:<br>- To configure unified streaming parameters for all platforms, only specify the value of `default`.<br>- To specify different streaming parameters for different platforms, in addition to filling in the `default` parameter, you can optionally add parameters for Android/iOS/PC platforms.
default | number | Yes | Unified step size for all platforms.
android | number | No | Step size for Android platform.
ios | number | No | Step size for iOS platform.
pc | number | No | Step size for PC platform.
print_strategy | enum | No | The streaming update strategy for a single text element (tag as plain_text) or rich text component. The optional values are as follows. The default is `fast`, which means quick rendering. For example effects, refer to the following description.<br>- **fast**: Quick rendering. This is the default strategy for Feishu versions 7.20 - 7.22. After calling the [Streaming Update Text](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/cardkit-v1/card-element/content) API, if the historical text has not been fully rendered, the unrendered part will be immediately rendered, and then the new content will start rendering.<br>- **delay**: Delayed rendering. After calling the [Streaming Update Text](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/cardkit-v1/card-element/content) API, if the historical text has not been fully rendered, the unrendered part will continue to be rendered with the typewriter effect until it is fully rendered, and then the new content will start rendering.

Here is an example request body for updating the card configuration:

```json
{
    "card_id": "7371713483664506900",  // The card entity ID.
    "streaming_mode": true,            // Enable streaming update mode.
    "streaming_config": {
        "print_frequency_ms": {
            "default": 70,
            "android": 70,
            "ios": 70,
            "pc": 70
        },
        "print_step": {
            "default": 1,
            "android": 1,
            "ios": 1,
            "pc": 1
        },
        "print_strategy": "fast"
    }
}
```

```json
{
  "settings": "{\"config\":{\"streaming_mode\":true,\"streaming_config\":{\"print_frequency_ms\":{\"default\":70,\"android\":70,\"ios\":70,\"pc\":70},\"print_step\":{\"default\":1,\"android\":1,\"ios\":1,\"pc\":1},\"print_strategy\":\"fast\"}}}",
  "uuid": "a0d69e20-1dd1-458b-k525-dfeca4015204",
  "sequence": 1
}
```

### Step 2: Streaming Update Text

In the streaming update mode of the card, call the [Streaming Update Text](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/cardkit-v1/card-element/content) API to pass the full text content to plain text elements (tag: `plain_text`) or rich text components in the card. If the old text is a prefix substring of the new text, the additional text will continue to be output at the end of the old text with a typewriter effect. If the prefixes of the old and new texts differ, the full text will be directly displayed without the typewriter effect.

![20250627115933_rec_-convert.gif](//sf3-cn.feishucdn.com/obj/open-platform-opendoc/43468be10ae16543fcd19448b72b2e83_4A1JJzv396.gif?height=952&lazyload=true&maxWidth=300&width=796)

When streaming update text, you can control the display strategy of the first unrendered text during two streaming updates using the `print_strategy` parameter. Suppose the content of a rich text component is **ABCDE**, and **ABC** has been displayed while the component is updated with new text **ABCDEFGH**. Different streaming update strategies (`print_strategy`) will produce different display effects:

- **Fast Display (fast, default)**: The unrendered **DE** in **ABCDE** will be immediately displayed, and the component will directly show **ABCDE**; then, the subsequent text **FGH** will be displayed with the typewriter effect.
- **Delayed Display (delay)**: The unrendered **DE** in **ABCDE** will be displayed sequentially with the typewriter effect; then, the subsequent text **FGH** will be displayed with the typewriter effect.

### Step 3: Continuously update the card

After the text streaming is complete, if you need to update parts of the card, such as appending a dropdown component below the text component to provide an entry for evaluating the AI response, or updating the component after user feedback, you can call the [Card and Component APIs](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/cardkit-v1/feishu-card-resource-overview#791c8e74) to continuously update the card multiple times. This includes fully updating the card, adding, deleting, or modifying components, and changing card configurations.  
Regardless of whether the streaming update mode is enabled, except for the [Streaming Update Text](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/cardkit-v1/card-element/content) API, you can call the [Card and Component APIs](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/cardkit-v1/feishu-card-resource-overview#791c8e74) to perform fine-grained operations on components within the card.

As shown in the example below, you can call the [Add Component](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/cardkit-v1/card-element/create) API to insert a button component after the rich text component.

![20250627120128_rec_-convert.gif](//sf3-cn.feishucdn.com/obj/open-platform-opendoc/19284bc7d11bcd05136a95701aef8088_Indi6B5vCy.gif?height=952&lazyload=true&maxWidth=300&width=796)

### Step 4 (Optional): Update the Card Based on Interaction Callbacks

In the card streaming update mode, if the user interacts with an interactive component and triggers the [Card Interaction Callback](https://open.feishu.cn/document/uAjLw4CM/ukzMukzMukzM/feishu-cards/card-callback-communication), you need to first disable the streaming update mode before processing the card callback.

1. After the card text streaming update is complete, call the [Update Card Configuration](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/cardkit-v1/card/settings) API and set the `streaming_mode` field to `false` to terminate the card's streaming update mode.
2. Refer to [Handling Card Callbacks](https://open.feishu.cn/document/uAjLw4CM/ukzMukzMukzM/feishu-cards/handle-card-callbacks) to process the callback request normally. When updating the card, you can continue to call card and component-level APIs to partially update the card.

### Step 5: Disable the Streaming Update Mode

After the card text streaming update is complete, you can call the [Update Card Configuration](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/cardkit-v1/card/settings) API and set the `streaming_mode` field to `false` to terminate the card's streaming update mode. The streaming update mode will automatically close 10 minutes after the last activation, but it is recommended to manually disable it.

## Frequently Asked Questions

### Q: Why does the streaming card display as "[Generating...]" or a fixed summary text in the Feishu client chat message preview instead of the actual card content?

![image.png](//sf3-cn.feishucdn.com/obj/open-platform-opendoc/49b7142e1c0c8b15e3b5c84e3a5a09bd_bJouLf3G2r.png?height=769&lazyload=true&maxWidth=300&width=672)

- **If the message preview shows "[Generating...]"**:

"[Generating...]" is the default summary for a card in streaming mode. This means the card has enabled the streaming update mode. You need to follow these steps to disable the card's streaming update mode:

- If you sent the card based on a template ID generated by the builder tool, you need to click the settings button in the upper right corner of the builder tool and disable the card's streaming update mode.

- If you sent the card based on the card JSON, you need to call the [Update Card Configuration](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/cardkit-v1/card/settings) API and set the `streaming_mode` field to `false` to terminate the card's streaming update mode.

- **If the message preview shows your custom summary text**:

Disabling the streaming update mode will not change the custom summary text defined by the developer. You can call the [Update Card Configuration](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/cardkit-v1/card/settings) API to modify this summary content by changing the value of `summary.content`.

### Q: Why can't a streaming card be forwarded, and how to resolve it?

A card with the streaming update mode enabled cannot be forwarded. You need to call the [Update Card Configuration](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/cardkit-v1/card/settings) API and set the `streaming_mode` field to `false` to disable the streaming update mode.

### Q: Does a streaming card support updating the card through interactive updates?

In the streaming update mode, the card does not support updating directly by responding to the [Card Interaction Callback](https://open.feishu.cn/document/uAjLw4CM/ukzMukzMukzM/feishu-cards/card-callback-communication). You need to first disable the streaming update mode and then handle the card callback. The specific steps are as follows:

1. After the card text streaming update is complete, call the [Update Card Configuration](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/cardkit-v1/card/settings) API and set the `streaming_mode` field to `false` to terminate the card's streaming update mode.
2. Refer to [Handling Card Callbacks](https://open.feishu.cn/document/uAjLw4CM/ukzMukzMukzM/feishu-cards/handle-card-callbacks) to process the callback request normally. When updating the card, you can continue to call card and component-level APIs to partially update the card.