> 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.eyJpc3MiOiJmZXJuLWRvY3M6YnVpbGR3aXRoZmVybi5jb20iLCJqdGkiOiI5ZTQzM2Q3YS1mY2MxLTQ0N2EtYTcxOC0zMTczODc4Mjk2NGUiLCJleHAiOjE3ODA1NjA2MDksImlhdCI6MTc4MDU2MDMwOX0.99NvgC1OMG29yYaXOSRCjGWgzD7frUzWUv6U7L_RAPg
>
> 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.

# 服务器

> 配置服务器 URL 和环境以帮助用户连接到您的 API。

OpenAPI 允许您在 `servers` 键下指定一个或多个基础 URL。

```yml openapi.yml 

servers: 
  - url: https://api.yourcompany.com/
  - url: https://api.eu.yourcompany.com/
```

指定服务器对 SDK 和文档都很有价值：

* 对于 SDK，您的用户无需在客户端实例化时手动指定 baseURL
* 对于文档，您的 API 调试工具将自动连接到正确的服务器

## 命名您的服务器

如果您有多个服务器，我们建议指定 `x-fern-server-name` 来为服务器命名。

```yml openapi.yml {3,5}
servers: 
  - x-fern-server-name: Production
    url: https://api.yourcompany.com/
  - x-fern-server-name: Production_EU
    url: https://api.eu.yourcompany.com/
```

## 单个 API 的多个基础 URL

如果您采用微服务架构，可能会有不同的端点托管在不同的 URL 上。例如，您的 AI 端点可能托管在 `ai.yourcompany.com`，而其余端点可能托管在 `api.yourcompany.com`。

要指定这种情况，您需要在 `generators.yml` 和 OpenAPI 规范中都添加配置。下面的代码片段显示了如何在 `generators.yml` 中配置具有多个 URL 的环境。

```yml generators.yml {3-8}
api: 
  default-environment: Production
  default-url: api
  environments: 
    Production: 
      api: api.yourcompany.com
      ai: ai.yourcompany.com
  specs: 
    - openapi: ./path/to/your/openapi
      overrides: ./path/to/your/overrides # optional
```

一旦您在 `generators.yml` 中指定了环境，就可以使用 `x-fern-server-name` 扩展来指定操作所属的服务器。

```yml openapi.yml {4}
paths: 
  /chat: 
    post: 
      x-fern-server-name: ai 
```

如果您有多个环境，如开发或测试环境，也可以在 `generators.yml` 中建模。

```yml generators.yml {7-12}
api: 
  default-environment: Production
  default-url: api
  environments: 
    Production: 
      api: api.yourcompany.com
      ai: ai.yourcompany.com
    Staging: 
      api: api.staging.yourcompany.com
      ai: ai.staging.yourcompany.com    
    Dev: 
      api: api.dev.yourcompany.com
      ai: ai.dev.yourcompany.com          
```

要查看生产环境中的示例，请查看 Chariot [generators.yml](https://github.com/chariot-giving/chariot-openapi/blob/main/fern/apis/2025-02-24/generators.yml)