SuperAPI AI 工具集

setup-api-key

编程与开发

查看项目

更新于 10-16 02:08

技能介绍

用途

本技能用于引导用户完成 Runway API 密钥的获取与配置,使项目能够通过 API 访问 Runway 服务。

前置条件

使用前需先运行 +check-compatibility,确保项目具备服务端能力。

主要步骤

第一步:创建 Runway 开发者账号

引导用户访问 https://dev.runwayml.com/ ,创建或使用已有组织,进入 Organization Settings → API Keys,点击 Create API Key,并立即复制密钥——密钥仅显示一次且无法恢复。

需告知用户的重要警告:

  • 丢失的密钥无法找回。若丢失,需禁用旧密钥并创建新密钥。
  • API 密钥按组织范围而非用户范围。
  • 必须先预付费购买积分,API 才能工作。最低购买金额为 $10(1,000 积分,$0.01/积分)。购买地址为 https://dev.runwayml.com/ 的 billing 页面。

第二步:安装 SDK

Node.js:

npm install @runwayml/sdk

需要 Node.js 18+。SDK 包含 TypeScript 类型定义。

Python:

pip install runwayml

需要 Python 3.8+。包含 MyPy 类型注解。

第三步:配置环境变量

SDK 会自动从 RUNWAYML_API_SECRET 环境变量读取 API 密钥。

选项 A:.env 文件(开发环境推荐)

检查项目是否已有 .env 文件。若有则追加,若无则创建。

RUNWAYML_API_SECRET=your_api_key_here

对于 Node.js 项目:确保项目加载 .env 文件:

  • Next.js、Remix、Vite——内置 .env 支持,无需额外设置
  • Express/Fastify/普通 Node——安装 dotenv:
npm install dotenv

在入口点添加:

import 'dotenv/config';

对于 Python 项目:若未使用内置支持的框架,确保安装 python-dotenv:

pip install python-dotenv

在入口点添加:

from dotenv import load_dotenv
load_dotenv()

选项 B:系统环境变量

export RUNWAYML_API_SECRET=your_api_key_here

选项 C:直接传给客户端(不推荐)

// Node.js
const client = new RunwayML({ apiKey: 'your_api_key_here' });

# Python
client = RunwayML(api_key='your_api_key_here')

警告用户:切勿在源代码中硬编码密钥。请使用环境变量或密钥管理器。

第四步:更新 .gitignore

确保 .env 在 .gitignore 中,防止意外提交 API 密钥:

.env
.env.local
.env.*.local

检查现有 .gitignore,若缺失则添加该条目。

第五步:验证配置

建议用户运行快速验证:

Node.js:

import RunwayML from '@runwayml/sdk';

const client = new RunwayML();
// If no error is thrown, the API key is configured correctly
console.log('Runway SDK initialized successfully');

Python:

from runwayml import RunwayML

client = RunwayML()
# If no error is thrown, the API key is configured correctly
print('Runway SDK initialized successfully')

第六步:确认积分余额

提醒用户:

  • API 需要预付费积分才能运行
  • 最低购买:$10(1,000 积分)
  • 购买地址:https://dev.runwayml.com/ → Billing

可通过 API 检查余额:

// Node.js - check organization info
const response = await fetch('https://api.dev.runwayml.com/v1/organization', {
  headers: {
    'Authorization': `Bearer ${process.env.RUNWAYML_API_SECRET}`,
    'X-Runway-Version': '2024-11-06'
  }
});
const org = await response.json();
console.log('Credits:', org.creditBalance);

安全检查清单

继续之前,请确认:

  • API 密钥存储在环境变量中,而非硬编码
  • .env 文件在 .gitignore 中
  • API 调用仅在服务端进行(不在浏览器执行的代码中)
  • 用户已购买积分

后续步骤

API 密钥配置完成后,用户可继续集成:

  • +integrate-video——视频生成(文生视频、图生视频)
  • +integrate-image——图像生成
  • +integrate-audio——音频生成(TTS、音效、语音)
  • +integrate-uploads——为需要图像/视频输入的模型上传文件