Define server URLs and environments to help users connect to your API.

OpenAPI allows you to specify one or more base URLs under the servers key.

openapi.yml
1servers:
2 - url: https://api.yourcompany.com/
3 - url: https://api.eu.yourcompany.com/

Specifying servers is valuable for both SDKs and Docs:

  • For SDKs, your users won’t need to manually specify the baseURL at client instantiation
  • For Docs, your API playground will automatically hit the correct server

Naming your servers

If you have more than one server, we recommend specifying an x-fern-server-name to name the server.

1servers:
2 - x-fern-server-name: Production
3 url: https://api.yourcompany.com/
4 - x-fern-server-name: Production_EU
5 url: https://api.eu.yourcompany.com/

Multiple Base URLs for a single API

If you have a microservice architecture, it is possible that you may have different endpoints hosted at differnt URLs. For example, your AI endpoints might be hosted at ai.yourcompany.com and the rest of your endpoins might be hosted at api.yourcompany.com.

To specify this, you will need to add configuration to both your generators.yml and OpenAPI spec. The snippet directly below shows how to configure an environment with multiple urls in your generators.yml.

1api:
2 default-environment: Production
3 default-url: api
4 environments:
5 Production:
6 api: api.yourcompany.com
7 ai: ai.yourcompany.com
8 specs:
9 - openapi: ./path/to/your/openapi
10 overrides: ./path/to/your/overrides # optional

Once you’ve specified the environments in your generators.yml, you can use the x-fern-server-name extension to specify which server the operation belongs to.

1paths:
2 /chat:
3 post:
4 x-fern-server-name: ai

If you have multiple environments like development or staging, you can model those in your generators.yml as well.

1api:
2 default-environment: Production
3 default-url: api
4 environments:
5 Production:
6 api: api.yourcompany.com
7 ai: ai.yourcompany.com
8 Staging:
9 api: api.staging.yourcompany.com
10 ai: ai.staging.yourcompany.com
11 Dev:
12 api: api.dev.yourcompany.com
13 ai: ai.dev.yourcompany.com
To see an example of this in production, check out the Chariot generators.yml
Built with