mage-os / module-ai-base
Base AI module for Mage-OS: register and retrieve configuration for multiple AI backends.
Package info
github.com/mage-os/module-ai-base
Type:magento2-module
pkg:composer/mage-os/module-ai-base
Requires
- php: ^8.2
- magento/framework: ^103.0.8 || ^104.0
- magento/module-backend: ^102.0 || ^103.0
- magento/module-config: ^101.2 || ^102.0
- magento/module-cron: ^100.4
- magento/module-reports: ^100.4
- magento/module-store: ^101.1 || ^102.0
- magento/module-ui: ^101.2 || ^102.0
- symfony/ai-anthropic-platform: ^0.15
- symfony/ai-open-ai-platform: ^0.15
- symfony/ai-platform: ^0.15
- symfony/http-client: ^7.3 || ^8.0
Requires (Dev)
Suggests
- mage-os/library-ai-opencode-custom-platform: Enables the bundled AI client and Test Connection for a self-hosted OpenCode server.
- mage-os/library-ai-opencode-zen-platform: Enables the bundled AI client and Test Connection for OpenCode Zen.
- symfony/ai-azure-platform: Enables the bundled AI client and Test Connection for Azure OpenAI.
- symfony/ai-deep-seek-platform: Enables the bundled AI client and Test Connection for Deepseek.
- symfony/ai-gemini-platform: Enables the bundled AI client and Test Connection for Google Gemini.
- symfony/ai-generic-platform: Enables the bundled AI client and Test Connection for OpenAI-Compatible (LiteLLM, OpenRouter-style gateways, and other self-hosted OpenAI-compatible servers).
- symfony/ai-hugging-face-platform: Enables the bundled AI client and Test Connection for HuggingFace.
- symfony/ai-lm-studio-platform: Enables the bundled AI client and Test Connection for LM Studio.
- symfony/ai-ollama-platform: Enables the bundled AI client and Test Connection for Ollama.
- symfony/ai-open-router-platform: Enables the bundled AI client and Test Connection for OpenRouter.
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-04 12:34:45 UTC
README
One place in Magento to configure your AI providers, one client every module can use to call them, and a dashboard that shows what each module spends.
![]() |
![]() |
| Stores > Configuration > Mage-OS > AI Configuration | Reports > AI Token Usage |
What it provides
- Provider configuration. OpenAI, Anthropic, Google Gemini, Azure OpenAI, DeepSeek, OpenRouter, Opper, Hugging Face, Ollama, LM Studio, OpenCode Zen, a self-hosted OpenCode server and any OpenAI-compatible gateway. Add a provider more than once, name each row, switch rows off, test the connection and refresh the model list from the form. API keys are encrypted at rest and never shown again.
- One client for every provider. Chat, streaming, tool calls and reasoning through a single
interface. Options like
max_tokensandtool_choiceare translated per provider, and failures come back as typed exceptions you can retry or skip. - Let the admin choose. A ready-made source model for your own
system.xml, so a store picks which configured service your feature uses. - Usage tracking. Token counts per module, service and store, on a dashboard, a grid and a CLI report. Prompts and responses are never stored.
- Extensible. Add your own provider with one class and a few lines of
di.xml.
Installation
composer require mage-os/module-ai-base bin/magento module:enable MageOS_AiBase bin/magento setup:upgrade
Requires Magento 2.4.8+ or Mage-OS 1.1+, and PHP 8.2+. OpenAI and Anthropic work out of the box; every other provider needs its Symfony AI bridge package, which the admin form names when it's missing.
Two bridges do not come from Symfony, which has released none for OpenCode: Mage-OS ships
mage-os/library-ai-opencode-zen-platform (the hosted OpenCode Zen gateway) and
mage-os/library-ai-opencode-custom-platform (a self-hosted opencode serve instance). They are
optional like the rest, and the admin form names them the same way.
OpenCode Custom talks to your own opencode server rather than a hosted API. Its credential is
the server's password (OPENCODE_SERVER_PASSWORD), models are named providerID/modelID exactly
as the server routes them (anthropic/claude-sonnet-4-6), and Refresh Models lists every model
the server has configured. Every call opens a throw-away session with the agent's own tools
switched off and all permissions denied, then deletes it. Tools your module offers still work: the
bridge describes them in the prompt and parses the model's calls back out, with reliability
depending on the model. The universal max_tokens / temperature / top_p / stop options are
accepted but dropped, because the server applies its own limits. If Magento runs in Docker, start
the server with --hostname 0.0.0.0 and a password, and use http://host.docker.internal:4096 as
the base URL. Set Agent to a plain agent defined in the server's own config: the default agent
injects opencode's own system prompt and the AGENTS.md of the directory the server runs in, which
leaks into answers.
The module only adds admin screens, so it works the same with Luma, Hyvä or a headless storefront.
The client is built on symfony/ai-platform 0.15, which is
experimental. This module's Api interfaces absorb its changes; code that reaches the Symfony
platform directly does not.
Getting started
- Go to Stores > Configuration > Mage-OS > AI Configuration and open Services.
- Click Add Service, choose your provider, for example OpenAI, paste the API key and pick a model.
- Click Save Config. Test Connection and Refresh Models only work on saved rows.
- Click Test Connection on the row. It sends a short prompt and shows the latency and the reply. A failure says whether the key was rejected, the host was unreachable or the provider is rate limiting you.
- Open the module that uses AI and pick this service in its own settings. Modules that offer Automatic use the first enabled service in the list whose provider is installed.
- After the first calls, Reports > Mage-OS AI > AI Token Usage shows the tokens each module used.
Configuration
Stores > Configuration > Mage-OS > AI Configuration > Services
Scope: Default, Website and Store View. Each row is one configured service; add the same provider more than once for separate accounts or models. The pencil names a row, and the toggle takes it out of use without deleting its key.
| Provider | Fields |
|---|---|
| OpenAI, Anthropic, Google Gemini, DeepSeek, OpenRouter | API Key, Model |
| Azure OpenAI | API Key, Endpoint (https://<resource>.openai.azure.com), Model |
| Hugging Face | API Key, Model (free text) |
| Ollama | Base URL (default http://localhost:11434), Model (free text) |
| LM Studio | Base URL (default http://localhost:1234), Model (free text) |
| OpenAI-Compatible | Base URL, API Key, Model (free text) |
| Opper | API Key, Model (free text) |
| OpenCode Zen | API Key, Base URL (default https://opencode.ai/zen), Model (free text) |
| OpenCode Custom | Base URL (default http://127.0.0.1:4096), Username (default opencode), Server Password, Agent, Model (free text) |
API keys are encrypted and shown as ****** once saved. Refresh Models replaces a row's model
suggestions with the provider's live list, for OpenAI, Anthropic, Gemini, OpenRouter, Opper, Ollama,
LM Studio, OpenCode Zen and OpenCode Custom.
Stores > Configuration > Mage-OS > AI Configuration > Usage Tracking
Scope: Default only.
| Setting | Default | What it does |
|---|---|---|
| Enable Usage Tracking | Yes | Records token counts for every call. Off stops recording; history already collected stays. |
| Raw Usage Retention (Days) | 30 | How long individual calls are kept before they are rolled up into daily totals. |
| Daily Usage Retention (Days) | 730 | How long the daily totals are kept. |
| Cleanup Cron Schedule | 0 3 * * * |
When the roll-up and cleanup run. Empty means never. |
The Usage Tracking guide covers what is recorded and how retention works.
Where it shows up
- Stores > Configuration > Mage-OS > AI Configuration: the services and usage settings above. Needs the Mage-OS AI Configuration role resource.
- Reports > Mage-OS AI > AI Token Usage: the dashboard and a grid of individual calls. Needs the Mage-OS AI Usage role resource.
bin/magento mageos:ai:usage: the same numbers on the command line.
Troubleshooting
- A provider is missing from the Add Service list. In production mode the form only offers
providers whose Symfony AI bridge is installed. Switch to developer mode to see the package name,
or
composer requireit (for examplesymfony/ai-ollama-platform) and deploy as usual. - Test Connection or Refresh Models is missing on a row. The row isn't saved yet. Save the configuration first.
- The saved API key is gone. Changing a row's Base URL or Endpoint drops its key in the same save, so a key can't be sent to another host. Enter the key again.
- The form is read-only. The services are set in
app/etc/env.phporconfig.php, which wins over the admin. Change them there. - Test Connection fails with an unclear message. The full error is written to the Magento log.
- A module's calls don't show up in the usage report. Check that Enable Usage Tracking is on. A module that talks to the Symfony AI platform directly instead of through this module's client can't be tracked.
Usage
use MageOS\AiBase\Api\AiClientFactoryInterface; class ProductSummary { public function __construct( private readonly AiClientFactoryInterface $aiClientFactory, ) { } public function summarize(string $description): string { return $this->aiClientFactory ->create(consumer: 'Vendor_ProductSummary') ->complete('Summarize this product description: ' . $description); } }
chat() and streamChat() cover conversations, tools and streaming. The
Consumer Guide has the full picture.
Documentation
- Consumer Guide: make AI calls, handle failures, let the admin pick a service, what's stable
- Provider Guide: add a provider, wire a client bridge, the admin form
- Usage Tracking: what is recorded, where to see it, retention
- Architecture: components, data flows, security model, design decisions
Contributing
See CONTRIBUTING.md and our Code of Conduct.
Security
Please report vulnerabilities privately, as described in SECURITY.md, not in a public issue.

