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

# 快速开始

> 复制代码跑通第一个文本或图片请求

三步：注册拿 Key、复制代码、拿到结果。第一次接入建议先用 OpenAI 兼容路径跑通一个最小请求，再按业务场景进入文本 API、图片 API 或后续视频 API。

<Warning>不要把 `sk-` API Key 放进浏览器前端、移动端包、公开仓库或截图里。前端产品请通过自己的后端代理调用 Tapapi。</Warning>

<Steps>
  <Step title="注册拿 API Key">
    在 [控制台](https://tapapi.ai) 注册并创建 API Key（`sk-` 开头）。
  </Step>

  <Step title="确认 base_url">
    Tapapi 的 OpenAI 兼容入口是：

    ```text theme={null}
    https://tapapi.ai/v1
    ```

    所有请求都需要带上 `Authorization: Bearer sk-xxx`。
  </Step>

  <Step title="跑通文本请求">
    文本请求走 `POST /v1/chat/completions`。下面示例使用 `gpt-5.4`；如果控制台推荐模型不同，以控制台为准。

    <CodeGroup>
      ```bash cURL theme={null}
      curl https://tapapi.ai/v1/chat/completions \
        -H "Authorization: Bearer sk-xxx" \
        -H "Content-Type: application/json" \
        -d '{
          "model": "gpt-5.4",
          "messages": [
            {"role": "user", "content": "用一句话解释 Tapapi 是什么"}
          ]
        }'
      ```

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

      client = OpenAI(api_key="sk-xxx", base_url="https://tapapi.ai/v1")

      resp = client.chat.completions.create(
          model="gpt-5.4",
          messages=[
              {"role": "user", "content": "用一句话解释 Tapapi 是什么"}
          ],
      )

      print(resp.choices[0].message.content)
      ```

      ```javascript Node.js theme={null}
      import OpenAI from "openai";

      const client = new OpenAI({
        apiKey: "sk-xxx",
        baseURL: "https://tapapi.ai/v1",
      });

      const resp = await client.chat.completions.create({
        model: "gpt-5.4",
        messages: [
          { role: "user", content: "用一句话解释 Tapapi 是什么" },
        ],
      });

      console.log(resp.choices[0].message.content);
      ```
    </CodeGroup>
  </Step>

  <Step title="跑通图片请求">
    图片生成请求走 `POST /v1/images/generations`。下面示例使用 `nano-banana-pro`；如果控制台推荐模型不同，以控制台为准。

    <CodeGroup>
      ```bash cURL theme={null}
      curl https://tapapi.ai/v1/images/generations \
        -H "Authorization: Bearer sk-xxx" \
        -H "Content-Type: application/json" \
        -d '{
          "model": "nano-banana-pro",
          "prompt": "a red apple on a wooden table",
          "n": 1,
          "response_format": "url",
          "size": "1024x1024"
        }'
      ```

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

      client = OpenAI(api_key="sk-xxx", base_url="https://tapapi.ai/v1")

      resp = client.images.generate(
          model="nano-banana-pro",
          prompt="a red apple on a wooden table",
          n=1,
          response_format="url",
          size="1024x1024",
      )

      if not resp.data:
          raise RuntimeError("Tapapi returned empty image data")

      item = resp.data[0]
      print(item.url or item.b64_json)
      ```

      ```javascript Node.js theme={null}
      import OpenAI from "openai";

      const client = new OpenAI({ apiKey: "sk-xxx", baseURL: "https://tapapi.ai/v1" });

      const resp = await client.images.generate({
        model: "nano-banana-pro",
        prompt: "a red apple on a wooden table",
        n: 1,
        response_format: "url",
        size: "1024x1024",
      });

      if (!resp.data?.length) {
        throw new Error("Tapapi returned empty image data");
      }

      const item = resp.data[0];
      console.log(item.url || item.b64_json);
      ```
    </CodeGroup>
  </Step>

  <Step title="拿到结果">
    文本请求返回 `choices[0].message.content`；图片请求通常返回 `data[0].url`，也可能返回 `data[0].b64_json`。生产环境建议把图片转存到自己的对象存储。
  </Step>
</Steps>

<Note>如果请求失败，记录 HTTP 状态码、错误 message 和响应头里的 `X-Oneapi-Request-Id`，再看 [错误码与重试](/errors)。快速开始只放 cURL、Python 和 Node.js。更多语言看 [Python](/integrations/python)、[Node.js / TypeScript](/integrations/node-typescript)、[PHP / Laravel](/integrations/php-laravel) 和 [HTTP REST](/integrations/http-rest)。接文本模型看 [文本 API](/text-generation/overview)；接图片模型看 [图片 API](/image-generation/overview)；接视频模型看 [视频 API](/video-generation/overview)，生产前先确认控制台权限和价格。</Note>
