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 定义?
    • 项目结构
      • 概览
      • 覆盖层(Overlays)
      • 覆盖(Overrides)
      • 身份验证
      • 服务器
      • 同步您的规范
        • 概览
        • API 版本
        • 受众
        • 可用性
        • 基础路径
        • 默认值
        • 枚举描述、名称和可用性
        • API Explorer 控制
        • 全局请求头
        • 忽略元素
        • SDK 变量
        • SDK 方法名称
        • 参数名称
        • 属性名称
        • 幂等性
        • 分页
        • 重试行为
        • Schema 名称
        • 服务器名称和 URL 模板化
        • 模式名称
        • 服务器名称和 URL 模板化
      • OpenAPI 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
预约演示登录免费开始
在本页
  • 在您的 OpenAPI 规范中
  • 默认值
  • 在 generators.yml 中
  • 生成的 SDK 行为
OpenAPI扩展

全局请求头

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

API Explorer 控制

下一个

忽略元素

有时,您的 API 会在每个端点或大部分端点中使用某些请求头,我们称之为”全局请求头”。为了方便起见,生成的 Fern SDK 提供了”全局请求头”功能,可以轻松地在 API 调用中更新它们。以 API 密钥为例,如果我们将 API 密钥声明为全局请求头,用户将能够轻松地插入他们的密钥:

1import os
2
3class Client:
4
5 def __init__(self, *, apiKey: str):

Fern 会自动提取在每个请求或大多数请求中使用的请求头,并将它们标记为全局的。

在您的 OpenAPI 规范中

要将其他请求头标记为全局的,或为全局请求头设置别名,请使用 x-fern-global-headers 扩展:

openapi.yml
1x-fern-global-headers:
2 - header: custom_api_key
3 name: api_key
4 - header: userpool_id
5 optional: true

当您使用 x-fern-global-headers 定义全局请求头时,您必须在 x-fern-examples 中包含它们。

默认值

使用 x-fern-default 为全局请求头设置客户端默认值。生成的 SDK 会将请求头设置为可选,并在调用者省略时发送默认值:

openapi.yml
1x-fern-global-headers:
2 - header: X-API-Version
3 name: version
4 x-fern-default: "2024-02-08"

在 generators.yml 中

或者,您可以将请求头添加到generators.yml 文件中的 api 块:

generators.yml
1api:
2 - openapi: ./path/to/openapi
3 headers:
4 custom_api_key:
5 name: api_key
6 type: string
7 userpool_id:
8 name: userpool_id
9 type: optional<string>

生成的 SDK 行为

两种配置都会产生以下客户端代码:

1import os
2
3class Client:
4
5 def __init__(self, *, apiKey: str, userpoolId: typing.Optional[str])