@pydantic/genai-prices 0.0.49 → 0.0.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -0
- package/dist/cli.js +668 -924
- package/dist/index.cjs +5 -5
- package/dist/index.d.cts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +328 -576
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -65,6 +65,44 @@ The library uses intelligent provider matching:
|
|
|
65
65
|
- Use `provider:model` format in CLI for explicit provider selection
|
|
66
66
|
- The async API with `--auto-update` provides the most up-to-date pricing
|
|
67
67
|
|
|
68
|
+
### Custom Pricing / New Models
|
|
69
|
+
|
|
70
|
+
If a model is not yet available in the bundled catalog, you can provide your own pricing definition. By passing a `provider` object in the options, the library will use your custom data instead of the internal catalog.
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { calcPrice, Provider } from '@pydantic/genai-prices'
|
|
74
|
+
|
|
75
|
+
const customProvider: Provider = {
|
|
76
|
+
id: 'custom-provider',
|
|
77
|
+
name: 'Custom Provider',
|
|
78
|
+
api_pattern: '.*',
|
|
79
|
+
models: [
|
|
80
|
+
{
|
|
81
|
+
id: 'my-new-model',
|
|
82
|
+
match: { equals: 'my-new-model' },
|
|
83
|
+
prices: {
|
|
84
|
+
input_mtok: 2.5,
|
|
85
|
+
output_mtok: 10.0,
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const usage = { input_tokens: 1000, output_tokens: 100 }
|
|
92
|
+
const result = calcPrice(usage, 'my-new-model', { provider: customProvider })
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Required fields:**
|
|
96
|
+
|
|
97
|
+
- `Provider`: `id`, `name`, `api_pattern`, and `models` array
|
|
98
|
+
- `ModelInfo`: `id`, `match` (determines how the model ID is matched), and `prices`
|
|
99
|
+
|
|
100
|
+
**Pricing fields** (all in cost per million tokens):
|
|
101
|
+
|
|
102
|
+
- `input_mtok` / `output_mtok`: Text token pricing
|
|
103
|
+
- `cache_read_mtok` / `cache_write_mtok`: Prompt caching pricing
|
|
104
|
+
- `input_audio_mtok` / `output_audio_mtok`: Audio token pricing
|
|
105
|
+
|
|
68
106
|
### Error Handling
|
|
69
107
|
|
|
70
108
|
When 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.
|