Filter Your Endpoints (Audiences)
Use audiences to generate tailored SDKs for different groups of API consumers. Common examples of audiences include:
- Internal consumers (e.g., frontend developers who use the API)
- Beta testers
- Customers
Learn how to use audiences to filter which endpoints are included in your SDKs and documentation.
Configuring audiences
For both the Fern Definition and OpenAPI spec, configuring audiences involves:
- Marking your API elements with audience tags.
- Applying filters in
generators.yml
. Without filtering configuration, all endpoints will be included in your SDK regardless of their audience tags.
Fern Definition
Configuring audiences in a Fern Definition involves:
- Explicitly defining audiences in
api.yml
. - Configuring audiences for specific endpoints, types, and properties.
- Apply audience filters to your SDK so only certain endpoints are passed to the generators.
Defining audiences
Audiences are explicitly declared in Fern Definition.
To use audiences in your Fern Definition, add them to api.yml
.
In the example below, we have created audiences for internal
, beta
, and customer
groups:
Apply audiences to your endpoints, types, and properties
Once you’ve defined audiences, mark endpoints, types, or properties for a
particular consumer by adding an audience
with the relevant groups.
Endpoints
In this example, the sendEmail
endpoint is only available to internal consumers:
Types
Types can also be marked for different audiences.
In this example, the Email
type is available to internal and beta consumers:
Properties
In this example, the to
property is available to beta consumers only:
OpenAPI
Configuring audiences in an OpenAPI spec involves:
- Configuring audience extensions for specific servers, endpoints, schemas, and properties.
- Apply audience filters to your SDK so only certain endpoints are passed to the generators.
Unlike the Fern Definition, OpenAPI doesn’t have a central audience declaration.
Define audiences
OpenAPI uses x-fern-audiences
to filter to servers, endpoints, schemas and properties.
Servers
To mark a server with a particular audience, add the x-fern-server-name
and x-fern-audiences
extension to the relevant server.
In the example below, the Production
server is only available to public consumers:
Endpoints
To mark an endpoint with a particular audience, add the x-fern-audiences
extension to the relevant endpoint.
In the example below, the POST /users/sendEmail
endpoint is only available to public consumers:
Schemas
Schemas can be marked for different audiences, as well.
In this example, the Email
type is available to both public and beta customers.
Properties
In this example, the to
property is available to beta customers only.