recordSuccessForApiKey is recordSuccess + per-API-key usage attribution. When apiKeyID is empty (legacy single-key path or unauthenticated path), only the global counters are updated. Persistence errors are logged but do not propagate.
(apiKeyID string, inputTokens, outputTokens int, credits float64)
| 1346 | thinkingOutput = "" |
| 1347 | } |
| 1348 | outputTokens = estimateClaudeOutputTokens(outputContent, thinkingOutput, toolUses) |
| 1349 | |
| 1350 | h.recordSuccessForApiKey(apiKeyID, inputTokens, outputTokens, credits) |
| 1351 | h.pool.RecordSuccess(account.ID) |
| 1352 | h.pool.UpdateStats(account.ID, inputTokens+outputTokens, credits) |
| 1353 | h.promptCache.Update(account.ID, cacheProfile) |
| 1354 | h.recordSuccessLog("claude", model, account.ID, inputTokens+outputTokens, credits, time.Since(reqStart).Milliseconds()) |
| 1355 | |
| 1356 | stopReason := mapClaudeStopReason(upstreamStopReason, len(toolUses)) |
| 1357 | |
| 1358 | ensureMessageStart() |
| 1359 | h.sendSSE(w, flusher, "message_delta", map[string]interface{}{ |