Skip to main content
Version: 2.0

AI Worker

The AI Worker sends a prompt to an AI model and stores the answer as the job's result. Use it to run AI tasks on a schedule ("summarize yesterday's errors every morning") or as a step in a workflow, where the answer feeds the next step: an HTTP call, an email, a SQL insert or another prompt.

Providers​

TypeServiceNotes
AnthropicClaude (Messages API)Official Anthropic SDK. Default model claude-opus-5-5.
OpenAIOpenAI Chat CompletionsOfficial OpenAI SDK. With BaseUrl it works with any OpenAI-compatible API: Azure OpenAI, OpenRouter, Groq, DeepSeek, a local Ollama.
GeminiGoogle Gemini (Generative Language API)REST generateContent.

You can configure several providers, and several accounts of the same provider, each under its own name. A job picks one by name.

AI Connections​

The Settings → AI connections page of the dashboard keeps the providers of a project. Jobs use a connection by name, and the worker needs no provider settings of its own.

  1. Put the provider's key on the Settings → Secrets page.
  2. Create a connection: name, provider (Anthropic, OpenAI, OpenAICompatible or Gemini), default model and the name of that secret. An OpenAICompatible connection needs a base URL and may have no key.
  3. Name it in the job data: "connection": "claude".
  • Per project. Only jobs of the project the connection was created in can use it. The name cannot change after creation.
  • The key stays a secret. The connection holds the name of the secret. The key is read when the job is sent to the worker, goes into that message only, and is never in the stored job data, the logs or an API response.
  • Test sends one short prompt to the provider, which may charge for it. Nothing else on the page calls the provider.
  • Disabled connections are refused: a job that names one fails before it is sent.
  • Fallback. When the project has no connection with that name, the worker uses its own AiConfig:Providers entry of that name, and fails the job when it has none. connection wins over configName.
  • Permissions: AiConnectionManagement.List, .Create, .Update (also needed to test a saved connection) and .Delete. A connection sends a secret to its provider or base URL, so creating one, or changing its provider, base URL or secret, also needs SecretManagement.Update. Without it the other fields can still be changed and the page hides those three. Only saved connections can be tested.
  • Addresses. Calls the API makes itself (tests, analyses, summaries, the assistant, evaluations and agents) do not contact link-local addresses, where cloud metadata services live, and do not follow redirects. They do not contact loopback and private addresses either. For an Ollama or vLLM server in your network, a super admin ticks Allow a private address on that connection; a change of its provider or base URL by anyone else turns it off again. MilvaionConfig__Ai__AllowPrivateAddresses=true allows private addresses for every connection. The system proxy is used only for connections that may use a private address. An answer larger than MilvaionConfig__Ai__MaxAnswerBytes (64 MB) is stopped while it is received. The AI worker connects as before.

Only the job named AiPromptJob is given connection settings. Connections work with AI Worker 2.0.0 and later; earlier versions ignore connection and use their default configuration, so update the worker first.

Usage and Cost​

Milvaion records every answered call: the AI worker's results and the calls the API makes itself (connection tests, failure analyses, summaries and the assistant). A record holds the connection, model, token counts, the job execution or workflow run it belongs to, and the prices the cost was computed with.

  • Prices come from the connection at the time of the call. Changing a price later does not change earlier records.
  • Unknown is not zero. Without both prices, without token counts from the provider, or with the worker's own AiConfig, the cost is unknown. Unknown costs are counted separately and never added as zero.
  • Prices and costs have no currency. Use one currency for all connections.
  • Unbelievable token counts (negative, or a trillion and more) are stored as unknown.
  • Not recorded: a call that failed, and an answer the worker threw away (for example because it was not the JSON that was asked for). The provider may still charge for these.

The AI Usage page shows calls, tokens and cost of the current project: in total, by connection, by workflow and for the 50 latest workflow runs. The API is GET /aiusage/summary with from, to, workflowId and workflowRunId. Usage needs the AiBudgetManagement.List permission.

Budgets​

