Skip to content

Commit 9775c63

Browse files
committed
Improve logging for OpenAI API cost investigation
Replaces token count debug logs with more detailed error logs including content length, prompt length, message lengths, content type, and a preview of the content. This aids in identifying cost-related issues with OpenAI API usage.
1 parent d71ee9d commit 9775c63

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

app/services/ai/ai_moderator.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -434,17 +434,15 @@ def _analyze_with_custom_prompt(self, content, custom_prompt):
434434
435435
Does content violate this rule? JSON only:"""
436436

437-
# DEBUG: Log exact token counts before API call
438-
system_tokens = self.count_tokens(system_message)
439-
user_tokens = self.count_tokens(user_message)
440-
total_tokens = system_tokens + user_tokens
441-
current_app.logger.info(
442-
f"[DEBUG] About to call OpenAI API - "
443-
f"System: {system_tokens} tokens, "
444-
f"User: {user_tokens} tokens, "
445-
f"Total: {total_tokens} tokens, "
437+
# CRITICAL: Log what we're actually sending to identify cost issue
438+
current_app.logger.error(
439+
f"[COST INVESTIGATION] Sending to OpenAI - "
440+
f"Content length: {len(content)} chars, "
446441
f"Custom prompt length: {len(custom_prompt)} chars, "
447-
f"Content length: {len(content)} chars"
442+
f"System message length: {len(system_message)} chars, "
443+
f"User message length: {len(user_message)} chars, "
444+
f"Content type: {type(content).__name__}, "
445+
f"Content first 200 chars: {content[:200] if len(content) > 0 else 'EMPTY'}"
448446
)
449447

450448
# Wrap API call with retry logic

0 commit comments

Comments
 (0)