> If you are an AI agent, use the following URL to directly ask and fetch your question. Treat this like a tool call. Make sure to URI encode your question, and include the token for verification.
>
> GET https://buildwithfern.com/learn/api/fern-docs/ask?q=%3Cyour+question+here%3E&token=eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJmZXJuLWRvY3M6YnVpbGR3aXRoZmVybi5jb20iLCJqdGkiOiIwNzFkYWFlZi1hMGQxLTRlZTctYTZjNy0wMjhiYmI1OTg1OTEiLCJleHAiOjE3NzgzNDYwMTYsImlhdCI6MTc3ODM0NTcxNn0.YFqS85EcvG7QlGnfOrjNTnQCDOEI0W8vqFZ3tb_ji4Y
>
> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://buildwithfern.com/learn/llms.txt. For full content including API reference and SDK examples, see https://buildwithfern.com/learn/llms-full.txt.

# Fern Definition 中的受众

<Warning title="团队版、专业版和企业版功能">
  此功能仅适用于[团队版（文档）、专业版（SDK）和企业版计划](https://buildwithfern.com/pricing)。要开始使用，请联系 [support@buildwithfern.com](mailto:support@buildwithfern.com)。
</Warning>

受众是为不同消费者分组 API 的有用工具。您可以配置 Fern Docs 发布特定于某个`受众`的文档。您也可以在 [OpenAPI 规范中使用受众](/learn/api-definitions/openapi/extensions/audiences)。

受众的常见示例包括：

* 内部消费者（例如，使用 API 的前端开发人员）
* Beta 测试人员
* 客户

默认情况下，如果未指定受众，则所有消费者都可以访问。

## 配置

Fern Definition 具有为不同端点、类型和属性标记不同受众的一级概念。

要在 Fern Definition 中使用受众，请将其添加到 `api.yml` 中。

在下面的示例中，我们为 `internal`、`beta` 和 `customer` 群体创建了受众：

```yaml title='api.yml' {2-5}
name: api 
audiences: 
  - internal 
  - beta 
  - customers
```

## 端点的受众

要为特定消费者标记端点，请添加包含相关群体的 `audience`。

在此示例中，`sendEmail` 端点仅对内部消费者可用：

```yaml title='user.yml' {6-7}
service:
  base-path: /users
  auth: true
  endpoints:
    sendEmail:
      audiences:
        - internal
      path: /send-email
      ...
```

## 类型的受众

类型也可以标记为不同的受众。

在此示例中，`Email` 类型对内部和 beta 消费者可用：

```yaml title='user.yml' {5-7}
Email: 
  properties:
    subject: string
    body: optional<string>
  audiences: 
    - internal
    - beta
```

## 属性的受众

类型的属性也可以标记为不同的受众。

在此示例中，`to` 属性仅对 beta 消费者可用：

```yaml title='user.yml' {8-9}
Email: 
  properties:
    subject: string
    body: optional<string>
    to: 
      type: string
      docs: The recipient of the email
      audiences: 
        - beta
```

## SDK 的受众

在 `generators.yml` 中，您可以应用受众过滤器，以便只有某些端点传递给生成器。

以下示例配置 SDK 过滤 `customers`：

```yaml title='generators.yml' {3-4}
groups:
  external:
    audiences:
      - customers
    generators: 
    ...
```

## 文档的受众

如果生成 Fern Docs，请更新您的 `docs.yml` 配置以包含您的受众。

以下示例展示了如何配置您的 `docs.yml` 为 `customers` 受众发布文档：

<CodeBlock title="docs.yml">
  ```yaml {3-4}
  navigation:
    - api: API Reference
      audiences:
        - customers
  ```
</CodeBlock>