Skip to content

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

  1. Navigate to AI > API Calls
  2. Browse the list of API calls (most recent first)
  3. 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 Insights
  • ai-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:

  1. Find the corresponding API call by timestamp and page
  2. Review the apicall field to see what was sent to the AI
  3. Review the response field to see what came back
  4. Check the error field 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

  1. Check this log when AI features produce unexpected results
  2. Monitor token counts to identify opportunities for prompt optimization
  3. The page field is your key to finding calls from specific features
  4. Large apicall and response fields can contain substantial JSON - use a JSON formatter for readability
  5. 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.


  • AI Overview - Central AI dashboard
  • AI Suggestions for Product - Product improvement AI
  • System Log Insights - AI-powered log analysis
  • AI Campaigns - Marketing campaign AI