2.1.0 • Published 1 year ago

openai-billing v2.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

查询 openai 余额

Install

npm i openai-billing

Usage

import { fetchBilling } from "openai-billing"

// for CommonJS
// const { fetchBilling } = require("openai-billing")

const apikey = 'YOUR OPENAI KEY'
const result = await fetchBilling(apikey, { baseURL: 'https://api.openai.com' })

if (result.error) {
    const { code, message } = result.error
    console.error(`Error: ${code} - ${message}`)
}
else {
    const { total, used, remain, expiresTime } = result
    console.log(`
额度总量: 💵 $ ${total}
已用额度: 💵 $ ${used}
剩余额度: 💵 $ ${remain}
过期时间:🪫  ${new Date(expiresTime).toLocaleDateString()}
    `)
}

Use in browser

<script src="https://cdn.jsdelivr.net/npm/openai-billing@2">
const apikey = 'YOUR OPENAI KEY'
const result = await OpenaiBilling.fetchBilling(apikey, { baseURL: 'https://api.openai.com' })

// ...
2.1.0

1 year ago

2.0.0

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago