
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
@pydantic/genai-prices
Advanced tools
JavaScript package and command-line tool for calculating LLM API prices.
calcPrice
The package exports a function for price calculation that, by default, uses the bundled price data.
import { calcPrice } from '@pydantic/genai-prices'
const usage = { input_tokens: 1000, output_tokens: 100 }
const result = calcPrice(usage, 'gpt-3.5-turbo', { providerId: 'openai' })
if (result) {
console.log(
`$${result.total_price} (input: $${result.input_price}, output: $${result.output_price})`,
result.provider.name,
result.model.name
)
} else {
console.log('No price found for this model/provider combination')
}
updatePrices
You can optionally use updatePrices
to implement logic that can periodically update the data used by calcPrice
.
See the src/examples/browser
directory for an example that implements a local storage-backed auto-update and src/examples/node-script.ts
for an example of a file-based asynchronous auto-update implementation.
calcPrice
is a synchronous function that uses the currently available data - either the bundled one, or the last data fetched from the updatePrices
setup. To force calcPrice
to await potential in-progress data updates that can happen in enableAutoUpdate
, await the waitForUpdate()
return value before calling calcPrice
import { calcPrice, updatePrices } from '@pydantic/genai-prices'
enableAutoUpdate(/** auto-update logic */)
// ...
// this guarantees that the latest data is used
await waitForUpdate()
const result = calcPrice(usage, 'gpt-5', { providerId: 'openai' })
console.log(
`$${result.total_price} (input: $${result.input_price}, output: $${result.output_price})`,
result.provider.name,
result.model.name
)
The library uses intelligent provider matching:
providerId
parameter or provider:model
formatmodel_match
logic (e.g., OpenAI matches models starting with "gpt-")Best practices:
providerId
if you know it (e.g., openai
, google
, etc.) for best resultsprovider:model
format in CLI for explicit provider selection--auto-update
provides the most up-to-date pricingWhen a model or provider is not found, the library returns null
. This makes it easier to handle cases where pricing information might not be available.
import { calcPrice } from '@pydantic/genai-prices'
const usage = { input_tokens: 1000, output_tokens: 100 }
// Returns null if model/provider not found
const result = calcPrice(usage, 'non-existent-model')
if (result === null) {
console.log('No pricing information available for this model')
} else {
console.log(`Total Price: $${result.total_price} (input: $${result.input_price}, output: $${result.output_price})`)
}
// Async version also returns null
const asyncResult = await calcPrice(usage, 'non-existent-model', { awaitAutoUpdate: true, providerId: 'unknown-provider' })
if (asyncResult === null) {
console.log('No pricing information available for this model/provider combination')
} else {
console.log(`Total Price: $${asyncResult.total_price} (input: $${asyncResult.input_price}, output: $${asyncResult.output_price})`)
}
providerId
(e.g., openai
, google
, anthropic
)provider:model
format in CLI--auto-update
flag to fetch latest dataThe easiest way to run the latest version of the package as a CLI tool is through npx:
npx @pydantic/genai-prices@latest
For example:
npx @pydantic/genai-prices@latest calc gpt-4 --input-tokens 1000 --output-tokens 500
npx @pydantic/genai-prices@latest list
You can also install it globally and then use the genai-prices
command:
npm i -g @pydantic/genai-prices
# Basic usage
genai-prices gpt-5 --input-tokens 1000 --output-tokens 100
# Specify provider explicitly
genai-prices openai:gpt-5 --input-tokens 1000 --output-tokens 100
# List available providers and models
genai-prices list
genai-prices list openai
FAQs
Calculate prices for calling LLM inference APIs
The npm package @pydantic/genai-prices receives a total of 246 weekly downloads. As such, @pydantic/genai-prices popularity was classified as not popular.
We found that @pydantic/genai-prices demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers 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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.