快速接入 Token多多
开发者只需拿到 APP ID (app-id-xxx),无需接触上游模型的 API Key。平台统一代理所有 AI 请求。
3 行代码,同时接入充值 + AI 能力
1. 安装
2. 初始化 (填入你的 APP ID)
import { createClient } from '@token-platform/sdk'
const { payment, chat } = createClient({
apiKey: 'app-id-xxx' // 你的 APP ID
})3a. 用户充值
payment.openPaymentWindow('user_unique_id')
// 用户会看到充值页面,选套餐付款后自动返回3b. 调用 AI (OpenAI 兼容,自动扣费)
const res = await chat.completions.create({
model: 'deepseek-v4-flash',
messages: [{ role: 'user', content: '你好' }],
userId: 'user_unique_id'
})
console.log(res.choices[0].message.content)
console.log('剩余余额:', res.usage.balance)发生了什么?
SDK 方法列表
| 方法 | 说明 | 返回 |
|---|---|---|
| chat.completions.create() | AI 对话 (OpenAI 兼容) | Promise |
| openPaymentWindow(userId) | 打开充值窗口 | Window |
| getEmbedUrl(userId) | 获取嵌入 URL | string |
| redirectToPayment(userId) | 跳转充值页 | void |
| getBalance() | 查询余额(需 userToken) | Promise |
| getPackages() | 获取套餐列表 | Promise |
| createWechatOrder(userId, pkgId) | 微信支付购买 | Promise |
| onPaymentSuccess(callback) | 监听充值成功 | unsubscribe fn |