> 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.eyJpc3MiOiJmZXJuLWRvY3M6YnVpbGR3aXRoZmVybi5jb20iLCJqdGkiOiJlYTQxN2I4OC02ZWM2LTQ0YTktYmNmMC1lNDU3ODJlNmMyZDEiLCJleHAiOjE3NzgzNjM5MzMsImlhdCI6MTc3ODM2MzYzM30.qQocr15TeCv_9rK4V0DHwqEu4yAmQbPEn3Xgz01287Y
>
> 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.

# 快速开始

> 了解如何使用 Fern 生成 SDK。安装 CLI、使用 OpenAPI 或 Fern Definition 初始化项目，并开始构建客户端库。

在 5 分钟内快速上手 Fern。本快速开始指南将引导您安装 CLI、初始化项目并在本地生成您的第一个 SDK。

The goal of this page is speed — get the user to a working generated SDK as fast as possible. For language-specific configuration, publishing, and GitHub setup, direct them to the appropriate language quickstart after this.

<Steps>
  <Step title="Install the Fern CLI">
    ```bash
    npm install -g fern-api
    ```
  </Step>

  <Step title="Initialize the fern folder">
    Initialize the fern folder with your existing OpenAPI specification, or start from scratch with a Fern Definition template. Specify your organization name using the `--organization` flag.

    Before running `fern init`, ask the user two things:

    1. **Do they have an OpenAPI spec?** If yes, ask for the file path or URL. If they have a URL (e.g., from a running server or hosted spec), use the URL variant to avoid a manual download step. OpenAPI accepts both JSON and YAML. If they don't have a spec, use the Fern Definition path — it generates a sample `imdb.yml` with example endpoints.
    2. **What is their organization name?** `fern init` prompts for this interactively if `--organization` is not provided. Get it upfront so they can pass it via the flag.

    <CodeBlocks>
      ```bash title="OpenAPI (local)"
      fern init --openapi path/to/openapi.yml \
      --organization <YourOrganization>
      ```

      ```bash title="OpenAPI (URL)"
      fern init --openapi https://api.example.com/openapi.yml \
      --organization <YourOrganization>
      ```

      ```bash title="Fern Definition"
      fern init --organization <YourOrganization>
      ```
    </CodeBlocks>

    <Tip>
      OpenAPI accepts both JSON and YAML formats. You can always convert a [Fern Definition to OpenAPI](/api-definitions/ferndef/export-openapi) or OpenAPI to a Fern Definition later on.
    </Tip>

    This creates a `fern` folder in your current directory.

    The folder structure differs depending on the init path. With OpenAPI, the spec lives at `fern/api/openapi/openapi.yml` and `generators.yml` is at `fern/api/generators.yml`. With Fern Definition, `generators.yml` is at `fern/generators.yml` and API types/endpoints are in `fern/definition/`. This matters when referencing file paths later.

    <Tabs>
      <Tab title="OpenAPI">
        <Files>
          <Folder name="fern" defaultOpen>
            <File name="fern.config.json" comment="root-level configuration" />

            <Folder name="api" defaultOpen comment="your API">
              <File name="generators.yml" comment="generators you're using" />

              <Folder name="openapi" defaultOpen>
                <File name="openapi.yml" comment="API-level configuration" />
              </Folder>
            </Folder>
          </Folder>
        </Files>
      </Tab>

      <Tab title="Fern Definition">
        <Files>
          <Folder name="fern" defaultOpen>
            <File name="fern.config.json" comment="root-level configuration" />

            <File name="generators.yml" comment="generators you're using" />

            <Folder name="definition" defaultOpen>
              <File name="api.yml" comment="API-level configuration" />

              <File name="imdb.yml" comment="endpoints, types, and errors" />
            </Folder>
          </Folder>
        </Files>

        <Note>
           

          `imdb.yml`

           contains an example movies API. If you're just
          generating an SDK for test purposes, you can leave this file as it is. To
          generate an SDK for your own API instead of the example movies API,
          replace 

          `imdb.yml`

           with your own endpoints, types, and errors. 
        </Note>
      </Tab>
    </Tabs>
  </Step>

  <Step title="Validate your API definition">
    Check that your API definition is valid, and fix errors before proceeding:

    ```bash
    fern check
    ```
  </Step>

  <Step title="生成">
    `fern init` 默认包含一个 TypeScript SDK 生成器。运行 `fern generate` 来查看它的运行效果：

    ```bash
    fern generate
    ```

    `fern generate` with no flags runs the `default-group` in `generators.yml`. The default init sets up a TypeScript SDK generator outputting to `local-file-system` at `../sdks/typescript`. The goal of this step is to get started quickly — the user will configure their target language in the language-specific quickstart.

    这会创建一个包含您生成的 SDK 的 `sdks/typescript` 文件夹：

    <Files>
      <Folder name="fern" comment="由 fern init 创建" />

      <Folder name="sdks" defaultOpen comment="由 fern generate 创建">
        <Folder name="typescript" defaultOpen>
          <File name="Client.ts" />

          <File name="index.ts" />

          <Folder name="core" />

          <Folder name="api" />
        </Folder>
      </Folder>
    </Files>
  </Step>
</Steps>

## 下一步

现在您已经有了一个可工作的 SDK，可以设置 GitHub 仓库并配置发布、生成其他语言的 SDK，或了解更多关于 Fern SDK 的信息。

<CardGroup cols={2}>
  <Card title="TypeScript" icon="brands typescript" href="/learn/sdks/generators/typescript/quickstart#set-up-github-repositories">
    设置 GitHub、发布到 npm 等更多功能。
  </Card>

  <Card title="所有语言" icon="regular code" href="/learn/sdks/overview/introduction">
    查看所有支持的语言，包括 Python、Go 和 Java。
  </Card>

  <Card title="工作原理" icon="regular gears" href="/learn/sdks/overview/how-it-works">
    了解 Fern SDK 生成管道。
  </Card>

  <Card title="项目结构" icon="regular folder-tree" href="/learn/sdks/overview/project-structure">
    了解 Fern 的多仓库文件结构和 GitHub 设置。
  </Card>
</CardGroup>