Infomaniak AI Toolkit
AI Provider for Infomaniak for the WordPress AI Client. Provides access to open-source models (Llama, Mistral, DeepSeek) hosted in Switzerland.
by Custom · github.com/marjc5/infomaniak-ai-toolkit · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/marjc5/infomaniak-ai-toolkit/archive/refs/heads/main.zipReadme
Infomaniak AI Toolkit (Unofficial)
An unofficial AI Provider for Infomaniak AI Tools for the PHP AI Client SDK.
Note: This plugin is not officially maintained by Infomaniak. It is developed independently by a partner developer.
Provides access to open-source models hosted in Switzerland via Infomaniak's OpenAI-compatible API. Supports text generation, image generation, function calling, conversation memory with automatic compaction, and usage tracking with per-preset cost attribution.
Requirements
- PHP 8.0 or higher
- WordPress 6.9 or higher
- WordPress 6.9 requires the wordpress/php-ai-client package to be installed separately
- WordPress 7.0+ includes the PHP AI Client natively
- An Infomaniak account with an AI Tools product
Installation
As a WordPress Plugin
- Download the plugin files
- Upload to
/wp-content/plugins/infomaniak-ai-toolkit/ - Activate the plugin through the WordPress admin
- Configure your API key in Settings > Connectors
- Configure your Product ID in Settings > Infomaniak AI
Configuration
Product ID
The Infomaniak AI product ID can be configured in three ways (checked in this order):
- Filter: Use the
infomaniak_ai_product_idfilter - Constant: Define
INFOMANIAK_AI_PRODUCT_IDinwp-config.php - Option: Set it via Settings > Infomaniak AI in the WordPress admin
// Via wp-config.php constant
define( 'INFOMANIAK_AI_PRODUCT_ID', '123456' );
// Via filter
add_filter( 'infomaniak_ai_product_id', function() {
return '123456';
});
API Key
The API key is managed via the WordPress Connectors system at Settings > Connectors. The key is stored as connectors_ai_infomaniak_api_key.
You can obtain your API key from the Infomaniak Manager.
Usage
With WordPress
The provider automatically registers itself with the PHP AI Client on the init hook. Simply ensure both plugins are active and configure your credentials:
use WordPress\AiClient\AiClient;
// Use the provider (auto-detected)
$result = AiClient::prompt( 'Hello, world!' )
->usingTemperature( 0.7 )
->generateText();
// Force the Infomaniak provider
$result = AiClient::prompt( 'Explain quantum computing' )
->usingProvider( 'infomaniak' )
->generateText();
// Use a specific model
$result = AiClient::prompt( 'Write a haiku' )
->usingProvider( 'infomaniak' )
->usingModelPreference( 'llama3' )
->generateText();
// Generate an image
$file = AiClient::prompt( 'A mountain landscape at sunset' )
->usingProvider( 'infomaniak' )
->generateImage();
$dataUri = $file->getDataUri(); // data:image/png;base64,...
$mimeType = $file->getMimeType(); // image/png
Markdown Commands
Markdown commands let site admins create AI commands without writing PHP. Each command is a .md file with YAML frontmatter (configuration) and a body (prompt template).
Quick start
Create a file in wp-content/ai-commands/translate.md:
---
description: Translates text to a target language.
max_tokens: 2000
temperature: 0.3
system: |
You are a professional translator.
Preserve formatting, tone, and meaning.
Return only the translated text, no commentary.
---
Translate the following text to {{language}}:
{{content}}
That's it. The command is auto-discovered and registered as a WordPress Ability:
- REST API:
POST /wp-json/wp-abilities/v1/abilities/infomaniak/translate/run - MCP tool: automatically exposed to AI agents
- Input:
{"language": "English", "content": "Bonjour le monde."}
How it works
- Frontmatter defines the command configuration (description, temperature, system prompt, etc.)
- Body is the prompt template with
{{variable}}placeholders - Variables are auto-detected from
{{variable}}patterns and used to generate the input JSON Schema - Name is derived from the filename (e.g.,
translate.mdbecomestranslate) - Commands inherit all preset features: usage tracking, conversation memory, compaction
Command directories
Files are scanned from these directories (first match wins on name conflicts):
- Directories added via the
infomaniak_ai_commands_dirsfilter - Active plugins:
{plugin}/ai-commands/ - Active theme:
{theme}/ai-commands/
// Add a custom directory
add_filter( 'infomaniak_ai_commands_dirs', function ( array $dirs ): array {
$dirs[] = WP_CONTENT_DIR . '/my-ai-commands';
return $dirs;
});
Frontmatter reference
| Field | Default | Description |
|---|---|---|
description |
required | What the command does |
label |
derived from filename | Human-readable label |
category |
content |
Ability category slug |
permission |
edit_posts |
Required WordPress capability |
temperature |
0.7 |
Generation temperature |
max_tokens |
1000 |
Maximum response tokens |
model |
null (SDK picks) |
Preferred model ID |
model_type |
llm |
llm or image |
system |
null |
System instruction (supports multi-line with \|) |
conversational |
false |
Enable conversation memory |
provider |
infomaniak |
AI provider ID |
Example commands
See the examples/commands/ directory for copy-paste-ready command files:
- summarize.md -- Summarizes content concisely
- translate.md -- Translates text to a target language
These files are not auto-loaded. Copy them to your theme's ai-commands/ directory or a custom directory registered via the infomaniak_ai_commands_dirs filter.
Markdown commands vs PHP presets
| Markdown Commands | PHP Presets | |
|---|---|---|
| Audience | Site admins, content creators | Developers |
| Syntax | Markdown + {{variables}} |
PHP classes + templates |
| Complexity | Simple text prompts | Full control (data fetching, validation, custom execution) |
| Features | Text generation, system prompts, conversation memory | Everything (image generation, JSON output, custom logic) |
| Location | .md files in ai-commands/ |
PHP classes in plugins |
Use markdown commands for simple, template-based AI prompts. Use PHP presets when you need data fetching, custom validation, structured output, or image generation.
AI Presets
This plugin provides BasePreset, an abstract class for building reusable AI commands. Each preset is a self-contained unit combining a prompt template, system instruction, AI configuration, and input validation -- all auto-registered as a WordPress Ability discoverable via REST API and MCP.
Why presets? Without presets, every AI feature requires writing the same boilerplate: build a prompt string, configure the AI client, handle errors, register an ability. With BasePreset, you declare what the AI should do, and the framework handles how.
Creating a preset
- Extend
BasePresetin your own plugin:
namespace MyPlugin\Presets;
use WordPress\InfomaniakAiToolkit\Presets\BasePreset;
class SummarizePreset extends BasePreset
{
public function name(): string { return 'summarize'; }
public function label(): string { return 'Summarize Content'; }
public function description(): string { return 'Generates a concise summary.'; }
public function inputSchema(): array
{
return [
'type' => 'object',
'properties' => [
'content' => ['type' => 'string', 'description' => 'Text to summarize.'],
'max_sentences' => ['type' => 'integer', 'default' => 3],
],
'required' => ['content'],
];
}
protected function templateName(): string { return 'summarize'; }
protected function systemTemplateName(): ?string { return 'content-editor'; }
protected function maxTokens(): int { return 500; }
}
- Create a PHP template at
your-plugin/templates/presets/summarize.php:
Summarize the following content:
<?= $content ?>
Requirements:
- Maximum <?= (int) $max_sentences ?> sentences.
- Focus on the main points.
- Register it on
wp_abilities_api_init:
add_action( 'wp_abilities_api_init', function() {
$preset = new \MyPlugin\Presets\SummarizePreset();
$preset->registerAsAbility();
});
The preset is now available as:
- REST API:
POST /wp-json/wp-abilities/v1/abilities/infomaniak/summarize/run - MCP tool: automatically exposed to AI agents
- PHP:
$preset->execute(['content' => '...'])
How it works
- PHP templates -- Prompts are
.phpfiles rendered withextract(). Variables come fromtemplateData(), which you can override to transform or enrich input. - System prompts -- Optional
.phpfiles in asystem/subdirectory set the AI persona (content editor, SEO expert, etc.). - Auto-detection --
BasePresetfinds templates relative to your plugin root automatically viaReflectionClass. No path configuration needed. - Structured output -- Override
outputSchema()to return a JSON Schema and the preset will useasJsonResponse()and decode the result automatically. - Image generation -- Override
execute()to callgenerateImage()instead ofgenerateText(). UseModelConfigto set orientation and other image options. OverridemodelType()to return'image'. - Model preference -- Call
setModelPreference()at runtime to override the model, or overridemodelPreference()for a default. - Provider override -- Override
provider()to use a different AI provider (defaults to'infomaniak'). - Agent mode -- Override
tools()to provide tools andexecute()automatically uses theAgentLoopfor function calling iteration. - Extensible -- Use the
infomaniak_ai_presetsfilter to add or remove presets from any plugin.
Overridable methods
| Method | Default | Description |
|---|---|---|
temperature() |
0.7 |
Controls response randomness |
maxTokens() |
1000 |
Maximum response length |
requestTimeout() |
60.0 |
HTTP request timeout in seconds for AI API calls |
outputSchema() |
null |
JSON Schema for structured output |
provider() |
'infomaniak' |
AI provider ID |
category() |
'content' |
Ability category slug |
permission() |
'edit_posts' |
Required WordPress capability |
annotations() |
readonly, non-destructive, idempotent |
MCP behavioral annotations |
templateData($input) |
passthrough | Transform input before rendering |
modelPreference() |
null |
Preferred model ID (SDK picks if null) |
modelType() |
'llm' |
Model type: 'llm' or 'image' |
tools() |
[] |
Tools for agent mode (function calling) |
maxAgentIterations() |
10 |
Max tool-calling rounds |
Examples
See the examples/presets/ directory for complete, copy-paste-ready presets:
- basic-preset.php -- Minimal preset with a prompt template and system instruction
- json-output-preset.php -- Structured JSON output with
outputSchema() - post-aware-preset.php -- Fetches WordPress post data via
templateData()and validates with a customexecute()override - image-preset.php -- Image generation with a custom
execute()override usinggenerateImage()andModelConfig - conversational-preset.php -- Multi-turn chat with conversation memory and optional compaction
- agent-preset.php -- Agent with function calling tools that search and read WordPress content
Agent Orchestrator
The AgentLoop class provides a function calling loop that lets AI models use tools autonomously. The model receives tool declarations, decides when to call them, and the loop handles execution and iteration until the model produces a final response.
With a preset
Override tools() in your preset to enable agent mode automatically:
use WordPress\InfomaniakAiToolkit\Agent\Tool;
use WordPress\InfomaniakAiToolkit\Presets\BasePreset;
class ResearchPreset extends BasePreset
{
protected function tools(): array
{
return [
new Tool(
'search_posts',
'Search WordPress posts by keyword',
[
'type' => 'object',
'properties' => [
'query' => ['type' => 'string', 'description' => 'Search keywords'],
],
'required' => ['query'],
],
function (array $args): array {
$posts = get_posts(['s' => $args['query'], 'posts_per_page' => 5]);
return array_map(fn($p) => [
'id' => $p->ID,
'title' => $p->post_title,
'excerpt' => wp_trim_words($p->post_content, 50),
], $posts);
}
),
];
}
protected function maxAgentIterations(): int { return 5; }
// ...
}
When tools() returns tools, execute() uses AgentLoop instead of a single AI call.