The SQL Query Builder includes a built-in AI Assistant that helps you write, refine, and troubleshoot SQL queries — right from your WordPress dashboard. To use the assistant, you’ll first need to configure it with a ChatGPT API key.
Who Can Use the AI Assistant? #
The AI Assistant is available to both free and premium users. There are no extra charges from WP Data Access — we simply pass your request to ChatGPT and return its response. You only pay OpenAI for the usage of your own API key.
Getting Started #
When you launch the AI Assistant for the first time, you’ll be prompted to set up your connection:
- If you already have a valid ChatGPT API key, just paste it into the dialog and you’re ready to go
- If not, follow the steps outlined in section How to Get a ChatGPT API Key
How to Get a ChatGPT API Key #
To use the AI Assistant in the Query Builder, you need a valid ChatGPT API key from OpenAI.
- Go to the official OpenAI API page:
https://platform.openai.com/account/api-keys - Log in with your OpenAI account, or create a free account if you don’t have one yet
- Click the “Create new secret key” button to generate your API key
- Copy the key and paste it into the setup dialog when launching the AI Assistant for the first time
Note: Keep your API key safe and never share it publicly. You will be billed directly by OpenAI for your usage. The plugin does not charge or log your key.
Switch API key #
Want to switch API keys later? Click Settings from the toolbar menu and choose Update ChatGPT API Key to enter a new one.
Note: ChatGPT API keys are stored per user, so each admin can use their own key.
Secure Your API Key (Recommended) #
For extra security, you can store your API key in encrypted format by adding the following constant to your wp-config.php:
define('WPDA_ENCRYPT_AI_KEY', 'enter-your-32-character-strong-random-string-here');
Using the AI Assistant #
Once an API key is set, just click the AI Assistant icon on the query toolbar to get started. The assistant supports both gpt-3.5-turbo and gpt-4-turbo models.
- Click the hint icon to learn how to formulate effective questions
- Enable the explanations icon to include step-by-step reasoning in responses
You can:
- Copy full responses or SQL queries to your clipboard
- Insert queries directly into the editor (this will overwrite current content)
- Add table definitions to improve the quality of the generated SQL
To add table definitions:
- Click Add Table Definitions
- Click inside the Table List
- Select the relevant tables for your query
Example #
- Write a query to select the average and total salaries of all employees per department
- Use gpt-3.5-turbo model
- Add explanations
- Added table definitions for tables dept and emp
AI-Powered Error Fixes #
If a query throws an error and ChatGPT is configured, an AI icon will appear in the message bar. Click it to send the error details to ChatGPT for troubleshooting. You can also attach table definitions to give ChatGPT better context and improve its suggestions.