Authentication
Fern Definition isn’t recommended for new customers and Fern isn’t accepting feature requests for this format. It remains supported for existing users.
Configuring authentication schemes happens in the api.yml file. All Fern-generated SDKs support both direct configuration and environment variables for authentication credentials.
To add an authentication scheme, specify the authentication method under the auth-schemes section.
Every scheme accepts docs, which appears in the API Reference’s Authorization section, and playground-docs, which appears only beneath the scheme’s input in the API Explorer:
To apply an authentication scheme across all endpoints, reference the auth-scheme within the auth section of your api.yml file.
Bearer authentication
Start by defining a Bearer authentication scheme in api.yml:
This will generate an SDK where the user would have to provide
a mandatory argument called token.
If you want to control variable naming and the environment variable to scan, use the configuration below:
The generated SDK would look like:
Basic authentication
Start by defining a Basic authentication scheme in api.yml:
This will generate an SDK where the user would have to provide
a mandatory arguments called username and password.
If you want to control variable naming and environment variables to scan, use the configuration below:
The generated SDK would look like:
Custom header (e.g. API key)
You can also create your own authentication scheme with customized headers.
This will generate an SDK where the user would have to provide
a mandatory argument called apiKey.
If you want to control variable naming and environment variables to scan, use the configuration below:
The generated SDK would look like:
OAuth client credentials
If your API uses OAuth, you can specify an oauth scheme in api.yml and define a token retrieval endpoint in a separate auth.yml file (example).
The request-properties and response-properties map OAuth standard parameters to your actual endpoint’s request and response field names defined in auth.yml.
If the expires-in property is set, the generated OAuth token provider will automatically refresh the token when it expires. Otherwise, it’s assumed that the access token is valid indefinitely.
The corresponding auth.yml file (example) defines the token endpoint:
With this, all of the OAuth logic happens automatically in the generated SDKs. As long as you configure these settings, your client will automatically retrieve an access token and refresh it as needed.
When using the docs playground, token-header and token-prefix can optionally be set to customize the header key name and
header value prefix, to match the expected format of the API auth scheme.
For example, the following would produce a header Fern-Authorization: Fern-Bearer <token>:
Refresh token exchange
If your API issues a long-lived refresh token and exchanges it for short-lived access tokens, define a bearer scheme with a get-token endpoint and type: refresh-token. The generated SDK takes the user’s refresh token, calls the get-token endpoint, and sends the returned access token with requests.
The get-token endpoint must have a grant_type request property that accepts refresh_token. The SDK always sends grant_type=refresh_token and doesn’t expose grant_type as a client option. fern check fails if the property is missing or is a literal other than refresh_token.
type defaults to api-key. Refresh token exchange is supported in the Python, TypeScript, and Java SDK generators. For refresh token rotation and version requirements, see the refresh token exchange reference.