Commit 9c2436d
committed
Fix metadata token counting for Anthropic format responses
The _log_metadata method only supported OpenAI format usage keys
(prompt_tokens, completion_tokens) but Anthropic responses use
different keys (input_tokens, output_tokens). This caused null
token counts in metadata.json for dedaluslabs and firmware providers
when using the /v1/messages endpoint.
Changes:
- Add fallback from OpenAI to Anthropic format for token counts
- Use explicit None checks instead of 'or' to handle 0 values
- Calculate total_tokens if missing from Anthropic responses
- Handle stop_reason (Anthropic) as well as finish_reason (OpenAI)1 parent 5293b13 commit 9c2436d
File tree
2 files changed
+28
-5
lines changed- src/rotator_library
- anthropic_compat
2 files changed
+28
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
131 | | - | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
132 | 135 | | |
133 | 136 | | |
134 | 137 | | |
| |||
416 | 419 | | |
417 | 420 | | |
418 | 421 | | |
419 | | - | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
420 | 426 | | |
421 | 427 | | |
422 | 428 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
265 | 265 | | |
266 | 266 | | |
267 | 267 | | |
| 268 | + | |
268 | 269 | | |
269 | 270 | | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
270 | 274 | | |
271 | 275 | | |
272 | 276 | | |
| |||
279 | 283 | | |
280 | 284 | | |
281 | 285 | | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
282 | 299 | | |
283 | 300 | | |
284 | 301 | | |
| |||
288 | 305 | | |
289 | 306 | | |
290 | 307 | | |
291 | | - | |
292 | | - | |
293 | | - | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
294 | 311 | | |
295 | 312 | | |
296 | 313 | | |
| |||
0 commit comments