API Calls (AI) Documentation¶
Menu Location: AI > API Calls
Access Level: Administrator and above
Last Updated: 2026-03-02
Overview¶
The API Calls page (admin-edit.php?table=openaiCalls) is a log viewer for all OpenAI/AI API calls made by the system. Every AI-powered feature (product suggestions, log insights, blog generation, image analysis, campaign creation, etc.) logs its API interactions here. This provides full audit capability, cost tracking, and debugging for all AI features.
Primary Functions:
- View complete log of all AI API calls
- Track token usage (prompt, completion, total)
- Monitor API costs
- Debug AI feature responses
- Audit AI interactions across the system
- Identify which features are making API calls
Database Fields¶
| Field | Description |
|---|---|
| id | Unique identifier (auto-incrementing) |
| timestamp | Unix timestamp of when the call was made |
| page | Which feature/page triggered the API call (e.g., "log-insights.php?minutes=60") |
| md5hash | Hash of the request for deduplication/caching |
| apicall | Full API request payload (JSON) |
| response | Full API response (JSON) |
| error | Any error messages from the API |
| prompt_tokens | Number of tokens in the prompt |
| completion_tokens | Number of tokens in the AI response |
| total_tokens | Total tokens used (prompt + completion) |
| cost | Estimated cost of the API call |
How to Use¶
Browsing API Calls¶
- Navigate to AI > API Calls
- Browse the list of API calls (most recent first)
- Click on any entry to see full details including the request and response payloads
Identifying Feature Usage¶
The page field shows which feature triggered each call:
log-insights.php?minutes=60- System Log Insightsai-suggestions.php- Product Suggestions- Blog, campaign, and other AI features also log here
Tracking Costs¶
Review the cost and token columns to understand AI spending:
- Sort by cost to find the most expensive calls
- Sum costs over a period for budget tracking
- Compare prompt_tokens vs completion_tokens to optimize prompts
Debugging AI Features¶
When an AI feature produces unexpected results:
- Find the corresponding API call by timestamp and page
- Review the
apicallfield to see what was sent to the AI - Review the
responsefield to see what came back - Check the
errorfield for any API errors
Common Use Cases¶
Cost Monitoring¶
Regularly review API call costs to ensure AI features stay within budget. Look for features that make excessive or expensive calls.
Feature Auditing¶
Use the page field to understand which AI features are most active and their usage patterns.
Debugging Unexpected AI Output¶
When an AI feature produces wrong or strange results, trace the exact API call to see the full prompt and response.
Caching Effectiveness¶
The md5hash field enables request deduplication. Monitor for repeated identical requests to verify caching is working.
Tips & Best Practices¶
- Check this log when AI features produce unexpected results
- Monitor token counts to identify opportunities for prompt optimization
- The
pagefield is your key to finding calls from specific features - Large
apicallandresponsefields can contain substantial JSON - use a JSON formatter for readability - Review error entries periodically to catch recurring API issues
FAQ¶
How long are API call logs retained?¶
Logs are retained indefinitely in the database. The table grows over time as more AI calls are made.
Can I delete old API call records?¶
Records can be removed through the admin-edit interface, but keeping them provides valuable audit trail and debugging history.
What AI models are being used?¶
The apicall JSON payload includes the model parameter. Common models include gpt-4, gpt-4o-mini, and others configured in the system.
Why are some costs showing as 0?¶
Cost calculation may not be available for all API calls, or cached responses may show 0 cost.
Related Pages¶
- AI Overview - Central AI dashboard
- AI Suggestions for Product - Product improvement AI
- System Log Insights - AI-powered log analysis
- AI Campaigns - Marketing campaign AI