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

# 快速开始

> 创建一个卡拉OK项目，等待其完成，导出并下载结果

本指南将带你以最快路径使用 `@youka/sdk` 将原始音频文件生成渲染好的卡拉OK视频。

## 开始之前

* Node.js 20 或更高版本
* 在 `YOUKA_API_KEY` 中设置 Youka API key（在 [online.youka.io/account](https://online.youka.io/account) 的 **API keys** 下创建）
* 本地音频文件（`./song.mp3`）或远程 URL

## 安装

```bash theme={null}
npm install @youka/sdk
```

## 创建、等待、导出

```ts theme={null}
import { YoukaClient, YoukaRequestError, YoukaTaskError } from "@youka/sdk";

const client = new YoukaClient({
  apiKey: process.env.YOUKA_API_KEY!,
});

async function main() {
  // 1. 从本地文件创建项目
  const projectOperation = await client.projects.create({
    source: { type: "path", path: "./song.mp3" },
    lyricsSource: { type: "transcribe" },
  });

  // 2. 等待分轨和歌词对齐完成
  const { project } = await client.projects.wait(projectOperation);
  console.log("Project ready:", project.id, project.title);

  // 3. 发起导出
  const exportOperation = await client.exports.create(project.id, {
    resolution: "1080p",
    quality: "high",
  });

  // 4. 等待导出完成
  const finishedExport = await client.exports.wait(exportOperation);
  await client.exports.download(finishedExport, {
    output: "./exports",
  });
  console.log("Export ready:", finishedExport.url);
}

main().catch((error) => {
  if (error instanceof YoukaRequestError) {
    console.error("Request failed:", error.code, error.status, error.message);
    process.exit(1);
  }
  if (error instanceof YoukaTaskError) {
    console.error("Task failed:", error.code, error.status, error.message);
    process.exit(1);
  }
  throw error;
});
```

<Note>
  `client.projects.create()` 会为 `path`、`bytes` 和 `url`
  类型的 source 处理上传。若需要更底层的上传控制，请使用 `client.uploads.*`。
</Note>

## 三种 source 类型

<Tabs>
  <Tab title="本地文件">
    ```ts theme={null}
    const operation = await client.projects.create({
      source: { type: "path", path: "./song.mp3" },
    });
    ```
  </Tab>

  <Tab title="内存字节">
    ```ts theme={null}
    const fileBuffer = new Uint8Array([/* audio bytes */]);

    const operation = await client.projects.create({
      source: {
        type: "bytes",
        data: fileBuffer,
        filename: "song.mp3",
      },
    });
    ```
  </Tab>

  <Tab title="远程 URL">
    ```ts theme={null}
    const operation = await client.projects.create({
      source: {
        type: "url",
        url: "https://example.com/song.mp4",
      },
    });
    ```
  </Tab>
</Tabs>

## 接下来

* [Projects](/zh/sdk/projects) — 完整的 projects API
* [Exports](/zh/sdk/exports) — 本地渲染与 `client.exports.prepareLocal`
* [Errors](/zh/sdk/errors) — 处理 `YoukaRequestError` 和 `YoukaTaskError`
* [AI agents](/zh/agents) — 推荐的轮询与重试模式
