安装
如何安装和配置 TurboAPI SDK。
系统要求
- Node.js 18+
- npm 9+ 或 pnpm 8+ 或 yarn 1.22+
安装 SDK
npm install @turboapiai/sdk
pnpm add @turboapiai/sdk
yarn add @turboapiai/sdk
bun add @turboapiai/sdk
pip install turboapi-sdk
go get github.com/turboapiai/turboapi-sdk-go@latest
配置
在项目根目录创建 .env 文件:
TURBOAPI_API_KEY=your_api_key_here
TURBOAPI_BASE_URL=https://api.turboapi.ai/api/v1
TypeScript 支持
SDK 开箱即用地包含完整的 TypeScript 支持:
import { TurboAPIClient } from '@turboapiai/sdk';
const client = new TurboAPIClient({
apiKey: process.env.TURBOAPI_API_KEY!,
});
// 类型安全的 API 调用
const task = await client.call.createAndWait('api-slug', {
prompt: '一只可爱的猫',
});
框架集成
Next.js
// lib/turboapi.ts
import { TurboAPIClient } from '@turboapiai/sdk';
export const client = new TurboAPIClient({
apiKey: process.env.TURBOAPI_API_KEY!,
});
Nuxt
创建客户端插件:
// plugins/turboapi.client.ts
import { TurboAPIClient } from '@turboapiai/sdk';
export default defineNuxtPlugin(() => {
const client = new TurboAPIClient({
apiKey: useRuntimeConfig().public.turboapiApiKey,
});
return {
provide: { turboapi: client },
};
});
验证安装
运行快速测试来验证您的安装:
import { TurboAPIClient } from '@turboapiai/sdk';
const client = new TurboAPIClient({
apiKey: process.env.TURBOAPI_API_KEY,
});
// 浏览可用 API
const apis = await client.apis.list();
console.log(apis);