A budget limits what the AI calls of a project, or of one of its workflows, cost per day or month (calendar periods in UTC). Budgets are managed under Settings → AI budgets, which also shows what each has spent in its current period. One alert (AiBudgetReached) is sent per period when the limit is reached.

ActionEffect
WarnThe alert only.
StopNew calls are refused: an AI job fails before it is sent to a worker, and the API makes no call.
  • The limit can be exceeded. The check happens before a call is sent, against the calls recorded so far. Calls that are already queued or running, and the worker's own retries of them, are not known yet and go on.
  • A stop budget needs prices. A call whose cost could not be known afterwards (a connection without both prices, or the worker's own AiConfig) is refused, because counting it as zero would let it past the limit.
  • Calls without token counts still count. When the API made the call and the provider reported no tokens, or the answer was stopped, an estimate on the high side counts for budgets: about three characters a token, and every allowed output token for a stopped answer. The cost shown stays unknown.
  • A project budget covers the calls of every workflow in it.
  • Permissions: AiBudgetManagement.List (also shows usage), .Create, .Update and .Delete.

Failure Analysis​

The page of a failed or timed out execution has an Analyze with AI button. It first shows, word for word, what would be sent; nothing leaves Milvaion until you pick a connection and press Send. If the data changes in between, you are asked to review it again.

  • What is sent: the execution's status and times, its exception, job data and result, and its last 200 log messages. Long parts are cut.
  • Secrets are masked before anything is shown or sent: the values of every secret of the project and of the secrets the job data refers to are replaced by their names. Values that were never stored as a secret, old values of a secret that was changed or deleted since, and secrets shorter than the mask's minimum length, cannot be recognised. Read the preview.
  • Logs, results and job data are not trusted. They go in as marked data that the model is told not to follow, the call has no tools, and the answer is shown as plain text. An answer can still be wrong or influenced by what a job wrote; check it against the logs.
  • The call counts as usage and is subject to budgets. It is in the activity log. The answer is not stored.
  • Permissions: AiAssistantManagement.Use and ScheduledJobManagement.Detail.

Summaries​

The Logs page and every report have a Summarize with AI button. It works like failure analysis: it shows word for word what would be sent, you pick a connection and press Send, secrets are masked, the data is marked as untrusted, the call has no tools and the answer is plain text.

  • Logs: counts over the last 24 hours and the latest 200 lines, with the filters of the page.
  • Reports: the values of the selected report.
  • Permissions: AiAssistantManagement.Use and ScheduledJobManagement.Detail.

Worker Configuration​

The worker's own providers are the fallback for jobs without a connection.

{
"AiConfig": {
"DefaultConfigName": "Claude",
"Providers": {
"Claude": {
"Type": "Anthropic",
"ApiKey": "",
"DefaultModel": "claude-opus-5-5",
"Models": ["claude-sonnet-5-5", "claude-haiku-5-5"],
"TimeoutSeconds": 300
},
"OpenAI": {
"Type": "OpenAI",
"ApiKey": "",
"DefaultModel": "gpt-5",
"Models": ["gpt-5-mini"]
},
"Gemini": {
"Type": "Gemini",
"ApiKey": "",
"DefaultModel": "gemini-2.5-flash"
},
"LocalLlama": {
"Type": "OpenAI",
"BaseUrl": "http://ollama:11434/v1",
"DefaultModel": "llama3.1"
}
}
}
}
PropertyDescription
TypeAnthropic, OpenAI, OpenAICompatible or Gemini
ApiKeyThe provider's API key. Set it through an environment variable such as AiConfig__Providers__Claude__ApiKey, not in the file.
BaseUrlOptional endpoint override (proxy, OpenAI-compatible service, local model)
DefaultModelModel used when the job does not name one
ModelsMore models to offer in the job form. DefaultModel is offered too.
TimeoutSecondsRequest timeout, default 300

Choosing the Model in the Dashboard​

When you create or edit a job for AiPromptJob, the job form shows drop-downs above the job data JSON: configName lists the provider configurations and model lists every configuration's DefaultModel and Models. Picking a value writes it into the JSON; you can still type any other model name into the JSON by hand.

You only need to pick the model. With configName left empty, the job runs on the configuration that lists that model, with that configuration's key. If you set both and the model is listed under a different configuration, the job fails with a message that names the right one, instead of sending, say, a GPT model to the Claude API.

To change the list, edit Models in the worker configuration and restart the worker.

Job Data Schema​

{
"configName": "Claude",
"model": "claude-opus-5-5",
"systemPrompt": "You are a release-notes writer. Write for end users, not developers.",
"prompt": "Write release notes from these commits:\n{{commits}}",
"variables": { "commits": "fix: login timeout\nfeat: dark mode" },
"responseFormat": "Text",
"maxTokens": 4096
}
PropertyDefaultDescription
connectionAI connection of the project, or a provider configuration of that name on the worker
configNameDefaultConfigNameProvider configuration to use
modelprovider's DefaultModelModel name. Pick it from the list in the job form or type another.
systemPromptInstructions. Supports {{variable}} placeholders.
promptrequiredThe prompt. Supports {{variable}} placeholders.
variablesValues for the placeholders. Text is inserted as is, objects and arrays as JSON.
responseFormatTextText, or Json to get a JSON object back, parsed
maxTokens4096Maximum output tokens
temperatureSampling temperature (OpenAI and Gemini; current Claude models do not take it)
effortlow, medium, high (Claude also xhigh, max). Claude's effort level, OpenAI's reasoning effort.
apiKeyOverrides the configured key. Use a secret reference like {{secret:openai-key}}, never a plain key; the dashboard's Secrets page is the easiest place to keep it.

A placeholder without a value stays in the prompt as written, so a typo is visible in the answer rather than silently empty.

Result​

{
"Text": "## What's new\n- Dark mode ...",
"Json": null,
"Provider": "Anthropic",
"ConfigName": "Claude",
"Model": "claude-opus-5-5",
"StopReason": "end",
"InputTokens": 412,
"OutputTokens": 233,
"DurationMs": 5120
}

With responseFormat: "Json" the worker asks the model for a single JSON object and puts the parsed object in Json. If the answer is not valid JSON the job fails and retries. StopReason is max_tokens when the answer was cut off; the worker logs a warning when that happens.

Using It in a Workflow​

A step's input is merged into the job's data, and expressions in it read earlier steps' results (see Workflows). Two patterns cover most cases.

Feed an earlier step's output into the prompt. Keep the prompt in the AI job's data with a placeholder, and fill variables from the earlier step:

Step fetch (HTTP: fetch yesterday's orders) → result: { "body": "[...]" }
Step summarize (AI) job data: { "prompt": "Summarize these orders for the sales team:\n{{orders}}" }

Input of summarize:
{ "variables": { "orders": "{{ steps.fetch.result.body }}" } }

Feed the answer into the next step. Read Text, or a field of Json:

Step summarize (AI, responseFormat Json) → result: { "Json": { "subject": "...", "body": "..." } }
Step mail (Email)

Input of mail:
{ "subject": "{{ steps.summarize.result.Json.subject }}", "body": "{{ steps.summarize.result.Json.body }}" }

Retries and Errors​

SituationBehavior
Rate limit (429), timeout, server error (5xx), network errorRetried with the consumer's retry settings
Invalid request, wrong key, unknown model (4xx)Fails at once, no retry
The model declines the requestFails at once, no retry
Json requested but the answer is not JSONRetried; fails at once if the answer was cut off at maxTokens

Every call costs money at the provider. Keep MaxRetries low on the AiPromptJob consumer and set maxTokens to what the task needs.

Deployment​

Docker image: milvasoft/milvaion-ai-worker. In the Helm chart, enable workers.ai and pass each key from a Secret:

workers:
ai:
enabled: true
extraEnv:
- name: AiConfig__Providers__Claude__Type
value: Anthropic
- name: AiConfig__Providers__Claude__ApiKey
valueFrom:
secretKeyRef:
name: ai-keys
key: anthropic
- name: AiConfig__DefaultConfigName
value: Claude

Prompts and answers go to the provider you configure. Do not send data there that your policies do not allow to leave your network; for that, point an OpenAI provider at a model you host yourself.