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 定义?
    • 项目结构
      • 概览
      • 身份验证
      • 类型
        • 概览
        • 环境
        • 全局请求头
        • 错误
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
预约演示登录免费开始
在本页
  • 单URL环境
  • 每个环境多个URL
  • 默认环境
  • URL模板
  • 基础路径
  • 受众
Fern 定义api.yml 参考

环境

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

api.yml 配置文件

下一个

全局配置

您可以指定部署服务器的环境。

单URL环境

api.yml
1name: api
2environments:
3 Production: https://www.yoursite.com
4 Staging:
5 docs: This staging environment is helpful for testing!
6 url: https://www.staging.yoursite.com

每个环境多个URL

您可以为每个环境指定多个URL。如果您有微服务架构,并希望单个SDK与多个服务器交互,这将很有帮助。

api.yml
1environments:
2 Production:
3 urls:
4 Auth: https://auth.yoursite.com
5 Plants: https://plants.yoursite.com
6 Staging:
7 urls:
8 Auth: https://auth.staging.yoursite.com
9 Plants: https://plants.staging.yoursite.com

如果您选择使用此功能,必须为定义的每个服务指定一个url:

auth.yml
1service:
2 url: Auth
3 base-path: /auth
4 ...

默认环境

您还可以提供默认环境:

api.yml
1name: api
2environments:
3 Production: https://www.yoursite.com
4 Staging:
5 docs: This staging environment is helpful for testing!
6 url: https://www.staging.yoursite.com
7default-environment: Production
通过提供默认环境,生成的SDK将设置为开箱即用地访问该URL。

URL模板

URL模板目前仅支持Python和Java SDK生成。

对于跨多个区域或环境部署的API,您可以定义带有变量占位符的URL模板,SDK用户可以在运行时自定义。设置方法:

  1. 在urls下定义静态基础URL——这些将出现在生成的环境枚举中。
  2. 为每个服务添加带有{variable}占位符的url-templates(例如,https://api.{region}.example.com/v1)。Fern将这些作为SDK中的可配置参数公开。
  3. 提供default-urls作为具体的后备方案,以便SDK用户无需提供变量即可获得开箱即用的客户端。
  4. 列出每个服务的可用variables,每个变量具有id、default值和可选的values列表来约束允许的选项。
api.yml
1environments:
2 RegionalApiServer:
3 urls:
4 Base: https://api.example.com/v1
5 Auth: https://auth.example.com
6 url-templates:
7 Base: https://api.{region}.{environment}.example.com/v1
8 Auth: https://auth.{region}.example.com
9 default-urls:
10 Base: https://api.example.com/v1
11 Auth: https://auth.example.com
12 variables:
13 Base:
14 - id: region
15 default: us-east-1
16 values:
17 - us-east-1
18 - us-west-2
19 - eu-west-1
20 - id: environment
21 default: prod
22 values:
23 - prod
24 - staging
25 - dev
26 Auth:
27 - id: region
28 default: us-east-1
29 values:
30 - us-east-1
31 - us-west-2
32 - eu-west-1
33default-environment: RegionalApiServer

基础路径

如果您希望所有端点都带有路径前缀,请使用base-path。

在下面的示例中,每个端点都带有/v1前缀:

api.yml
1name: api
2base-path: /v1

受众

如果您有想要筛选的已列出环境,可以利用受众功能。

api.yml
1audiences:
2 - public
3
4environments:
5 Dev:
6 url: https://api.dev.buildwithfern.com
7 Prod:
8 url: https://api.buildwithfern.com
9 audiences:
10 - external