Codumentor logo Codumentor Enterprise

Media Generation Plugin

Lets users ask for images (and, in a later release, short videos) in chat: diagrams, mock-ups, illustrations. Codumentor orchestrates; the external tool generates. Codumentor turns the conversation into a prompt, calls the service the administrator chose, stores the result in the conversation's workspace and records who asked for what. It does not ship or host a generative model.

Output quality, content policy and the rights to the output belong to the selected provider and to your contract with it. Codumentor does not grant or change them. Every result is labelled with the provider and model that produced it.

Enterprise edition only. Load user_secrets (per-user keys) and workspace_files (result delivery) alongside it.

Status

This release generates and edits images: the generate_image and edit_image tools, the mask editor on the result card, the openai_images adapter (OpenAI Images API or a compatible gateway), technical-user keys and per-user keys (byo_key), the result card with its provenance label, audit records, per-user rate limits, provider probing with effective capabilities, budgets with media spend reported next to LLM spend, and the settings panel. Video follows in a later release.

With no providers configured, the plugin registers no tools and no UI.

Configuration

plugins:
  - module: codumentor.plugins.media_generation
    class: MediaGenerationPlugin
    args:
      providers:
        corp-images:                       # id shown to users and admins
          adapter: fake                    # registry key of the provider adapter
          mode: technical_user             # or byo_key
          api_key: ${env:IMAGES_API_KEY}   # a reference, never a pasted key
          base_url: https://gateway.corp.example/v1   # optional proxy / regional endpoint
          models: [fake-image-1]
          allow_operations: [image.generate, image.edit]   # narrows, never widens
          allowed_egress: [gateway.corp.example]
          limits: { per_user_per_hour: 20, max_count: 4 }
          pricing:                         # required per model when budgets are set
            currency: USD
            per_image: { fake-image-1: 0.04 }
            per_size: { fake-image-1: { 1024x1024: 0.08 } }   # optional overrides
          args: {}                         # adapter-specific options
      default_provider: { image: corp-images }
      probe_ttl_seconds: 600
      budgets:
        per_user_daily: { amount: 5.00, currency: USD }
        instance_monthly: { amount: 500.00, currency: USD }
      retention_days: 90
      store_prompts_in_audit: false
      target_agents: main
KeyDefaultMeaning
enabledtrueTurn the plugin off without removing its config.
providers{}Named provider entries. Empty means the plugin contributes nothing.
providers.<id>.adapterrequiredWhich adapter talks to the service. Available: openai_images, fake.
providers.<id>.modetechnical_usertechnical_user: one operator key shared by every user. byo_key: each user's own key only (see Keys); api_key is never used for it.
providers.<id>.api_keynone${env:VAR}.
providers.<id>.modelsrequiredModels users may select (at least one).
providers.<id>.allow_operationsall the adapter declaresAny of image.generate, image.edit, image.variation, video.generate, video.from_image.
providers.<id>.allowed_egress[]Hosts besides base_url the adapter may download results from.
providers.<id>.limitsnoneper_user_per_hour, per_provider_per_hour, max_count, max_video_seconds.
providers.<id>.pricingnonePrice table: currency, per_image (model to price per image), optional per_size (model to size to price). The cost when the provider reports none. Required for every model when budgets are set, and its currency must match theirs.
default_providernoneProvider id per media kind (image, video); must name a configured provider.
budgetsnoneper_user_daily and instance_monthly spending caps (amount, currency; both in one currency).
probe_ttl_seconds600How long a provider probe is trusted before it is re-run (min 10).
retention_daysunsetReserved; the plugin does not run an output-retention sweep. Files follow workspace retention (by default, 30 days of workspace inactivity for isolated workspaces with .workspace_meta).
store_prompts_in_auditfalseAudit records carry a prompt hash; set true to store the full prompt.
inputs{max_bytes: 20000000, max_pixels: 40000000}Caps on an edit's source image and mask: file size in bytes (min 1024) and width × height.
output_dirmediaWorkspace folder generated files are written to (relative, no ..).
target_agentsmainWhich agents get the generation tools. An unrecognized value falls back to main.

Unknown keys are rejected, including inside a provider entry and its args.

Keys

Keys are referenced, never pasted into YAML: ${env:...} for a technical-user key. Keys never appear in prompts, tool results, logs, audit records or probe output.

Per-user keys (byo_key). Load User Secrets. Each user sets their own key in the plugin's settings under "Your API keys" (one row per byo_key provider: key set or not, a password field, Test, Clear). It is stored encrypted for that user under media_generation/<provider id>/api_key and never shown again. A byo_key provider runs on that key only: without one, the provider offers that user nothing (the agent gets no tool for it, and a call says where to set a key), and the operator api_key is never used. Test probes with the user's key; the result is kept for that user only and decides their effective capabilities. If the provider rejects the key, the user is told to update it in "Your API keys", and the provider offers them nothing until the key changes. Admins cannot probe a byo_key provider (it has no shared key).

What leaves the instance

The prompt, any source images and the requested parameters go to the provider at base_url. Point base_url at a regional or self-hosted endpoint to keep data in a region.

AdapterSent to base_urlDownloaded fromNot sent
openai_imagesprompt, model, size, count, quality / output_format if set; for an edit the source image and mask (metadata stripped, see Editing); the key in the Authorization headerresult URLs, only from the base_url host or an allowed_egress hostconversation history, workspace files, user identity
fakenothing (runs in-process)nothingeverything

The OpenAI Images API has no per-request "do not train" or retention option. Data controls are set on the OpenAI organisation or in your gateway's contract.

