feat: extend enterprise gateway policies billing protocols and operations
This commit is contained in:
1 parent
1528b71882
commit
af43947b5d
67 files changed
+1822
-69
No files matched your search
@@ -65,6 +65,10 @@ public class UsageAuditService {
|
||||
int latency, Integer firstTokenMs, java.math.BigDecimal cost, Object output, String code, String message) {
|
||||
jdbc.update("UPDATE usage_events SET status=?,input_units=?,output_units=?,cached_input_units=?,latency_ms=?,first_token_ms=?,cost_amount=?,output_payload=?::jsonb,error_code=?,error_message=?,updated_at=now() WHERE id=?",
|
||||
status,tokens.prompt(),tokens.completion(),tokens.cached(),latency,firstTokenMs,cost,json(output),code,message,id);
|
||||
jdbc.update("UPDATE usage_events SET cache_write_units=? WHERE id=?",tokens.cacheWrite5m()+tokens.cacheWrite1h(),id);
|
||||
}
|
||||
public void observeUsage(UUID id,String protocol,Object observed) {
|
||||
jdbc.update("UPDATE usage_events SET observed_usage=?::jsonb WHERE id=?",json(Map.of("protocol",protocol,"usage",observed)),id);
|
||||
}
|
||||
|
||||
public void recordCall(
|
||||
@@ -393,8 +397,8 @@ public class UsageAuditService {
|
||||
ObjectNode result = objectMapper.createObjectNode();
|
||||
node.fields().forEachRemaining(entry -> {
|
||||
String key = entry.getKey().toLowerCase();
|
||||
boolean usageField = java.util.Set.of("prompt_tokens", "completion_tokens", "total_tokens", "cached_tokens", "reasoning_tokens", "audio_tokens", "accepted_prediction_tokens", "rejected_prediction_tokens", "prompt_cache_hit_tokens", "prompt_cache_miss_tokens", "max_tokens", "max_completion_tokens").contains(key) && entry.getValue().isNumber();
|
||||
boolean usageDetails = java.util.Set.of("prompt_tokens_details", "completion_tokens_details").contains(key) && entry.getValue().isObject();
|
||||
boolean usageField = java.util.Set.of("prompt_tokens", "completion_tokens", "total_tokens", "cached_tokens", "reasoning_tokens", "audio_tokens", "accepted_prediction_tokens", "rejected_prediction_tokens", "prompt_cache_hit_tokens", "prompt_cache_miss_tokens", "max_tokens", "max_completion_tokens", "input_tokens", "output_tokens", "cache_read_input_tokens", "cache_creation_input_tokens", "ephemeral_5m_input_tokens", "ephemeral_1h_input_tokens", "prompttokencount", "candidatestokencount", "thoughtstokencount", "cachedcontenttokencount").contains(key) && entry.getValue().isNumber();
|
||||
boolean usageDetails = java.util.Set.of("prompt_tokens_details", "completion_tokens_details", "input_tokens_details", "output_tokens_details").contains(key) && entry.getValue().isObject();
|
||||
if (key.contains("authorization") || key.contains("api_key") || key.contains("apikey") || (key.contains("token") && !usageField && !usageDetails) || key.contains("secret") || key.contains("password")) result.put(entry.getKey(), "[REDACTED]");
|
||||
else result.set(entry.getKey(), sanitize(entry.getValue()));
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user