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

# 快速入門

在本指南中，我們將引導您使用我們其中一個熱門的模型端點，例如 [black-forest-labs/flux-kontext-pro/text-to-image](https://sunra.ai/models/black-forest-labs/flux-kontext-pro/text-to-image)。
在開始之前，請確保您已從您的[儀表板](https://sunra.ai/dashboard/api-tokens)取得 API 金鑰，
這是向 sunra API 驗證您的請求所必需的。

請在下方選擇您偏好的程式語言以開始：

## JavaScript/Node.js

若要開始，請安裝客戶端套件並使用您的 API 金鑰進行設定：

<CodeGroup>
  ```bash npm theme={null}
  npm install @sunra/client
  ```

  ```bash pnpm theme={null}
  pnpm add @sunra/client
  ```

  ```bash yarn theme={null}
  yarn add @sunra/client
  ```
</CodeGroup>

將您的 API 金鑰設定為環境變數：

```bash theme={null}
export SUNRA_KEY="your-api-key-here"
```

設定完成後，您可以使用 sunra [客戶端](/client-libraries/javascript) 呼叫我們的模型 API 端點：

```javascript theme={null}
import { sunra } from "@sunra/client";

// 可選地，使用與環境變數中設定的不同 API 金鑰設定客戶端
sunra.config({
  credentials: "YOUR_SUNRA_KEY",
});

const result = await sunra.subscribe("black-forest-labs/flux-kontext-pro/text-to-image", {
  input: {
    prompt: "一隻戴著眼鏡的兔子在蘑菇下看書，水彩風格。",
    width: 1024,
    height: 768,
    output_format: "jpeg"
  },
});
```

## Python

使用 pip 安裝 Python 客戶端函式庫：

```bash theme={null}
pip install sunra-client
```

將您的 API 金鑰設定為環境變數：

```bash theme={null}
export SUNRA_KEY="your-api-key-here"
```

設定並使用客戶端：

```python theme={null}
import sunra_client

result = sunra_client.subscribe(
    "black-forest-labs/flux-kontext-pro/text-to-image",
    arguments={
        "prompt": "一隻戴著眼鏡的兔子在蘑菇下看書，水彩風格。",
        "width": 1024,
        "height": 768,
        "output_format": "jpeg"
    },
    with_logs=True,
    on_enqueue=print,
    on_queue_update=print,
)
print(result)
```

## Java

使用您偏好的建置系統將 Java 客戶端函式庫新增至您的專案：

<CodeGroup>
  ```kotlin Gradle theme={null}
  implementation("ai.sunra.client:sunra-client:0.1.5")
  ```

  ```xml Maven theme={null}
  <dependency>
      <groupId>ai.sunra.client</groupId>
      <artifactId>sunra-client</artifactId>
      <version>0.1.5</version>
  </dependency>
  ```
</CodeGroup>

將您的 API 金鑰設定為環境變數：

```bash theme={null}
export SUNRA_KEY="your-api-key-here"
```

設定並使用客戶端：

```java theme={null}
import ai.sunra.client.*;
import ai.sunra.client.queue.*;
import java.util.Map;
import com.google.gson.JsonObject;
import java.util.function.Consumer;

ClientConfig config = ClientConfig.builder()
    .withCredentials(CredentialsResolver.fromEnv())
    .build();

SunraClient client = SunraClient.withConfig(config);
Map<String, Object> input = Map.of(
    "prompt", "一隻戴著眼鏡的兔子在蘑菇下看書，水彩風格。",
    "width", 1024,
    "height", 768,
    "output_format", "jpeg"
);

Consumer<QueueStatus.StatusUpdate> statusUpdateHandler = update -> {
    String status = update.getStatus().toString();
    String message = String.format("\n狀態更新：%s，請求 ID：%s",
        status, update.getRequestId());
    System.out.println(message);
};

SubscribeOptions<JsonObject> options = SubscribeOptions.<JsonObject>builder()
    .input(input)
    .resultType(JsonObject.class)
    .onQueueUpdate(statusUpdateHandler)
    .logs(true)
    .build();

Output<JsonObject> response = client.subscribe("black-forest-labs/flux-kontext-pro/text-to-image", options);
System.out.println("已完成！");
System.out.println(response.getData());
```

## 後續步驟

我們提供各種模型，例如 Flux kontext pro 和 Kling v2 master，作為即用型 API。請在我們的[模型實驗室](https://sunra.ai/models)中探索這些模型。

若要使用模型，請造訪其「API」分頁以尋找 URL、原始碼和使用範例，協助您將其無縫整合到您的應用程式中。

如需有關每個客戶端函式庫的更多詳細資訊，請造訪我們的[客戶端函式庫文件](/client-libraries)。
