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
| Type | Service | Notes |
|---|---|---|
Anthropic | Claude (Messages API) | Official Anthropic SDK. Default model claude-opus-5-5. |
OpenAI | OpenAI Chat Completions | Official OpenAI SDK. With BaseUrl it works with any OpenAI-compatible API: Azure OpenAI, OpenRouter, Groq, DeepSeek, a local Ollama. |
Gemini | Google 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.
Worker Configuration
{
"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"
}
}
}
}
| Property | Description |
|---|---|
Type | Anthropic, OpenAI or Gemini |
ApiKey | The provider's API key. Set it through an environment variable such as AiConfig__Providers__Claude__ApiKey, not in the file. |
BaseUrl | Optional endpoint override (proxy, OpenAI-compatible service, local model) |
DefaultModel | Model used when the job does not name one |
Models | More models to offer in the job form. DefaultModel is offered too. |
TimeoutSeconds | Request 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
}
| Property | Default | Description |
|---|---|---|
configName | DefaultConfigName | Provider configuration to use |
model | provider's DefaultModel | Model name. Pick it from the list in the job form or type another. |
systemPrompt | Instructions. Supports {{variable}} placeholders. | |
prompt | required | The prompt. Supports {{variable}} placeholders. |
variables | Values for the placeholders. Text is inserted as is, objects and arrays as JSON. | |
responseFormat | Text | Text, or Json to get a JSON object back, parsed |
maxTokens | 4096 | Maximum output tokens |
temperature | Sampling temperature (OpenAI and Gemini; current Claude models do not take it) | |
effort | low, medium, high (Claude also xhigh, max). Claude's effort level, OpenAI's reasoning effort. | |
apiKey | Overrides 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
Data mappings pass values between steps. 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 map the earlier step's output into variables:
Step 1 (HTTP: fetch yesterday's orders) → result: { "body": "[...]" }
Step 2 (AI) job data: { "prompt": "Summarize these orders for the sales team:\n{{orders}}" }
Mapping on Step 2:
step1Id:body → variables.orders
Feed the answer into the next step. Map Text, or a field of Json:
Step 2 (AI, responseFormat Json) → result: { "Json": { "subject": "...", "body": "..." } }
Step 3 (Email)
Mapping on Step 3:
step2Id:json.subject → subject
step2Id:json.body → body
Retries and Errors
| Situation | Behavior |
|---|---|
| Rate limit (429), timeout, server error (5xx), network error | Retried with the consumer's retry settings |
| Invalid request, wrong key, unknown model (4xx) | Fails at once, no retry |
| The model declines the request | Fails at once, no retry |
Json requested but the answer is not JSON | Retried; 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.