-
Notifications
You must be signed in to change notification settings - Fork 0
Set up an OpenAI compatible Provider
This is the least-effort option: paste a key and it works. It is also the one that costs money per question, so read the cost note at the bottom before putting it on a busy page.
"OpenAI-compatible" means any endpoint that speaks the OpenAI chat-completions API — OpenAI itself, or a gateway, proxy or hosting provider that implements the same shape.
Settings › AI Fun Questions, choose the OpenAI-compatible card:
| Field | Default | Notes |
|---|---|---|
| OpenAI-compatible Endpoint | https://api.openai.com/v1/chat/completions |
Change only if you are using a different gateway |
| OpenAI-compatible API Key | (empty) | Paste your key, or better, define a constant — below |
| OpenAI-compatible Model | gpt-4o-mini |
Any chat model the endpoint offers |
Save, then load a page with the shortcode to confirm. There is no test button on the settings screen.
The recommended production setup is not to store the key in the database at all:
define( 'AI_FQ_OPENAI_KEY', 'sk-…' );The constant takes priority over anything saved in the settings, and the screen will tell you so: "Defined via AI_FQ_OPENAI_KEY in wp-config.php. The field below is ignored."
Why bother: a key in the database ends up in every database export, every migration, and every staging copy. A key in wp-config.php does not. See Keeping API Keys Out of the Database.
Unlike Ollama, this endpoint is validated with WordPress's wp_http_validate_url(), which rejects loopback and private addresses. You cannot point this provider at localhost, 127.0.0.1, or a 10.x / 192.168.x address — it will return a configuration error.
If you are running a local OpenAI-compatible server, use the Ollama provider instead, which permits local addresses by design. The request shape it sends differs slightly, so check your server accepts it.
Any compatible endpoint works. Set the endpoint URL to your gateway's chat-completions path and the model to whatever it exposes. The plugin sends a standard chat-completions request with a response_format asking for JSON, and reads the reply from choices[0].message.content.
If your gateway does not support response_format, it will usually ignore the field rather than fail — but if you get "The AI provider returned an invalid response", that is the first thing to suspect.
- Requests time out after 30 seconds and follow at most 2 redirects.
- The plugin asks the model for JSON and validates every field before showing anything. A reply that is not valid JSON, or is missing a field, produces an error rather than a broken widget.
- Length caps are enforced server-side: 300 characters for the question, 160 for the punchline, 200 for the hint. A model that rambles gets its answer rejected, not truncated.
| Symptom | Likely cause |
|---|---|
| "The OpenAI-compatible configuration is invalid." | Endpoint empty or not a valid public URL, key empty, or model empty |
| "The AI service is temporarily unavailable." | Bad key, no credit, rate limited upstream, network blocked, or timeout |
| "The AI provider returned an invalid response." | The model did not return usable JSON — try a more capable model |
| "The AI response did not meet the required content limits." | The model returned something too long, or empty after sanitising |
The plugin deliberately does not show you the provider's own error text — a raw upstream error can contain your endpoint or key. To see the real reason, enable WP_DEBUG on a staging site and check the debug log. Do not leave debug logging on in production.
Every widget that loads makes one API call. One widget on a page with a thousand daily visits is a thousand calls a day, and crawlers are included since the widget fetches on page load.
Work out your provider's per-call rate and multiply before putting this on a high-traffic page. If the number is uncomfortable, Set up Ollama has no marginal cost.
Getting started
- Home
- What AI Fun Questions Does
- Installing the Plugin
- The Settings Screen
- Adding the Widget to Your Site
Provider setup
Running it
- Keeping API Keys Out of the Database
- Rate Limits Explained
- Running Behind Cloudflare or a CDN
- What It Costs to Run
Troubleshooting
- Error Messages Reference
- Please Wait Before Requesting Another Question
- Could Not Generate a Question
Privacy and security
Extending