SDK 快速开始
先确认本地运行时版本:TypeScript SDK 需要 Node.js 18.17+;Python SDK 需要 Python 3.10+,安装后用 seacloud_sdk 导入。
pnpm add @seacloudai/sdkpip install seacloudai-sdk2. 初始化客户端
Section titled “2. 初始化客户端”API Key 必须由调用方显式传入。你可以从环境变量读取后再传给 SDK,但 SDK 本身不会自动读取环境变量。
import { SeaCloud, getSeaCloudDocs } from "@seacloudai/sdk";
const docs = getSeaCloudDocs({ locale: "zh-CN" });
const client = new SeaCloud({ apiKey: process.env.SEACLOUD_API_KEY!, timeout: 600_000,});
console.table(docs.methods);import os
from seacloud_sdk import SeaCloud, getSeaCloudDocs
docs = getSeaCloudDocs({"locale": "zh-CN"})
client = SeaCloud( api_key=os.environ["SEACLOUD_API_KEY"], timeout=600_000,)
print(docs["methods"])3. 发送对话请求
Section titled “3. 发送对话请求”const text = await client.chat.send( "gpt-4.1", [{ role: "user", content: "用一句话介绍 SeaCloud SDK" }], { temperature: 0.2, maxTokens: 128 },);
console.log(text);text = await client.chat.send( "gpt-4.1", [{"role": "user", "content": "用一句话介绍 SeaCloud SDK"}], {"temperature": 0.2, "maxTokens": 128},)
print(text)4. 创建生成任务并等待结果
Section titled “4. 创建生成任务并等待结果”run 只创建任务并立即返回任务句柄;runSync / run_sync 会创建任务、轮询状态并读取最终 response。
const result = await client.runSync("wan25_t2i_preview", { prompt: "a cinematic photo of a cat astronaut", n: 1, prompt_extend: true, size: "1024*1024", watermark: false,});
console.log(result.output?.urls);result = await client.run_sync("wan25_t2i_preview", { "prompt": "a cinematic photo of a cat astronaut", "n": 1, "prompt_extend": True, "size": "1024*1024", "watermark": False,})
print(result.get("output", {}).get("urls"))5. 下一步
Section titled “5. 下一步”- 需要理解
dryRun、任务轮询、模型规格和错误处理:继续看操作手册。