spendgate 0.1.0__py3-none-any.whl

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.
Files changed (131) hide show
  1. spendgate/__init__.py +1 -0
  2. spendgate/catalog/prices.yaml +342 -0
  3. spendgate/catalog/schema.json +135 -0
  4. spendgate/cli/__init__.py +5 -0
  5. spendgate/cli/client.py +58 -0
  6. spendgate/cli/commands.py +231 -0
  7. spendgate/cli/entry.py +185 -0
  8. spendgate/cli/render.py +26 -0
  9. spendgate/cli/runtime.py +52 -0
  10. spendgate/cli/serve.py +163 -0
  11. spendgate/client/__init__.py +41 -0
  12. spendgate/client/anthropic.py +64 -0
  13. spendgate/client/errors.py +207 -0
  14. spendgate/client/openai.py +64 -0
  15. spendgate/client/session.py +158 -0
  16. spendgate/config/__init__.py +17 -0
  17. spendgate/config/load.py +407 -0
  18. spendgate/config/schema.py +234 -0
  19. spendgate/config/secrets.py +63 -0
  20. spendgate/config/yamlio.py +37 -0
  21. spendgate/core/__init__.py +1 -0
  22. spendgate/core/audio.py +427 -0
  23. spendgate/core/budgets.py +194 -0
  24. spendgate/core/catalog.py +294 -0
  25. spendgate/core/cost.py +240 -0
  26. spendgate/core/errors.py +106 -0
  27. spendgate/core/estimate.py +388 -0
  28. spendgate/core/health.py +122 -0
  29. spendgate/core/limits.py +206 -0
  30. spendgate/core/money.py +191 -0
  31. spendgate/core/outcomes.py +166 -0
  32. spendgate/core/policy.py +199 -0
  33. spendgate/core/sessions.py +128 -0
  34. spendgate/gateway/__init__.py +1 -0
  35. spendgate/gateway/admin.py +126 -0
  36. spendgate/gateway/admin_budgets.py +172 -0
  37. spendgate/gateway/admin_codec.py +149 -0
  38. spendgate/gateway/admin_http.py +297 -0
  39. spendgate/gateway/admin_models.py +131 -0
  40. spendgate/gateway/admin_reports.py +166 -0
  41. spendgate/gateway/admin_scopes.py +215 -0
  42. spendgate/gateway/app.py +177 -0
  43. spendgate/gateway/bootstrap.py +133 -0
  44. spendgate/gateway/logs.py +92 -0
  45. spendgate/gateway/maintenance.py +57 -0
  46. spendgate/gateway/metrics.py +267 -0
  47. spendgate/gateway/observability.py +135 -0
  48. spendgate/gateway/wiring.py +163 -0
  49. spendgate/ledger/__init__.py +1 -0
  50. spendgate/ledger/admin_engine.py +87 -0
  51. spendgate/ledger/admin_flow.py +360 -0
  52. spendgate/ledger/admin_port.py +131 -0
  53. spendgate/ledger/admin_reads.py +229 -0
  54. spendgate/ledger/common.py +217 -0
  55. spendgate/ledger/engine.py +299 -0
  56. spendgate/ledger/hold_flow.py +298 -0
  57. spendgate/ledger/ids.py +12 -0
  58. spendgate/ledger/key_flow.py +318 -0
  59. spendgate/ledger/key_types.py +102 -0
  60. spendgate/ledger/keys.py +200 -0
  61. spendgate/ledger/migrations/__init__.py +34 -0
  62. spendgate/ledger/migrations/postgres/0001_init.sql +204 -0
  63. spendgate/ledger/migrations/postgres/0002_usage.sql +5 -0
  64. spendgate/ledger/migrations/postgres/0003_scope_display_name.sql +2 -0
  65. spendgate/ledger/migrations/postgres/0004_calls_http_status_check.sql +3 -0
  66. spendgate/ledger/migrations/sqlite/0001_init.sql +194 -0
  67. spendgate/ledger/migrations/sqlite/0002_usage.sql +5 -0
  68. spendgate/ledger/migrations/sqlite/0003_scope_display_name.sql +2 -0
  69. spendgate/ledger/migrations/sqlite/0004_calls_http_status_check.sql +12 -0
  70. spendgate/ledger/port.py +368 -0
  71. spendgate/ledger/postgres.py +158 -0
  72. spendgate/ledger/postgres_driver.py +109 -0
  73. spendgate/ledger/rows.py +83 -0
  74. spendgate/ledger/settle_flow.py +272 -0
  75. spendgate/ledger/sql.py +365 -0
  76. spendgate/ledger/sqlite.py +220 -0
  77. spendgate/ledger/usage.py +290 -0
  78. spendgate/ledger/usage_flow.py +104 -0
  79. spendgate/local/__init__.py +16 -0
  80. spendgate/local/bridge.py +107 -0
  81. spendgate/local/guard.py +280 -0
  82. spendgate/local/loop.py +44 -0
  83. spendgate/local/principal.py +71 -0
  84. spendgate/local/runtime.py +156 -0
  85. spendgate/local/sdk.py +55 -0
  86. spendgate/local/session.py +27 -0
  87. spendgate/local/setup.py +82 -0
  88. spendgate/local/transport.py +126 -0
  89. spendgate/local/transport_httpx2.py +100 -0
  90. spendgate/pipeline/__init__.py +1 -0
  91. spendgate/pipeline/adapters.py +37 -0
  92. spendgate/pipeline/answers.py +43 -0
  93. spendgate/pipeline/auth.py +40 -0
  94. spendgate/pipeline/closing.py +171 -0
  95. spendgate/pipeline/intake.py +248 -0
  96. spendgate/pipeline/leases.py +102 -0
  97. spendgate/pipeline/model.py +174 -0
  98. spendgate/pipeline/multipart.py +121 -0
  99. spendgate/pipeline/pipeline.py +408 -0
  100. spendgate/pipeline/replies.py +144 -0
  101. spendgate/pipeline/routing.py +435 -0
  102. spendgate/pipeline/settle.py +212 -0
  103. spendgate/pipeline/steps.py +347 -0
  104. spendgate/pipeline/streaming.py +335 -0
  105. spendgate/pipeline/transport.py +98 -0
  106. spendgate/pipeline/upkeep.py +46 -0
  107. spendgate/pipeline/watch.py +48 -0
  108. spendgate/providers/__init__.py +1 -0
  109. spendgate/providers/anthropic.py +381 -0
  110. spendgate/providers/azure_openai.py +146 -0
  111. spendgate/providers/azure_openai_auth.py +74 -0
  112. spendgate/providers/azure_speech.py +110 -0
  113. spendgate/providers/azure_speech_shapes.py +216 -0
  114. spendgate/providers/bedrock.py +231 -0
  115. spendgate/providers/bedrock_request.py +239 -0
  116. spendgate/providers/bedrock_stream.py +349 -0
  117. spendgate/providers/elevenlabs.py +196 -0
  118. spendgate/providers/google.py +326 -0
  119. spendgate/providers/google_shapes.py +121 -0
  120. spendgate/providers/google_stream.py +90 -0
  121. spendgate/providers/openai.py +76 -0
  122. spendgate/providers/openai_shapes.py +425 -0
  123. spendgate/providers/openai_usage.py +143 -0
  124. spendgate/providers/port.py +332 -0
  125. spendgate/providers/sse.py +169 -0
  126. spendgate/py.typed +0 -0
  127. spendgate-0.1.0.dist-info/METADATA +188 -0
  128. spendgate-0.1.0.dist-info/RECORD +131 -0
  129. spendgate-0.1.0.dist-info/WHEEL +4 -0
  130. spendgate-0.1.0.dist-info/entry_points.txt +3 -0
  131. spendgate-0.1.0.dist-info/licenses/LICENSE +202 -0
