Dynamic API¶
Add-on for OG AI Core. Give one OG AI Core environment several API keys. Dynamic API rotates them and moves to the next key when one hits a rate limit, a quota or an authentication error. With Provider fallback, a query that fails on one environment runs once on a backup environment, so your chatbot still answers.
Requires: OG AI Core (free or Pro) and a Dynamic API licence. WordPress 6.0+, PHP 8.1+. Provider fallback needs OG AI Core 1.2.36 or later.
Install¶
Install it from OG AI Core > Manage add-ons > Get add-ons: one click if you own it, or enter its licence key. Then open OG AI Core > Add-ons > Dynamic API. Without OG AI Core it does nothing.
Settings save themselves as you change them. Forms that hold API keys keep their Save button.
Settings¶
General
- Rotation: use the keys below for OG AI Core queries. When off, every query uses the environment's own key.
- Cooldown: how long a key is skipped after a rate-limit (429), quota or authentication (401/403) error. Default 5 minutes, up to 1440.
Per environment (one block for each OG AI Core environment):
- Distribution: round-robin (one after the other) or weighted (by the weight of each key).
- Keys: label, API key, enabled, weight, daily soft cap and Rules only (a key used only by rules).
- Rules: label, enabled, query types (text and chat, embeddings, images, transcription, assistant, other), chatbot IDs, and the keys to use.
Saved keys are never shown again: only their last four characters are. Leave a key field empty to keep the saved key.
More keys, more capacity?
Providers usually limit rates per account or project, not per key. Rotation adds capacity only when the keys come from different accounts or projects. Features that keep state at the provider (uploaded files, vector stores, a previous response) need the same project: pin those chatbots to one key with a rule.
Provider fallback¶
When an environment runs out of credit, its key stops working or it hits a rate limit, the query runs once on a backup environment instead, and the visitor still gets an answer.
- Tick Switch to the backup environment when one fails.
- Add rows: When this fails (an environment) and Use this (its backup).
- Optional: a Stand-in model for chat, used for chat queries whose model the backup does not have. Type the model ID exactly as the backup environment names it.
How it decides:
- Rows are tried in order. Up to 6 rows.
- The same model is used on the backup when the backup has it.
- Embeddings only switch to the same model, so stored Knowledge keeps matching.
- Free models never switch, so they never start costing money.
- After a credit or key error, the first environment is skipped for the cooldown time, then tried again.
OG AI Core makes sure that:
- the backup runs on a copy of the query, without the first environment's key;
- it happens once per query, never twice;
- it never happens after part of a reply has already been streamed;
- function-calling rounds stay on the environment they started on.
The Status tab lists every switch: time, query type, chatbot ID, from, to, result and error.
Status¶
The Status section shows each key with its state (Ready, Cooling down, Daily cap reached, Disabled, Rules only), requests and failures today, the cooldown end and the last error. Clear cooldown puts a key back into use. Counters restart at midnight in the site time zone.
Recent decisions lists the last queries OG AI Core passed to the add-on and what it did: key assigned, key kept, left untouched or query failed. Run a query in the Playground to see it work.
How it works¶
Dynamic API uses only OG AI Core's public filters and makes no calls of its own. It hooks into ogaie_ai_query, ogaie_ai_embeddings_query and ogaie_ai_feedback_query, then ogaie_ai_allowed, ogaie_ai_exception and ogaie_ai_reply. It picks a key for each query, counts failures and cools a key down on rate-limit, quota and auth errors. Provider fallback answers ogaie_ai_route and ogaie_ai_failover, and logs through ogaie_ai_fallback_used and ogaie_ai_fallback_failed. Every callback catches its own errors, so a problem in the add-on never breaks an OG AI Core query.
Fail safe: when no key is usable, or the engine would ignore a per-query key, the query is left alone and OG AI Core uses its own key.
Where an engine ignores a per-query key, the add-on leaves the query alone:
- OVH environments always use the environment key.
- Google (Gemini) uses the per-query key for text queries only, and not when Use Standard API is on.
- OpenAI Assistants use the environment key.
Hooks¶
ogda_error_kindreceives the kind found by the built-in patterns and the raw error message. Returnrate_limit,quotaorauthto make the key cool down; anything else only counts the failure.ogda_engine_uses_query_keyreceives the built-in answer, the environment type and the query type (text,embed,image,transcribe,assistantorother). Returntruewhen an engine sends the per-query key.
// Treat "insufficient_quota" from a custom engine as a quota error.
add_filter( 'ogda_error_kind', function ( $kind, $message ) {
return str_contains( $message, 'insufficient_quota' ) ? 'quota' : $kind;
}, 10, 2 );
Data¶
| Option | Holds |
|---|---|
ogda_settings |
Rotation, cooldown, keys and rules |
ogda_state |
Counters and cooldowns |
ogda_fallback |
Provider fallback: on/off and the rows |
ogda_fallback_log |
The last 40 switches |
Error messages are stored without keys and cut to 300 characters. The add-on sends nothing anywhere.