Probes and status

Each provider is probed (a cheap authenticated call, for openai_images GET <base_url>/models) at startup in the background, after a config reload that changes it, from the settings panel's Test button, and when the last result is older than probe_ttl_seconds. A provider's status is:

StatusMeaning
okThe last probe succeeded; its operations are offered.
degradedThe probe failed (service down, quota, none of the configured models offered by the key, ...). Nothing is offered until a probe succeeds.
unauthenticatedNo usable key, or the service rejected it. Nothing is offered.
pendingNot probed yet (the first request waits for the probe).

What a user is offered is one computation, the effective capabilities: what the adapter declares for the model, narrowed by allow_operations and limits.max_count, by the last probe (status and the models the key offers), and by the user's permissions. It decides whether the agent gets generate_image on that user's turn and what the settings panel and GET /ui/plugins/media_generation/capabilities show. If a provider answers a call with "unsupported", that operation is dropped from its capabilities until an admin presses Test. Probe errors are redacted and shown to admins only; keys never appear.

Budgets and spend

With budgets set, each request reserves its estimated cost before the provider is called. The estimate uses the price table, after count and size have been bounded. A request that would exceed the user's daily or the instance's monthly budget is refused with a plain-text message, and the provider is not called. After the call the reservation is settled with the provider-reported cost when the provider reports one in the budget currency (the OpenAI Images API does not), otherwise with the estimate. A failed call releases it, and a reservation never settled (a crashed worker) stops counting after 15 minutes. A settle that fails is retried once; if it fails again the reservation keeps counting at its estimate and the server log records an error. If the images are generated but cannot be saved to the workspace, the spend stays counted and reported, and the request is audited as media.failed with kind storage. Days and months are UTC.

The ledger is a SQLite file in the plugin data directory (media_generation.sqlite3, WAL), shared by every worker process. If it cannot be read or written, generation is refused (fail closed). Settled USD spend is reported like any tool usage: it counts toward the conversation's cost, the run's ledger and Provider Usage, under provider media_generation:<provider id> with provenance provider_reported_charge or estimate. Usage reporting is USD only: media costs in another currency are budgeted (and shown in the settings panel) but do not appear in Provider Usage or the conversation's cost.

Settings panel

The plugin's settings show one row per provider with its status, effective operations and model, and the budget use (your day; for admins also the instance's month and each provider's share). Admins (admin:config) also see probe errors and a Test button that re-probes the provider. Below them, "Your API keys" lists the byo_key providers for the caller's own key. The same data is served under /ui/plugins/media_generation/: GET capabilities (with byo, the caller's key rows, and default_provider.edit, the provider an edit uses for the caller), POST probe/{provider id} (admin), PUT / DELETE byo/{provider id}/key and POST byo/{provider id}/test (any signed-in user, always on their own key; responses never carry it), POST edit-mask (uploads the painted mask, below) and GET budget.

Using it

The agent gets generate_image(prompt, size?, count?, provider?) on a user's turn when image.generate is effective for that user on some provider (see Probes and status).

Editing images

The agent gets edit_image(prompt, source, mask?, size?, count?, provider?) on a user's turn when image.edit is effective for that user on some provider and they have media_generation:edit. source and mask are workspace paths.

The openai_images adapter

      providers:
        corp-images:
          adapter: openai_images
          api_key: ${env:OPENAI_IMAGES_API_KEY}
          base_url: https://api.openai.com/v1        # default; or your gateway
          models: [gpt-image-1]                    # or dall-e-3, dall-e-2
          allowed_egress: []                       # extra hosts result URLs may use
          limits: { per_user_per_hour: 20 }
          args: { quality: high, timeout_s: 120 }

Calls POST <base_url>/images/generations, and for an edit POST <base_url>/images/edits (multipart: the source as image[] for gpt-image models, image for DALL·E 2, and the optional mask). Probe: GET <base_url>/models. Results come back as base64 or as a URL. A URL is downloaded server-side, only over https (http only when base_url is http) and only from the base_url host or an allowed_egress host, without following redirects. The key is sent only when scheme, host and port all match base_url; allowed_egress hosts never get it. A URL on any other host fails with an error naming it. Error messages are redacted (keys, key-shaped strings, data URLs) before they reach logs, audit or chat.

ArgDefaultMeaning
timeout_s120Per-request timeout (max 600).
sizesper modelOverride the offered sizes (e.g. for a gateway model).
qualitynoneSent as quality (low/medium/high, or hd for DALL·E 3).
output_formatpnggpt-image models: png, jpeg or webp.
max_download_bytes50 MiBCap on one downloaded result.

image.generate on every model; image.edit with mask on gpt-image models and DALL·E 2, not on DALL·E 3.

The fake provider

A deterministic provider for tests and demos. It returns solid-colour PNGs (same request, same image) and supports image.generate and image.edit. Its args:

ArgDefaultMeaning
operations[image.generate, image.edit]Declared operations; drop image.edit to see the no-edit behaviour.
models[fake-image-1]Accepted models.
sizes[256x256, 512x512, 1024x1024]Accepted sizes.
max_count4Images per request.
supports_masktrueWhether image.edit takes a mask; false shows the mask refusal.
fail_withnoneMake every call fail with this error kind (auth, quota, rate_limited, content_policy, invalid_request, unavailable, timeout, unsupported).
fail_probetrueWhether fail_with also fails the probe; false makes only calls fail.
retry_afternoneSeconds reported with a rate_limited failure.
cost_per_image / currency0.0 / USDReported cost.
report_costtruefalse reports no cost, like an API without prices (the price table applies).

See also