spendgate/__init__.py ADDED
@@ -0,0 +1 @@
1
+ """spendgate: a small, auditable LLM spend guard."""
@@ -0,0 +1,342 @@
1
+ # spendgate seed price catalog (schema: schema.json). Prices are quoted decimal strings in the entry's currency.
2
+ # Compiled 2026-11-13 from each provider's own pages / public price feeds (see source_url and per-entry notes).
3
+ # verified: true = every price on the entry was read today from the provider's own page or official public price feed.
4
+ # No Realtime entries (on the roadmap). Bedrock region used for every bedrock entry: us-east-1.
5
+ # Known schema gaps: Anthropic/Bedrock have 5m and 1h cache-write prices but only one cache_write meter exists, so the
6
+ # dearer 1h price is stored (never lower). Batch/Flex/Priority variants are not seeded. Vertex AI pricing page could not be
7
+ # read, so no Vertex-specific price is encoded (google/* entries are Gemini API prices).
8
+ catalog_version: 1
9
+ updated: "2026-11-13"
10
+
11
+ providers:
12
+ openai: { free_statuses: [429] }
13
+ azure_openai: { free_statuses: [429] }
14
+ anthropic: { free_statuses: [429, 529] }
15
+ bedrock: { free_statuses: [429] }
16
+ google: { free_statuses: [429] }
17
+ azure_speech: { free_statuses: [429] }
18
+ elevenlabs: { free_statuses: [429] }
19
+
20
+ models:
21
+ # ===================== OpenAI (direct) =====================
22
+ # Page: developers.openai.com/api/docs/pricing and /models/<id>. Long context: prompts over 272K input tokens price the
23
+ # whole request at 2x input/cache, 1.5x output. Max output 128,000, context 1,050,000 (model pages).
24
+ - id: openai/gpt-6-astra
25
+ mode: responses
26
+ currency: USD
27
+ effective_from: "2026-11-13"
28
+ source_url: https://developers.openai.com/api/docs/models/gpt-6-astra
29
+ verified: true
30
+ checked_on: "2026-11-13"
31
+ note: "Flagship. Standard tier. Pricing page lists 10/1/50; model page adds cache write 12.50."
32
+ deployment_type: standard
33
+ meters: { input_per_mtok: "10", cached_input_per_mtok: "1", cache_write_per_mtok: "12.5", output_per_mtok: "50" }
34
+ long_context: { threshold_input_tokens: 272000, input_multiplier: "2", output_multiplier: "1.5" }
35
+ limits: { max_output_tokens: 128000, context_window: 1050000 }
36
+ - id: openai/gpt-6-luna
37
+ mode: responses
38
+ currency: USD
39
+ effective_from: "2026-11-13"
40
+ source_url: https://developers.openai.com/api/docs/models/gpt-6-luna
41
+ verified: true
42
+ checked_on: "2026-11-13"
43
+ note: "Small/cheap model. Standard tier."
44
+ deployment_type: standard
45
+ meters: { input_per_mtok: "0.1", cached_input_per_mtok: "0.01", cache_write_per_mtok: "0.125", output_per_mtok: "0.5" }
46
+ long_context: { threshold_input_tokens: 272000, input_multiplier: "2", output_multiplier: "1.5" }
47
+ limits: { max_output_tokens: 128000, context_window: 1050000 }
48
+ - id: openai/text-embedding-3-small
49
+ mode: embedding
50
+ currency: USD
51
+ effective_from: "2026-11-13"
52
+ source_url: https://developers.openai.com/api/docs/pricing
53
+ verified: true
54
+ checked_on: "2026-11-13"
55
+ meters: { input_per_mtok: "0.02" }
56
+
57
+ # --- OpenAI speech-to-text (pricing page and /models/<id> pages read 2026-11-18). Not encoded: gpt-live-transcribe and
58
+ # gpt-realtime-whisper (Realtime only, on the roadmap); gpt-4o-transcribe, gpt-4o-mini-transcribe and gpt-4o-transcribe-diarize
59
+ # (deprecated, shutdown 2027-02-26; the pages disagree on whether their token prices are audio or text tokens). ---
60
+ - id: openai/gpt-transcribe
61
+ mode: transcription
62
+ currency: USD
63
+ effective_from: "2026-11-18"
64
+ source_url: https://developers.openai.com/api/docs/pricing
65
+ verified: true
66
+ checked_on: "2026-11-18"
67
+ note: "0.0045 USD per minute (pricing page and model page). No deprecation notice."
68
+ meters: { audio_input_per_minute: "0.0045" }
69
+ - id: openai/whisper-1
70
+ mode: transcription
71
+ currency: USD
72
+ effective_from: "2026-11-18"
73
+ source_url: https://developers.openai.com/api/docs/pricing
74
+ verified: true
75
+ checked_on: "2026-11-18"
76
+ note: "0.006 USD per minute (pricing page lists 'Whisper'). Deprecated 2026-08-26; shutdown 2027-02-26 (deprecations page)."
77
+ meters: { audio_input_per_minute: "0.006" }
78
+ deprecation_date: "2027-02-26"
79
+
80
+ # ===================== Azure OpenAI (Foundry Models) =====================
81
+ # Source: Azure Retail Prices API (https://prices.azure.com/api/retail/prices, serviceName 'Foundry Models'), read 2026-11-13.
82
+ # Stored meters are Global Standard; price_multiplier 1.20 = highest Data Zone uplift seen in any region (1.10 in US zones,
83
+ # 1.20 in EU). Long context (over 272K input) is 2x input/cache, 1.5x output, matching the LongCo meters. Cache write meter
84
+ # is published, so it is encoded. max_output_tokens 128000 follows OpenAI's model page (not re-checked on Azure docs).
85
+ - id: azure_openai/gpt-6-astra
86
+ mode: responses
87
+ currency: USD
88
+ effective_from: "2026-09-01"
89
+ source_url: https://prices.azure.com/api/retail/prices
90
+ verified: true
91
+ checked_on: "2026-11-13"
92
+ note: "Flagship. Global 10/1/12.5/50 x 1.20 Data Zone upper bound (retail meters DZ 11-12 / 55-60)."
93
+ deployment_type: data_zone
94
+ price_multiplier: "1.20"
95
+ meters: { input_per_mtok: "10", cached_input_per_mtok: "1", cache_write_per_mtok: "12.5", output_per_mtok: "50" }
96
+ long_context: { threshold_input_tokens: 272000, input_multiplier: "2", output_multiplier: "1.5" }
97
+ limits: { max_output_tokens: 128000, context_window: 1050000 }
98
+ - id: azure_openai/gpt-6-luna
99
+ mode: responses
100
+ currency: USD
101
+ effective_from: "2026-09-01"
102
+ source_url: https://prices.azure.com/api/retail/prices
103
+ verified: true
104
+ checked_on: "2026-11-13"
105
+ note: "Small/cheap. Global 0.10/0.01/0.125/0.50 x 1.20 Data Zone upper bound."
106
+ deployment_type: data_zone
107
+ price_multiplier: "1.20"
108
+ meters: { input_per_mtok: "0.1", cached_input_per_mtok: "0.01", cache_write_per_mtok: "0.125", output_per_mtok: "0.5" }
109
+ long_context: { threshold_input_tokens: 272000, input_multiplier: "2", output_multiplier: "1.5" }
110
+ limits: { max_output_tokens: 128000, context_window: 1050000 }
111
+ - id: azure_openai/gpt-6.1-terra
112
+ mode: responses
113
+ currency: USD
114
+ effective_from: "2026-10-01"
115
+ source_url: https://prices.azure.com/api/retail/prices
116
+ verified: true
117
+ checked_on: "2026-11-13"
118
+ note: "Global 1.00/0.05/1.25/5.00 x 1.20 Data Zone upper bound."
119
+ deployment_type: data_zone
120
+ price_multiplier: "1.20"
121
+ meters: { input_per_mtok: "1", cached_input_per_mtok: "0.05", cache_write_per_mtok: "1.25", output_per_mtok: "5" }
122
+ long_context: { threshold_input_tokens: 272000, input_multiplier: "2", output_multiplier: "1.5" }
123
+ limits: { max_output_tokens: 128000, context_window: 1050000 }
124
+ - id: azure_openai/gpt-6.1-sol
125
+ mode: responses
126
+ currency: USD
127
+ effective_from: "2026-10-01"
128
+ source_url: https://prices.azure.com/api/retail/prices
129
+ verified: true
130
+ checked_on: "2026-11-13"
131
+ note: "Global 2.00/0.10/2.50/10.00 x 1.20 Data Zone upper bound."
132
+ deployment_type: data_zone
133
+ price_multiplier: "1.20"
134
+ meters: { input_per_mtok: "2", cached_input_per_mtok: "0.1", cache_write_per_mtok: "2.5", output_per_mtok: "10" }
135
+ long_context: { threshold_input_tokens: 272000, input_multiplier: "2", output_multiplier: "1.5" }
136
+ limits: { max_output_tokens: 128000, context_window: 1050000 }
137
+
138
+ # --- Azure OpenAI speech-to-text (highest regional meter = upper bound; all from the Azure Retail Prices API) ---
139
+ - id: azure_openai/whisper
140
+ mode: transcription
141
+ currency: USD
142
+ effective_from: "2026-11-13"
143
+ source_url: https://prices.azure.com/api/retail/prices
144
+ verified: true
145
+ checked_on: "2026-11-13"
146
+ note: "Highest regional batch meter 0.4752 USD/h (global 0.36). Retires 2026-12-15 per learn.microsoft.com/azure/foundry/openai/concepts/model-retirement-schedule, read 2026-11-18."
147
+ meters: { audio_input_per_minute: "0.00792" }
148
+ deprecation_date: "2026-12-15"
149
+ - id: azure_openai/gpt-transcribe
150
+ mode: transcription
151
+ currency: USD
152
+ effective_from: "2026-09-01"
153
+ source_url: https://prices.azure.com/api/retail/prices
154
+ verified: true
155
+ checked_on: "2026-11-13"
156
+ note: "Data Zone meter 0.297 USD/h (global 0.27)."
157
+ meters: { audio_input_per_minute: "0.00495" }
158
+ - id: azure_openai/gpt-live-transcribe
159
+ mode: transcription
160
+ currency: USD
161
+ effective_from: "2026-09-01"
162
+ source_url: https://prices.azure.com/api/retail/prices
163
+ verified: true
164
+ checked_on: "2026-11-13"
165
+ note: "Data Zone meter 1.122 USD/h (global 1.02)."
166
+ meters: { audio_input_per_minute: "0.0187" }
167
+ - id: azure_openai/gpt-4o-transcribe
168
+ mode: transcription
169
+ currency: USD
170
+ effective_from: "2025-04-01"
171
+ source_url: https://prices.azure.com/api/retail/prices
172
+ verified: true
173
+ checked_on: "2026-11-13"
174
+ note: "Highest regional token meters (audio in 0.00792/1K, text 0.0033/1K, out 0.0132/1K); minute rate is a guard basis, not published. Retired 2026-10-15 per learn.microsoft.com/azure/foundry/openai/concepts/model-retirement-schedule, read 2026-11-18."
175
+ meters:
176
+ audio_input_per_minute: "0.00792"
177
+ audio_input_per_mtok: "7.92"
178
+ input_per_mtok: "3.3"
179
+ output_per_mtok: "13.2"
180
+ deprecation_date: "2026-10-15"
181
+ - id: azure_openai/gpt-4o-mini-transcribe
182
+ mode: transcription
183
+ currency: USD
184
+ effective_from: "2025-12-01"
185
+ source_url: https://prices.azure.com/api/retail/prices
186
+ verified: true
187
+ checked_on: "2026-11-13"
188
+ note: "Highest regional token meters (audio 3.96, text 1.65, out 6.60 per 1M); minute rate is a guard basis. Version 2025-12-15 retires 2027-06-15, 2025-03-20 retired 2026-10-15 (learn.microsoft.com/azure/foundry/openai/concepts/model-retirement-schedule, read 2026-11-18)."
189
+ meters:
190
+ audio_input_per_minute: "0.00396"
191
+ audio_input_per_mtok: "3.96"
192
+ input_per_mtok: "1.65"
193
+ output_per_mtok: "6.6"
194
+ deprecation_date: "2027-06-15"
195
+
196
+ # ===================== Azure Speech =====================
197
+ # Source: Azure Retail Prices API, serviceName 'Foundry Tools'/'MAI Models'. The azure.microsoft.com page shows blank prices.
198
+ - id: azure_speech/azure-speech
199
+ mode: transcription
200
+ currency: USD
201
+ effective_from: "2026-11-13"
202
+ source_url: https://prices.azure.com/api/retail/prices
203
+ verified: true
204
+ checked_on: "2026-11-13"
205
+ note: "Fast Transcription: highest regional meter 0.45 USD/h (min 0.36). Promo meter 0.10-0.125 ignored."
206
+ meters: { audio_input_per_minute: "0.0075" }
207
+ - id: azure_speech/mai-transcribe-2
208
+ mode: transcription
209
+ currency: USD
210
+ effective_from: "2026-10-01"
211
+ source_url: https://prices.azure.com/api/retail/prices
212
+ verified: true
213
+ checked_on: "2026-11-13"
214
+ note: "0.54 USD/h in every region (was launch price 0.10 in the earlier in-house guard; promo valid till 2026-12-31 per Azure page)."
215
+ meters: { audio_input_per_minute: "0.009" }
216
+
217
+ # ===================== Anthropic (direct API) =====================
218
+ # Page: platform.claude.com/docs/en/about-claude/pricing; limits from /docs/en/models/overview (max output 128K, context 1M;
219
+ # retirement not sooner than 2027-11-09 for Fable 5.2 and 2027-10-07 for Haiku 5.5, so no deprecation_date).
220
+ # cache_write_per_mtok holds the 1h cache-write price (dearer than the 5m price) because the schema has one meter.
221
+ - id: anthropic/claude-fable-5-2
222
+ mode: messages
223
+ currency: USD
224
+ effective_from: "2026-11-13"
225
+ source_url: https://platform.claude.com/docs/en/about-claude/pricing
226
+ verified: true
227
+ checked_on: "2026-11-13"
228
+ note: "Flagship. Input 8, cache write 5m 10 (1h 16 stored), cache hit 0.20 (0.025x), output 40."
229
+ meters: { input_per_mtok: "8", cached_input_per_mtok: "0.2", cache_write_per_mtok: "16", output_per_mtok: "40" }
230
+ limits: { max_output_tokens: 128000, context_window: 1000000 }
231
+ - id: anthropic/claude-haiku-5-5
232
+ mode: messages
233
+ currency: USD
234
+ effective_from: "2026-11-13"
235
+ source_url: https://platform.claude.com/docs/en/about-claude/pricing
236
+ verified: true
237
+ checked_on: "2026-11-13"
238
+ note: "Small. Prompts over 100,000 tokens: 5x on every meter (0.50/2.50 etc.). Cache write: 1h price 0.20 stored (5m 0.125)."
239
+ meters: { input_per_mtok: "0.1", cached_input_per_mtok: "0.01", cache_write_per_mtok: "0.2", output_per_mtok: "0.5" }
240
+ long_context: { threshold_input_tokens: 100000, input_multiplier: "5", output_multiplier: "5" }
241
+ limits: { max_output_tokens: 128000, context_window: 1000000 }
242
+
243
+ # ===================== AWS Bedrock (Converse), region us-east-1 =====================
244
+ # Source: AWS Price List bulk API (pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonBedrockFoundationModels/current),
245
+ # read 2026-11-13; the aws.amazon.com/bedrock/pricing page itself did not render the Anthropic tables to the fetcher.
246
+ # Model ids from platform.claude.com models overview. Cache write = 1h price (dearer than 5m).
247
+ - id: bedrock/global.anthropic.claude-fable-5-2
248
+ mode: messages
249
+ currency: USD
250
+ effective_from: "2026-11-01"
251
+ source_url: https://aws.amazon.com/bedrock/pricing/
252
+ verified: true
253
+ checked_on: "2026-11-13"
254
+ region: us-east-1
255
+ deployment_type: global
256
+ note: "Flagship, global inference profile price. Regional (non-global) us-east-1 would be +10% (8.8/44)."
257
+ meters: { input_per_mtok: "8", cached_input_per_mtok: "0.2", cache_write_per_mtok: "16", output_per_mtok: "40" }
258
+ limits: { max_output_tokens: 128000, context_window: 1000000 }
259
+ - id: bedrock/anthropic.claude-haiku-5-5
260
+ mode: messages
261
+ currency: USD
262
+ effective_from: "2026-10-01"
263
+ source_url: https://aws.amazon.com/bedrock/pricing/
264
+ verified: true
265
+ checked_on: "2026-11-13"
266
+ region: us-east-1
267
+ deployment_type: regional
268
+ note: "Small. Regional us-east-1 price (+10% over global, the dearer choice). Over 100,000 input tokens: 5x all meters."
269
+ meters: { input_per_mtok: "0.11", cached_input_per_mtok: "0.011", cache_write_per_mtok: "0.22", output_per_mtok: "0.55" }
270
+ long_context: { threshold_input_tokens: 100000, input_multiplier: "5", output_multiplier: "5" }
271
+ limits: { max_output_tokens: 128000, context_window: 1000000 }
272
+
273
+ # ===================== Google (Gemini API, AI Studio) =====================
274
+ # Page: ai.google.dev/gemini-api/docs/pricing (redirects to aistudio.google.com/docs/pricing), Standard paid tier.
275
+ # Vertex AI pricing page could not be read by the fetcher, so Vertex-specific prices are not encoded.
276
+ # max_output_tokens 65536: the models page says "65K / 1M" for Gemini 4 (ambiguous) and is silent for 3.5 Flash-Lite; the
277
+ # lower figure is used (it is sent as the cap, so cost is bounded). Context window 1M per models page for Gemini 4.
278
+ - id: google/gemini-4-carbon
279
+ mode: chat
280
+ currency: USD
281
+ effective_from: "2026-11-13"
282
+ source_url: https://ai.google.dev/gemini-api/docs/pricing
283
+ verified: true
284
+ checked_on: "2026-11-13"
285
+ note: "Flagship. Price valid through 2026-11-30; doubles from 2026-12-01 (see next entry). Implicit caching only."
286
+ meters: { input_per_mtok: "2", cached_input_per_mtok: "0.1", output_per_mtok: "10" }
287
+ limits: { max_output_tokens: 65536, context_window: 1000000 }
288
+ - id: google/gemini-4-carbon
289
+ mode: chat
290
+ currency: USD
291
+ effective_from: "2026-12-01"
292
+ source_url: https://ai.google.dev/gemini-api/docs/pricing
293
+ verified: true
294
+ checked_on: "2026-11-13"
295
+ note: "Announced price from 2026-12-01 ($4 input, $0.20 cached, $20 output)."
296
+ meters: { input_per_mtok: "4", cached_input_per_mtok: "0.2", output_per_mtok: "20" }
297
+ limits: { max_output_tokens: 65536, context_window: 1000000 }
298
+ - id: google/gemini-3.5-flash-lite
299
+ mode: chat
300
+ currency: USD
301
+ effective_from: "2026-11-13"
302
+ source_url: https://ai.google.dev/gemini-api/docs/pricing
303
+ verified: true
304
+ checked_on: "2026-11-13"
305
+ note: "Small/cheap current model (stable). Output includes thinking. Cache storage ($1/MTok/h) not encoded. Output limit not stated by Google."
306
+ meters: { input_per_mtok: "0.3", cached_input_per_mtok: "0.03", output_per_mtok: "2.5" }
307
+ limits: { max_output_tokens: 65536 }
308
+
309
+ # ===================== ElevenLabs (TTS, per 1,000 characters) =====================
310
+ - id: elevenlabs/eleven_v4
311
+ mode: speech
312
+ currency: USD
313
+ effective_from: "2026-11-10"
314
+ source_url: https://elevenlabs.io/pricing/api
315
+ verified: true
316
+ checked_on: "2026-11-13"
317
+ meters: { per_1k_characters: "0.08" }
318
+ - id: elevenlabs/eleven_v4_turbo
319
+ mode: speech
320
+ currency: USD
321
+ effective_from: "2026-11-10"
322
+ source_url: https://elevenlabs.io/pricing/api
323
+ verified: true
324
+ checked_on: "2026-11-13"
325
+ meters: { per_1k_characters: "0.04" }
326
+ - id: elevenlabs/eleven_multilingual_v2
327
+ mode: speech
328
+ currency: USD
329
+ effective_from: "2026-11-10"
330
+ source_url: https://elevenlabs.io/pricing/api
331
+ verified: true
332
+ checked_on: "2026-11-13"
333
+ meters: { per_1k_characters: "0.08" }
334
+ - id: elevenlabs/eleven_flash_v2_5
335
+ mode: speech
336
+ currency: USD
337
+ effective_from: "2026-11-10"
338
+ source_url: https://elevenlabs.io/pricing/api
339
+ verified: true
340
+ checked_on: "2026-11-13"
341
+ note: "Page lists 'Flash / Turbo' at 0.04 without naming v2.5."
342
+ meters: { per_1k_characters: "0.04" }
@@ -0,0 +1,135 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://spendgate.invalid/schema/catalog-v1.json",
4
+ "title": "spendgate price catalog",
5
+ "description": "Prices and model metadata. All prices are decimal STRINGS (never floats). Unit is in the field name.",
6
+ "type": "object",
7
+ "additionalProperties": false,
8
+ "required": ["catalog_version", "models"],
9
+ "properties": {
10
+ "catalog_version": { "const": 1 },
11
+ "updated": { "$ref": "#/$defs/date" },
12
+ "providers": {
13
+ "type": "object",
14
+ "description": "Optional per-provider settlement rules, keyed by the provider part of a model id.",
15
+ "propertyNames": { "$ref": "#/$defs/slug" },
16
+ "additionalProperties": { "$ref": "#/$defs/settlement" }
17
+ },
18
+ "models": {
19
+ "type": "array",
20
+ "minItems": 1,
21
+ "items": { "$ref": "#/$defs/entry" }
22
+ }
23
+ },
24
+ "$defs": {
25
+ "date": { "type": "string", "format": "date", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" },
26
+ "slug": { "type": "string", "pattern": "^[a-z][a-z0-9_]*$", "description": "Provider slug = adapter module name (openai, azure_openai, anthropic, bedrock, google, azure_speech, elevenlabs). Vertex is an auth mode of google, not a slug." },
27
+ "decimal": {
28
+ "type": "string",
29
+ "pattern": "^(0|[1-9][0-9]*)(\\.[0-9]+)?$",
30
+ "description": "Non-negative decimal as a string, e.g. \"0.012\"."
31
+ },
32
+ "multiplier": {
33
+ "type": "string",
34
+ "pattern": "^(0\\.[0-9]*[1-9][0-9]*|[1-9][0-9]*(\\.[0-9]+)?)$",
35
+ "description": "Strictly positive decimal string."
36
+ },
37
+ "settlement": {
38
+ "type": "object",
39
+ "additionalProperties": false,
40
+ "description": "Catalog data can never fail open: there is no zero-charge option. Fail-open knobs live only in spendgate.yaml under fail_open.",
41
+ "properties": {
42
+ "free_statuses": {
43
+ "type": "array",
44
+ "items": { "enum": [429, 529] },
45
+ "uniqueItems": true,
46
+ "default": [429],
47
+ "description": "Upstream HTTP statuses (throttling only) that mean the provider rejected the call before processing it: the attempt costs 0 and the request may fail over (core predicate not_processed). Default [429] for every provider; anthropic sets [429, 529]."
48
+ }
49
+ }
50
+ },
51
+ "long_context": {
52
+ "type": "object",
53
+ "additionalProperties": false,
54
+ "required": ["threshold_input_tokens", "input_multiplier", "output_multiplier"],
55
+ "description": "When a single request's input_tokens EXCEED the threshold, the whole request is priced at the multiplied rates.",
56
+ "properties": {
57
+ "threshold_input_tokens": { "type": "integer", "minimum": 1 },
58
+ "input_multiplier": { "$ref": "#/$defs/multiplier", "description": "Applies to input, cached input and cache-write meters (text and audio)." },
59
+ "output_multiplier": { "$ref": "#/$defs/multiplier", "description": "Applies to output and reasoning meters." }
60
+ }
61
+ },
62
+ "meters": {
63
+ "type": "object",
64
+ "additionalProperties": false,
65
+ "minProperties": 1,
66
+ "properties": {
67
+ "input_per_mtok": { "$ref": "#/$defs/decimal" },
68
+ "output_per_mtok": { "$ref": "#/$defs/decimal" },
69
+ "cached_input_per_mtok": { "$ref": "#/$defs/decimal" },
70
+ "cache_write_per_mtok": { "$ref": "#/$defs/decimal" },
71
+ "reasoning_per_mtok": { "$ref": "#/$defs/decimal" },
72
+ "audio_input_per_mtok": { "$ref": "#/$defs/decimal" },
73
+ "cached_audio_input_per_mtok": { "$ref": "#/$defs/decimal" },
74
+ "audio_output_per_mtok": { "$ref": "#/$defs/decimal" },
75
+ "audio_input_per_minute": { "$ref": "#/$defs/decimal" },
76
+ "audio_granularity_seconds": { "type": "integer", "minimum": 1, "default": 1, "description": "Audio duration is rounded UP to a multiple of this many seconds (min one unit)." },
77
+ "per_1k_characters": { "$ref": "#/$defs/decimal" },
78
+ "per_image": { "$ref": "#/$defs/decimal" }
79
+ }
80
+ },
81
+ "entry": {
82
+ "type": "object",
83
+ "additionalProperties": false,
84
+ "required": ["id", "mode", "currency", "effective_from", "source_url", "verified", "meters"],
85
+ "properties": {
86
+ "id": { "type": "string", "pattern": "^[a-z][a-z0-9_]*/[A-Za-z0-9][A-Za-z0-9._:/-]*$", "description": "provider-slug/model, as the caller names it." },
87
+ "mode": { "enum": ["chat", "responses", "messages", "embedding", "transcription", "speech"] },
88
+ "currency": { "enum": ["USD", "EUR"] },
89
+ "effective_from": { "$ref": "#/$defs/date" },
90
+ "source_url": { "type": "string", "format": "uri", "pattern": "^https://" },
91
+ "verified": { "type": "boolean", "description": "true only if a person compared every price to source_url on checked_on." },
92
+ "checked_on": { "$ref": "#/$defs/date" },
93
+ "note": { "type": "string", "maxLength": 300 },
94
+ "deployment_type": { "enum": ["global", "data_zone", "regional", "standard", "batch", "flex", "priority", "provisioned"] },
95
+ "region": { "type": "string", "pattern": "^[a-z0-9-]+$" },
96
+ "price_multiplier": { "$ref": "#/$defs/multiplier", "default": "1", "description": "Applied to every meter after long-context, before FX." },
97
+ "meters": { "$ref": "#/$defs/meters" },
98
+ "long_context": { "$ref": "#/$defs/long_context" },
99
+ "limits": {
100
+ "type": "object",
101
+ "additionalProperties": false,
102
+ "properties": {
103
+ "max_output_tokens": { "type": "integer", "minimum": 1 },
104
+ "context_window": { "type": "integer", "minimum": 1 }
105
+ }
106
+ },
107
+ "deprecation_date": { "$ref": "#/$defs/date", "description": "First day the model is refused (the provider's shutdown date). Unset means no known end." }
108
+ },
109
+ "allOf": [
110
+ {
111
+ "if": { "properties": { "mode": { "enum": ["chat", "responses", "messages"] } } },
112
+ "then": {
113
+ "required": ["limits"],
114
+ "properties": {
115
+ "meters": { "required": ["input_per_mtok", "output_per_mtok"] },
116
+ "limits": { "required": ["max_output_tokens"] }
117
+ }
118
+ }
119
+ },
120
+ {
121
+ "if": { "properties": { "mode": { "const": "embedding" } } },
122
+ "then": { "properties": { "meters": { "required": ["input_per_mtok"] } } }
123
+ },
124
+ {
125
+ "if": { "properties": { "mode": { "const": "transcription" } } },
126
+ "then": { "properties": { "meters": { "anyOf": [{ "required": ["audio_input_per_minute"] }, { "required": ["audio_input_per_mtok"] }] } } }
127
+ },
128
+ {
129
+ "if": { "properties": { "mode": { "const": "speech" } } },
130
+ "then": { "properties": { "meters": { "anyOf": [{ "required": ["per_1k_characters"] }, { "required": ["audio_output_per_mtok"] }] } } }
131
+ }
132
+ ]
133
+ }
134
+ }
135
+ }
@@ -0,0 +1,5 @@
1
+ """The spendgate command line."""
2
+
3
+ from spendgate.cli.entry import main
4
+
5
+ __all__ = ["main"]
@@ -0,0 +1,58 @@
1
+ """The CLI's one HTTP client: a real admin API over TCP, or the admin app in-process (`--local`)."""
2
+
3
+ import httpx
4
+
5
+ type Json = dict[str, object]
6
+
7
+ EXIT_OK = 0
8
+ EXIT_REFUSED = 1 # the server understood and said no: invalid_request, not_found, conflict
9
+ EXIT_USAGE = 2 # argparse: bad command line
10
+ EXIT_CONFIG = 3 # the configuration file is invalid or missing
11
+ EXIT_AUTH = 4 # no admin key, or unauthorized / forbidden
12
+ EXIT_UNAVAILABLE = 5 # cannot reach the API, ledger unavailable, or a server error
13
+ _AUTH_STATUS = (401, 403)
14
+ _SERVER_ERROR = 500
15
+
16
+
17
+ class CliError(Exception):
18
+ """Prints `message` on stderr and exits with `code`."""
19
+
20
+ def __init__(self, code: int, message: str) -> None:
21
+ super().__init__(message)
22
+ self.code = code
23
+
24
+
25
+ def _exit_code(status: int) -> int:
26
+ if status in _AUTH_STATUS:
27
+ return EXIT_AUTH
28
+ return EXIT_UNAVAILABLE if status >= _SERVER_ERROR else EXIT_REFUSED
29
+
30
+
31
+ class Client:
32
+ def __init__(self, http: httpx.AsyncClient) -> None:
33
+ self._http = http
34
+
35
+ async def call(
36
+ self,
37
+ method: str,
38
+ path: str,
39
+ *,
40
+ query: dict[str, str] | None = None,
41
+ body: Json | None = None,
42
+ ) -> Json:
43
+ """The decoded JSON answer (empty for 204); any failure raises `CliError`."""
44
+ try:
45
+ r = await self._http.request(method, path, params=query, json=body)
46
+ except httpx.TransportError:
47
+ raise CliError(EXIT_UNAVAILABLE, "cannot reach the admin API") from None
48
+ if r.status_code < 400: # noqa: PLR2004
49
+ decoded: Json = r.json() if r.content else {}
50
+ return decoded
51
+ try:
52
+ err = r.json()["error"]
53
+ text = f"{err['code']}: {err['message']}" + (
54
+ f" (param {err['param']})" if err.get("param") else ""
55
+ )
56
+ except (ValueError, KeyError, TypeError):
57
+ text = f"HTTP {r.status_code}"
58
+ raise CliError(_exit_code(r.status_code), text)