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.
预约演示登录免费开始
  • 使用 SDK
    • SDK 概述
    • SDK 如何工作
    • Quickstart
    • Customer showcase
  • 使用 SDK
    • 项目结构
    • 添加自定义代码
    • Migrating to Replay
    • 功能特性
  • 参考
      • SDK 用户特性
      • 自定义 README
      • 自定义方法名称
      • 按受众过滤端点
      • 服务器 URL 模板化
      • Webhook 签名验证
  • 资源
    • generators.yml
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
预约演示登录免费开始
在本页
  • 生成的 SDK 行为
  • 设置服务器 URL 模板化
SDK 设计

服务器 URL 模板化

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

过滤你的端点(受众)

下一个

Webhook 签名验证

服务器 URL 模板化让你可以定义带有变量占位符的基础 URL(例如 {region}、{environment}),SDK 用户可以在运行时自定义这些变量。这对于部署在多个区域、环境或自定义域名的 API 非常有用。

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

生成的 SDK 行为

Fern 生成一个环境模块,它暴露了每个命名服务器的默认 URL。SDK 用户可以选择预定义的环境或传递自定义 URL 字符串。

Python
Java

生成的 SDK 暴露了一个 Environment 类:

environment.py
1class MyApiEnvironment:
2 REGIONAL_API_SERVER = {
3 "base": "https://api.example.com/v1",
4 "auth": "https://auth.example.com",
5 }

SDK 用户可以在构造客户端时覆盖基础 URL:

1from my_api import MyApiClient
2
3# 使用默认环境
4# → https://api.example.com/v1
5client = MyApiClient()
6
7# 通过 URL 变量指定特定区域和环境
8# → https://api.eu-west-1.staging.example.com/v1
9client = MyApiClient(
10 region="eu-west-1",
11 environment="staging",
12)
13
14# 或者提供自定义基础 URL
15# → https://api.us-west-2.staging.example.com/v1
16client = MyApiClient(
17 base_url="https://api.us-west-2.staging.example.com/v1",
18)

设置服务器 URL 模板化

在你的 API 定义中定义 URL 模板变量,并为不自定义变量的 SDK 用户提供静态回退 URL:

openapi.yml
1servers:
2 - url: https://api.{region}.{environment}.example.com/v1
3 x-fern-server-name: Default
4 x-fern-default-url: https://api.example.com/v1
5 variables:
6 region:
7 default: us-east-1
8 enum: [us-east-1, us-west-2, eu-west-1]
9 environment:
10 default: prod
11 enum: [prod, staging, dev]

有关完整配置详情,请参阅 OpenAPI 中的服务器名称和 URL 模板化。