Hermes Microsoft Foundry MAI Image Plugin
Standalone Hermes Agent image-generation backend for Microsoft Foundry MAI image models.
Quick Start
1. Get your Microsoft Foundry values
From the Foundry resource's Keys and Endpoint page, collect:
-
An API key.
-
The resource endpoint, for example:
https://your-resource.services.ai.azure.com
-
The deployment name assigned to your MAI image model.
Use the resource root as the endpoint; the plugin appends /mai/v1 itself. The endpoint is normalized to https://host[:port]: a pasted /mai/v1, /models, /openai/v1, /api/projects/<name> suffix, query string or trailing slash is stripped (logged at debug level), and a bare host such as your-resource.services.ai.azure.com gets https:// prepended. A non-https endpoint is rejected with an invalid_config error and no request is sent. The deployment name is the value sent as the API model field and may differ from the catalog model name.
2. Install the plugin into Hermes
Two paths install the same plugin. Prefer the catalog install; fall back to the Git install when you want the moving branch.
Catalog install (recommended). Once this plugin is listed in the Hermes plugin catalog:
hermes plugins install mai-image
The catalog entry pins an exact 40-character commit SHA that has been validated and reviewed for the catalog. Installs clone the repository and check out precisely that commit, so a catalog install is reproducible and does not move until you run hermes plugins update mai-image (which adopts a newly reviewed pin). Use this path for a stable, vetted plugin.
Git install (tracks the branch). To run the current development code instead of a pinned release:
/usr/local/lib/hermes-agent/venv/bin/pip install --upgrade \\
"git+https://github.com/joescars/hermes-mai-image.git"
The Git install tracks the branch, so --upgrade picks up the newest commits. A catalog install is pinned and validated; a Git install is live and unreviewed. Use the catalog install unless you specifically want unreleased changes.
Verify the package is visible either way:
hermes plugins list
3. Enable the plugin and image generation
hermes plugins enable azure-mai-image
hermes tools enable image_gen
Verify:
hermes plugins list
hermes tools list
You should see azure-mai-image enabled and:
✓ enabled image_gen 🎨 Image Generation
4. Restart Hermes processes
Plugins load when a Hermes process starts. No operating-system reboot is needed, but restart long-running processes after installation or updates:
hermes gateway restart
hermes dashboard --stop
hermes dashboard
5. Configure from the CLI
Run the interactive tool setup:
hermes tools
Choose Image Generation → Microsoft Foundry MAI, then enter the API key, endpoint, and deployment/model when prompted.
6. Configure from the Hermes Web UI
- Run
hermes dashboardand authenticate. - Open Tools → Image Generation.
- Select Microsoft Foundry MAI.
- Enter the API key and resource endpoint.
- Save the provider.
- Select the MAI deployment/model if the model picker is shown.
The Web UI uses the provider's setup schema and saves credentials in the active profile's .env. It supports these fields:
MAI_FOUNDRY_API_KEY
MAI_FOUNDRY_ENDPOINT
Credential handling. The plugin reads MAI_FOUNDRY_API_KEY and MAI_FOUNDRY_ENDPOINT through Hermes secret scope for the active profile — the values are resolved in the context of the profile that is running, so a second profile cannot pick them up accidentally. The values live in the active profile's .env under $HERMES_HOME/profiles/<profile>/.env (the default profile's .env sits at $HERMES_HOME/.env). The API key is sent to your Foundry resource in the api-key header on each request and is never logged, never written by the plugin anywhere else, and never included in image metadata.
Never put API keys in config.yaml, chat messages, or Git. Only MAI_FOUNDRY_API_KEY is a secret: inside Hermes it is read solely from the active profile's secret scope (a same-named process environment variable is ignored); outside Hermes it falls back to the environment. The endpoint, model and discovery path are non-secret and can instead be set in config.yaml under image_gen.azure-mai as endpoint, model and models_path (config wins over the MAI_FOUNDRY_ENDPOINT, MAI_IMAGE_MODEL, MAI_FOUNDRY_MODELS_PATH env vars; MAI_IMAGE_MODEL and MAI_FOUNDRY_MODELS_PATH are optional). config.yaml holds only non-secret model selection, not credentials.
If the provider does not appear, restart the dashboard after installing the package. A browser refresh alone does not reload Python plugins.
Updating Hermes later
Hermes updates do not normally change this GitHub-installed plugin or its configuration. The API key, endpoint, deployment selection, and plugin-enabled state are stored separately in the active Hermes profile.
After a normal Hermes update, verify the plugin:
hermes plugins list
If azure-mai-image is still listed as enabled, restart Hermes processes:
hermes gateway restart
hermes dashboard --stop
hermes dashboard
If the Hermes update recreated or replaced its Python virtual environment, reinstall the plugin into the new Hermes environment:
/usr/local/lib/hermes-agent/venv/bin/pip install --upgrade \\
"git+https://github.com/joescars/hermes-mai-image.git"
Then enable it again if necessary and restart Hermes:
hermes plugins enable azure-mai-image
hermes gateway restart
You do not need to re-enter the API key unless the active Hermes profile changed or its .env was intentionally reset.
7. Set the deployment explicitly when needed
For most Foundry deployments, set the exact deployment name in the active Hermes profile's .env:
MAI_FOUNDRY_API_KEY=your-foundry-key
MAI_FOUNDRY_ENDPOINT=https://your-resource.services.ai.azure.com
MAI_IMAGE_MODEL=your-deployment-name
Never put API keys in config.yaml, chat messages, or Git. Only MAI_FOUNDRY_API_KEY is a secret: inside Hermes it is read solely from the active profile's secret scope (a same-named process environment variable is ignored); outside Hermes it falls back to the environment. The endpoint, model and discovery path are non-secret and can instead be set in config.yaml under image_gen.azure-mai as endpoint, model and models_path (config wins over the MAI_FOUNDRY_ENDPOINT, MAI_IMAGE_MODEL, MAI_FOUNDRY_MODELS_PATH env vars; MAI_IMAGE_MODEL and MAI_FOUNDRY_MODELS_PATH are optional). MAI_IMAGE_MODEL defaults to MAI-Image-2.5 if omitted, but the exact deployment name is recommended.
8. Test generation
hermes chat -q "Generate an image of a red fox sitting in a snowy forest at sunrise."
Generated images are saved under $HERMES_HOME/cache/images/.
9. Test editing
Provide a local PNG or JPEG path in the prompt:
hermes chat -q "Edit /absolute/path/to/source.png: turn the scene into a nighttime scene with moonlight."
The edit request uses MAI's /mai/v1/images/edits multipart endpoint.
Features
- API-key authentication with the Foundry
api-keyheader - Live model discovery through the resource
/modelsendpoint, with a documented MAI fallback catalog - Text-to-image generation through
/mai/v1/images/generations - Image-to-image editing through
/mai/v1/images/edits - Landscape, square, and portrait dimensions
- Stable local output files under
$HERMES_HOME/cache/images/ - Installable from the Hermes plugin catalog (pinned SHA) or directly from GitHub
Model discovery
The model sent to MAI is your Foundry deployment name, not necessarily a base model name. Picking MAI-Image-2.6 works only if your deployment is literally named MAI-Image-2.6; otherwise MAI returns 404.
Discovery is best-effort and unverified. The provider calls GET {endpoint}/models with the api-key header and reads a data (or models) array. Microsoft's MAI documentation lists deployments only through the Azure management plane, and we could not confirm that /models returns MAI deployments on a real resource, so in practice you will usually see the fallback list. Discovered entries that do not look like image models are labelled (unverified: may not be an image model).
What the picker shows:
- Your configured deployment (explicit model,
image_gen.azure-mai.model,MAI_IMAGE_MODEL, orimage_gen.model) is always listed first, labelled(configured deployment), and de-duplicated against the rest. - Discovered entries, if any; otherwise the built-in fallback catalog, labelled
(model name — must match your deployment name):
MAI-Image-2.6-Flash
MAI-Image-2.6
MAI-Image-2.5-Pro
MAI-Image-2.5-Flash
MAI-Image-2.5
Labels appear only in the display/description columns; the id saved to config and sent to the API is always the bare name.
List your real deployment names with the Azure CLI:
az cognitiveservices account deployment list \
--name <resource-name> --resource-group <resource-group> \
--query "[].name" -o tsv
Set one of those as the model (MAI_IMAGE_MODEL or image_gen.azure-mai.model) if it differs from the fallback names.
Overriding the discovery path. Set MAI_FOUNDRY_MODELS_PATH to point discovery at a different route on the same resource. A value without a leading / is normalised by adding one:
MAI_FOUNDRY_MODELS_PATH=/models
The model actually sent to MAI is resolved in this order: an explicit per-request model, then image_gen.azure-mai.model in config.yaml, then MAI_IMAGE_MODEL from the environment, then image_gen.model, then the MAI-Image-2.5 default. The picker list does not change which deployment name is sent unless you pick one.
API behavior
MAI generation uses:
POST {endpoint}/mai/v1/images/generations
api-key: ...
{"model": "<deployment>", "prompt": "...", "width": 1248, "height": 832}
MAI editing uses multipart form data:
POST {endpoint}/mai/v1/images/edits
api-key: ...
model=<deployment>
prompt=<prompt>
image=<file>
The plugin accepts a local file path or HTTP(S) URL as image_url/reference_image_urls. Up to five source images (JPEG/PNG) are supported for edits and are sent as repeated multipart image fields in the order given (image_url first, then reference_image_urls); more than five are rejected with a too_many_references error before any request is sent. Each source passes the same safety, format and size checks, and the combined upload is capped at 250 MB. Generated images remain in Hermes' $HERMES_HOME/cache/images/. Successful results expose the WebUI-facing file:// URI in image and retain the absolute cached path in host_image for Hermes media delivery.
Retry behavior
- HTTP 429 is always retried, waiting for
Retry-After(seconds or HTTP-date, capped at 120s). Without the header the wait is about 10s, then 30s, plus jitter, because MAI quotas can be as low as 2 requests per minute. - Among 5xx errors only 502 and 503 are retried. 500 and 504 are never retried, since they do not prove a paid generation did not run and a retry could bill twice.
- At most 3 attempts are made, all within an overall deadline set by
MAI_REQUEST_DEADLINE(seconds, default 600; alsoimage_gen.azure-mai.request_deadlinein config.yaml). The plugin never sleeps past the deadline, and each request timeout is shortened to the remaining budget. - Connection errors and timeouts are not retried.
Disclosure
This section is the plugin's catalog rule 13 disclosure — what the plugin does that you should know before installing it.
- Network destination. Your prompt, the optional source image (for edits), and your
MAI_FOUNDRY_API_KEYare sent over https to your own Microsoft Azure AI Foundry resource — the endpoint you configure inMAI_FOUNDRY_ENDPOINT. The plugin talks to no other host. The API key travels only in theapi-keyheader on requests to that resource. - Web grounding (opt-in). If you enable
web_grounding(MAI-Image-2.6 only, off by default), the model may derive search queries from your prompt and send them to Bing Search as part of the Foundry service. Leave it off if prompts must not leave your Foundry resource for web search. - Billing. Every generation and edit calls your Foundry deployment and bills your Azure subscription for that deployment. There is no Hermes approval prompt before spending — the plugin does not gate on cost and does not know MAI pricing. Your Azure quota and rate limits are the only backstop.
- Local writes. Returned images are downloaded and written into the Hermes image cache under
$HERMES_HOME/cache/images/. Nothing is written outside that cache and the plugin's own working directory. - No telemetry. The plugin reports no usage, analytics, or diagnostics anywhere.
- No shell commands. It never runs a subprocess or shell command.
- No background processes. It makes synchronous HTTP requests and starts no daemons, timers, or watchers.
- No self-updates. The plugin does not fetch or replace its own files. Catalog updates arrive only through a reviewed SHA-bump in the catalog plus
hermes plugins update mai-image. - No extra dependencies. The only runtime dependency is
requests(plus Hermes itself).
Compatibility
- Hermes floor:
requires_hermes: ">=0.21.6". The plugin uses image-gen provider APIs that require a Hermes at or above this version. - Where it is declared: in
plugin.yaml(requires_hermes) inside the package, and in the catalog entry (catalog/mai-image.yaml,requires_hermes), so both the loader and the catalog enforce the same floor. - Install behaviour: an install by catalog name refuses on an older Hermes, and
hermes plugins updatekeeps an installed copy at its current pin until Hermes is updated. - Python: 3.10 or newer (
requires-python = ">=3.10").
Security behaviour
Source images are the one place this plugin handles untrusted input. Remote references are fetched with requests behind an explicit SSRF policy rather than being handed to the HTTP client unexamined. Local file reads are additionally checked against Hermes' file-safety rules.
- Scheme allowlist. Only
httpssource references are fetched; anything else is refused. - Address checks. The host is resolved and every returned address must be public; loopback, private, link-local, reserved and multicast ranges are refused, and the cloud metadata address is blocked regardless of settings. When Hermes' own
tools.url_safetypolicy is importable it is used in preference to the built-in check. - Redirects are not followed. A redirecting source response raises instead of being followed, so a public URL cannot bounce into an internal address. Requests are sent with
allow_redirects=False, and any 3xx status or response with redirect history is refused. Known limitation: the address check resolves the host separately from the fetch, so a DNS-rebinding attacker who controls a hostname's DNS could in principle return a public address for the check and an internal one for the connection; connection-time IP pinning is not implemented. - Byte caps. A downloaded source image is capped at 50 MiB (
MAX_SOURCE_IMAGE_BYTES) enforced while streaming, so an oversized body is aborted rather than buffered; the same limit applies to local source files. - Content sniffing. The source is validated by magic bytes (PNG or JPEG) and the authoritative MIME type is taken from the file content, not from the file extension or a caller-supplied type. Non-images are rejected, and GIF and WebP sources are rejected before upload (
invalid_input) because MAI accepts only JPEG or PNG source images; convert them first. - Up to five reference images. MAI editing takes at most five JPEG/PNG source images. Six or more are rejected with a
too_many_referenceserror before any request is sent, and the total upload across sources is capped at 250 MB. - Width and height constraints. Generation uses fixed presets chosen from the resolved aspect ratio and the model family (width and height each ≥ 768; MAI-Image-2.5 family ≤ 1,048,576 pixels, MAI-Image-2.6 family ≤ 2,359,296). 2.5 (default): landscape
1248x832, square1024x1024, portrait832x1248. 2.6: landscape1824x1216, square1536x1536, portrait1216x1824. A deployment name containing2.6or2-6selects the 2.6 sizes; otherwise 2.5 sizes are used. For custom deployment names, setMAI_IMAGE_SIZE_PROFILE=2.6(or2.5) in the profile.env, orimage_gen.azure-mai.size_profileinconfig.yaml. There is no free-form width/height input. - MAI-Image-2.6 options.
auto_aspect_ratio(the model chooses the output aspect ratio) andweb_grounding(the model may use Bing Search results as context; see Disclosure) are off by default and sent only when enabled, on both generation and edits. Enable withimage_gen.azure-mai.auto_aspect_ratio: true/web_grounding: trueinconfig.yaml, orMAI_AUTO_ASPECT_RATIO=true/MAI_WEB_GROUNDING=truein the profile.env(truthy:1,true,yes,on). They are only supported by 2.6 deployments (2.5 returns 400): on other deployments the fields are skipped with a logged warning. For custom deployment names, setsize_profile/MAI_IMAGE_SIZE_PROFILEto2.6.
Development
python3 -m venv .venv
. .venv/bin/activate
pip install -e '.[test]'
pytest -q
The tests mock HTTP responses and never require an Azure key.
Validation
hermes plugins validate src/hermes_mai_image passes. It reports one warning, which is understood and accepted:
⚠ private core imports (catalog rule 9: public surfaces only; these can break on
any release): provider.py:45 agent.file_safety.raise_if_read_blocked
Why it is accepted. raise_if_read_blocked is the shared chokepoint Hermes itself uses for local-path input loading; the same import appears in Hermes' own bundled providers (plugins/image_gen/{xai,openai,openai-codex,krea,openrouter} and plugins/video_gen/xai). It is what stops a local reference image from reading a credential store or a protected path, and there is no public equivalent for it. Dropping the import to silence the warning would remove that guard — a worse outcome than the warning.
The warning fires because agent.file_safety is not listed in hermes_cli/data/plugin_api.json, which is the allowlist the lint consults. A request to publish a public seam for this (and for image fetching, where no public download API exists at all) is filed upstream at NousResearch/hermes-agent#155704; if it lands, the import is replaced and the warning disappears.
The other private import originally flagged — tools.vision_tools._download_image — has been removed: the plugin now fetches source images itself behind the published tools.url_safety.is_safe_url policy. The redirect guard, byte cap and magic-byte sniffing are covered by tests, including a test asserting a redirect's Location is never dereferenced.
Microsoft documentation
Metadata
Release files for hermes-mai-image 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hermes_mai_image-0.2.1.tar.gz | 34.1 kB | With provenance | Details for hermes_mai_image-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hermes_mai_image-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for hermes_mai_image-0.2.1-py3-none-any.whl |
Total release size: 54.7 kB
Release files / hermes_mai_image-0.2.1.tar.gz
| Download URL | hermes_mai_image-0.2.1.tar.gz |
|---|---|
| Size | 34.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5c29bc3582765f2f305700360a0afc8c9f9168819b72871053bc268328f0c99f
|
|
BLAKE2b-256 checksum How to use checksums |
1694dccbaaac210b8344d96852a0701310a0c6c6568f41769714052586ad915c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.
Transparency logRelease files / hermes_mai_image-0.2.1-py3-none-any.whl
| Download URL | hermes_mai_image-0.2.1-py3-none-any.whl |
|---|---|
| Size | 20.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2c55b1b2f8626b4f4055ab9eb42cf71df2a2e8dd84d9b4df0a686b9f83d65156
|
|
BLAKE2b-256 checksum How to use checksums |
01674933a58888a6d6e27fc6e84de2829ba21c5098ad95154168c68e9e69615e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.
Transparency logSecurity for hermes-mai-image 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for hermes_mai_image-0.2.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.