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

# 快速接入 API

> 用四个步骤完成 Xcompute 的首次接口调用。

这份快速开始适合已经准备好接入代码的开发者。你将完成 API Key 创建、模型选择、第一次请求发送，以及异步任务状态查询。

<Steps>
  <Step title="获取 API Key">
    1. 访问 [API 密钥管理页面](https://xcompute.us/keys)。
    2. 登录你的账户。
    3. 创建新的 API Key。

    <Frame>
      <img src="https://mintcdn.com/leaddream/P6N_xmP_YUzrMKmk/images/image.png?fit=max&auto=format&n=P6N_xmP_YUzrMKmk&q=85&s=2797ec170370f07dbe9affd39f42acf2" alt="API 密钥管理页面" width="1600" height="771" data-path="images/image.png" />
    </Frame>

    4. 复制生成的密钥并安全保存。

    <Frame>
      <img src="https://mintcdn.com/leaddream/P6N_xmP_YUzrMKmk/images/image-1.png?fit=max&auto=format&n=P6N_xmP_YUzrMKmk&q=85&s=8d14bef1d61e73986c3b590b28822361" alt="复制 API Key" width="723" height="292" data-path="images/image-1.png" />
    </Frame>
  </Step>

  <Step title="选择模型">
    打开模型广场，选择最符合你任务目标的模型。

    <Frame>
      <img src="https://mintcdn.com/leaddream/P6N_xmP_YUzrMKmk/images/image-2.png?fit=max&auto=format&n=P6N_xmP_YUzrMKmk&q=85&s=d73f64da65e5270066c713b0c361bfeb" alt="模型广场" width="1600" height="768" data-path="images/image-2.png" />
    </Frame>

    推荐思路：

    * 需要稳定的文本和代码生成，优先选择通用对话模型。
    * 需要生图或视频能力，优先选择对应的多模态模型。
    * 先小规模测试，再根据质量、速度和价格调整模型。
  </Step>

  <Step title="发送第一条请求">
    下面的示例使用兼容 OpenAI 的接口格式。将 `YOUR_API_KEY` 替换为你的真实密钥即可。

    <Tabs>
      <Tab title="文本生成">
        ```bash theme={null}
        curl -X POST https://xcompute.us/v1/chat/completions \
          -H "Authorization: Bearer YOUR_API_KEY" \
          -H "Content-Type: application/json" \
          -d '{
            "model": "gpt-4o",
            "messages": [
              {
                "role": "user",
                "content": "你好，请介绍一下你自己"
              }
            ]
          }'
        ```
      </Tab>

      <Tab title="图像生成">
        ```bash theme={null}
        curl -X POST https://xcompute.us/v1/images/generations \
          -H "Authorization: Bearer YOUR_API_KEY" \
          -H "Content-Type: application/json" \
          -d '{
            "model": "gpt-4o-image",
            "prompt": "一只可爱的熊猫",
            "size": "1:1",
            "n": 1
          }'
        ```
      </Tab>

      <Tab title="视频生成">
        ```bash theme={null}
        curl -X POST https://xcompute.us/v1/videos/generations \
          -H "Authorization: Bearer YOUR_API_KEY" \
          -H "Content-Type: application/json" \
          -d '{
            "model": "sora-2",
            "prompt": "海浪拍打着海岸",
            "duration": 15,
            "aspect_ratio": "16:9"
          }'
        ```
      </Tab>
    </Tabs>
  </Step>

  <Step title="查询异步任务状态">
    图像和视频任务通常会异步处理。你可以用任务 ID 查询执行状态和最终结果。

    ```bash theme={null}
    curl -X GET https://xcompute.us/v1/tasks/YOUR_TASK_ID \
      -H "Authorization: Bearer YOUR_API_KEY"
    ```
  </Step>
</Steps>

<Warning>
  不要在前端代码、公开仓库或截图中暴露你的 API Key。建议按应用和环境拆分不同密钥。
</Warning>

## 下一步

<Columns cols={3}>
  <Card title="Claude Code 接入" icon="terminal" href="/claude-code">
    把 Xcompute 接入终端编程工作流。
  </Card>

  <Card title="Codex 接入" icon="code" href="/codex">
    通过 Codex CLI 接入 Xcompute。
  </Card>

  <Card title="OpenClaw 接入" icon="bot" href="/openclaw">
    将自托管 AI 助手接入 Xcompute。
  </Card>

  <Card title="OpenCode 接入" icon="square-code" href="/opencode">
    在开源代码 Agent 工具里配置 Xcompute。
  </Card>
</Columns>
