
Security News
/Research
Fake Corepack Site Distributes Infostealer and Proxyware to Developers
A fake corepack.org site is impersonating the Node.js tool and delivers an infostealer and proxyware to developers who download it.
deechat-token-calculator
Advanced tools
基于策略模式的多厂商AI模型Token计算器,支持精确的token计数和成本估算。
npm install @deechat/token-calculator
import { countTokens, countGPT4, countClaude } from '@deechat/token-calculator'
// 通用接口
const tokens = countTokens('Hello, world!', 'openai', 'gpt-4')
console.log(`Tokens: ${tokens}`) // Tokens: 4
// 便捷方法
const gpt4Tokens = countGPT4('Hello, world!')
const claudeTokens = countClaude('Hello, world!')
import { estimateCost } from '@deechat/token-calculator'
const cost = estimateCost(
'Your input text here',
100, // 预期输出tokens
'gpt-4'
)
console.log(`Total cost: $${cost.totalCost}`)
import { compareProviders, getMostEconomical } from '@deechat/token-calculator'
// 对比不同提供者的token计数
const comparison = compareProviders('Hello, world!')
// { openai: 4, anthropic: 4, generic: 5 }
// 找到最经济的选择
const economical = getMostEconomical('Your text', 100)
console.log(`Most economical: ${economical.model}`)
console.log(`Cost: $${economical.cost.totalCost}`)
countTokens(text: string, provider?: string, model?: string): number通用token计数函数。
// OpenAI
countTokens('Hello', 'openai', 'gpt-4')
countTokens('Hello', 'openai') // 默认 gpt-4
// Anthropic
countTokens('Hello', 'anthropic', 'claude-3-sonnet')
countTokens('Hello', 'claude') // 自动识别厂商
// 通用策略
countTokens('Hello', 'generic')
countTokens('Hello') // 默认使用第一个可用策略
countGPT4(text: string): number // GPT-4
countGPT35(text: string): number // GPT-3.5 Turbo
countClaude(text: string, model?: string): number // Claude (默认3-sonnet)
estimateCost(
inputText: string,
outputTokens: number = 0,
model: string,
provider?: string
): CostEstimate
// 返回格式
interface CostEstimate {
inputCost: number
outputCost: number
totalCost: number
currency: string
}
batchCount(texts: string[], provider?: string, model?: string): BatchTokenResult[]
// 批量成本估算
const calculator = new TokenCalculator()
const costCalculator = new CostCalculator(calculator)
const costs = costCalculator.batchEstimateCost(texts, 100, 'gpt-4')
import { TokenCalculator, CostCalculator } from '@deechat/token-calculator'
const calculator = new TokenCalculator()
const costCalculator = new CostCalculator(calculator)
// 基本计数
const tokens = calculator.count('Hello', 'openai', 'gpt-4')
// 智能检测
const smartTokens = calculator.smartCount('Hello', 'gpt-4-turbo')
// 编码/解码 (如果支持)
const encoded = calculator.encode('Hello', 'openai', 'gpt-4')
const decoded = calculator.decode(encoded, 'openai', 'gpt-4')
// 成本分析
const economical = costCalculator.getMostEconomical('Hello', 100)
const monthlyCost = costCalculator.estimateMonthlyCost(1000, 500, 'gpt-4')
import { healthCheck, getAvailableProviders, getSupportedModels } from '@deechat/token-calculator'
// 检查所有提供者状态
const health = healthCheck()
console.log('Health:', health)
// 获取可用提供者
const providers = getAvailableProviders()
console.log('Providers:', providers)
// 获取支持的模型
const models = getSupportedModels('openai')
console.log('OpenAI models:', models)
所有定价数据基于2024年官方价格,单位为USD per 1K tokens。成本会根据最新定价自动更新。
# 安装依赖
npm install
# 开发模式
npm run dev
# 构建
npm run build
# 测试
npm test
# 清理
npm run clean
MIT License
欢迎提交Issue和Pull Request来改进这个项目!
由 DeeChat 团队开发 ❤️
FAQs
Token calculation and cost estimation for AI models
We found that deechat-token-calculator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
/Research
A fake corepack.org site is impersonating the Node.js tool and delivers an infostealer and proxyware to developers who download it.

Research
/Security News
A large-scale campaign abused GitHub Actions in compromised repositories to exploit CVE-2026-41940 in cPanel and WHM and steal server credentials.

Security News
Five frontier LLMs generated the same nonexistent package names, leaving 53 available for potential slopsquatting across PyPI and npm.