For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
预约演示登录免费开始
  • 概览
    • 什么是 API 定义?
    • 项目结构
      • 概览
      • 身份验证
      • 类型
        • 概览
        • HTTP JSON 端点
        • 多部分表单上传
        • 字节
        • 服务器发送事件
Checking status...
SOC2Soc 2 Type II
© 2026 Fern • Birch Solutions, Inc., a Postman company

Documentation

SDKsDocsAsk FernCLI Reference

API Definitions

OpenAPIAsyncAPIOpenRPCgRPC

Resources

BlogSupportPricing

Company

Brand KitPrivacy PolicyTerms of Service
LogoLogo
预约演示登录免费开始
在本页
  • JSON 流
  • 服务器发送事件
  • Stream 参数
Fern 定义端点

服务器发送事件和流式 API

使用 response-stream 键来建模流式端点

||以 Markdown 格式查看|
此页面是否有帮助?
在仪表板中编辑
上一个

二进制数据和文件

下一个

Fern 定义中的 Webhooks

团队版和企业版功能

此功能仅适用于团队版和企业版计划。要开始使用,请联系 support@buildwithfern.com。

在端点上指定 response-stream 允许您表示流式响应的端点。

JSON 流

如果您的 API 返回一系列 JSON 块,如下所示

1{ "text": "Hi, I am a" }
2{ "text": "chatbot. Do you have any"}
3{ "text": "questions for me"}

那么只需在您的端点的 response-stream 下指定响应。

chat.yml
1service:
2 base-path: /chat
3 endpoints:
4 stream:
5 method: POST
6 path: ""
7 response-stream: Chat
8
9types:
10 Chat:
11 properties:
12 text: string

服务器发送事件

如果您的 API 返回服务器发送事件,包含 data 和 event 键,如下所示

1data: { "text": "Hi, I am a" }
2data: { "text": "chatbot. Do you have any"}
3data: { "text": "questions for me"}

那么请确保包含 format: sse。

chat.yml
1service:
2 base-path: /chat
3 endpoints:
4 stream:
5 method: POST
6 path: ""
7 response-stream:
8 type: Chat
9 format: sse
10
11types:
12 Chat:
13 properties:
14 text: string

Stream 参数

对于端点来说,拥有一个 stream 参数来控制响应是否流式传输已经成为常见做法。Fern 以一流的方式支持这种模式。

只需指定 stream-condition 以及普通响应和流式响应:

chat.yml
1service:
2 base-path: /chat
3 endpoints:
4 stream:
5 method: POST
6 path: ""
7 stream-condition: $request.stream
8 request:
9 name: StreamChatRequest
10 body:
11 properties:
12 stream: boolean
13 response: Chat
14 response-stream:
15 type: ChatChunk
16 format: sse
17
18types:
19 Chat:
20 properties:
21 text: string
22 tokens: integer
23 ChatChunk:
24 properties:
25 text: string