> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sub2api.ruilinlu.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 快速开始：5 分钟完成第一次 API 调用

> 从登录、获取 API Key 到发出第一条请求，带你用 5 分钟完成 Sub2API 的完整接入流程。

本指南带你完成 Sub2API 的首次接入，从登录控制台到发出成功的 AI 模型调用，整个过程只需几分钟。你需要先拥有一个 Sub2API 账号和 API Key。

<Steps>
  <Step title="登录控制台">
    打开 [Sub2API 登录页面](https://sub2api.ruilinlu.com/login)，输入你的邮箱和密码登录。

    由于当前自助注册已暂停，如果你还没有账号，请联系管理员申请开通。
  </Step>

  <Step title="创建 API Key">
    登录后，进入 API Key 管理页面创建一个新的 Key。创建完成后请妥善保存，Key 只会显示一次。

    详细步骤请参考 [创建 API Key](/getting-started/create-api-key)。
  </Step>

  <Step title="配置 Base URL">
    将 Base URL 设置为 Sub2API 的网关地址：

    ```text theme={null}
    https://sub2api.ruilinlu.com
    ```

    如果你使用 OpenAI SDK 或其他兼容客户端，只需把默认的 `https://api.openai.com/v1` 替换为上述地址即可。
  </Step>

  <Step title="发起第一次调用">
    使用 cURL 或 Python 向 `/v1/chat/completions` 发起请求：

    <CodeGroup>
      ```bash cURL theme={null}
      curl https://sub2api.ruilinlu.com/v1/chat/completions \
        -H "Authorization: Bearer YOUR_API_KEY" \
        -H "Content-Type: application/json" \
        -d '{
          "model": "gpt-4o",
          "messages": [
            {"role": "user", "content": "你好"}
          ]
        }'
      ```

      ```python Python theme={null}
      from openai import OpenAI

      client = OpenAI(
          base_url="https://sub2api.ruilinlu.com",
          api_key="YOUR_API_KEY",
      )

      response = client.chat.completions.create(
          model="gpt-4o",
          messages=[{"role": "user", "content": "你好"}],
      )
      print(response.choices[0].message.content)
      ```
    </CodeGroup>

    如果配置正确，你会收到类似如下的 JSON 响应：

    ```json theme={null}
    {
      "id": "chatcmpl-xxx",
      "object": "chat.completion",
      "created": 1710000000,
      "model": "gpt-4o",
      "choices": [
        {
          "index": 0,
          "message": {
            "role": "assistant",
            "content": "你好！有什么我可以帮助你的吗？"
          },
          "finish_reason": "stop"
        }
      ],
      "usage": {
        "prompt_tokens": 4,
        "completion_tokens": 14,
        "total_tokens": 18
      }
    }
    ```
  </Step>
</Steps>

<Tip>
  想查看更完整的示例（包括 Node.js、切换 Claude / Gemini 模型等）？请阅读 [第一次 API 调用完整示例](/getting-started/first-api-call)。
</Tip>
