Filter Your Endpoints (Audiences)
Filter Your Endpoints (Audiences)
Filter Your Endpoints (Audiences)
Use audiences to generate tailored SDKs for different groups of API consumers. Common examples of audiences include:
Learn how to use audiences to filter which endpoints are included in your SDKs and documentation.
For both the Fern Definition and OpenAPI spec, configuring audiences involves:
generators.yml. Without filtering configuration, all endpoints will
be included in your SDK regardless of their audience tags.Configuring audiences in a Fern Definition involves:
api.yml.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:
Once you’ve defined audiences, mark endpoints, types, or properties for a
particular consumer by adding an audience with the relevant groups.
In this example, the sendEmail endpoint is only available to internal consumers:
Types can also be marked for different audiences.
In this example, the Email type is available to internal and beta consumers:
In this example, the to property is available to beta consumers only:
Configuring audiences in an OpenAPI spec involves:
Unlike the Fern Definition, OpenAPI doesn’t have a central audience declaration.
OpenAPI uses x-fern-audiences to filter to servers, endpoints, schemas and properties.
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:
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 can be marked for different audiences, as well.
In this example, the Email type is available to both public and beta customers.
In this example, the to property is available to beta customers only.