Blade 私有认证服务 - 提供完整的 Claude ChatService 实现
npm install blade-auth-serviceBlade 私有认证服务 - 提供完整的 Claude ChatService 实现
- ✅ 完整的 Claude API ChatService 实现
- ✅ 自动从 Cloudflare Worker 获取 API Key
- ✅ 支持流式和非流式响应
- ✅ 支持工具调用(Tool Use)
- ✅ 支持多模态(文本 + 图片)
- ✅ API Key 缓存机制
``bash`从 GitHub Packages 安装
npm install @blade/auth-service
`typescript
import { BladeChatService } from '@blade/auth-service';
// 创建服务实例
const chatService = new BladeChatService({
model: 'claude-sonnet-4-20250514',
temperature: 0.7,
maxOutputTokens: 4096,
});
// 非流式调用
const response = await chatService.chat([
{ role: 'user', content: 'Hello, Claude!' }
]);
console.log(response.content);
// 流式调用
for await (const chunk of chatService.streamChat([
{ role: 'user', content: 'Tell me a story' }
])) {
if (chunk.content) {
process.stdout.write(chunk.content);
}
}
`
#### 构造函数
`typescript`
new BladeChatService(config: ChatConfig)
#### 方法
- chat(messages, tools?, signal?) - 非流式聊天streamChat(messages, tools?, signal?)
- - 流式聊天getConfig()
- - 获取配置updateConfig(newConfig)
- - 更新配置
```
BladeChatService → Cloudflare Worker → 获取 API Key → Claude API
- API Key 存储在 Cloudflare Worker 中
- 客户端永远不接触真实的 API Key
- 支持 IP 限流和使用量监控
PRIVATE - 仅供 Blade 项目内部使用