Skip to content

Sends each input event to an OpenAI-compatible Responses API endpoint and adds the model response to the event.

ai::prompt model=string, [endpoint=string, system=string, data=any,
into=field, api_key=string, temperature=double,
max_tokens=uint, timeout=duration, concurrency=uint,
tls=record]

The ai::prompt operator evaluates one request per input event. By default, it serializes this as compact JSON and sends that string as the Responses API input field. Set data to use another expression instead. String values are also serialized as JSON strings before they are sent.

The operator uses http://127.0.0.1:11434/v1 as its default endpoint, which matches the standard Ollama OpenAI-compatible API port. The operator appends /responses to the endpoint and sends a POST request to the Responses API. It doesn’t use the Chat Completions API. For providers that support the Responses API store flag, the operator sets it to false.

The operator preserves input order, even when concurrency is greater than 1. If a request fails, Tenzir emits a warning, keeps the input event, and writes null to the result field for that event.

The result field is a record with the following structure:

{
text: string,
model: string | null,
usage: {
input_tokens: uint64 | null,
output_tokens: uint64 | null,
total_tokens: uint64 | null,
} | null,
latency: duration,
}

The text field contains the concatenated Responses API output_text content. The operator doesn’t parse JSON-looking text into structured data.

The model to use.

This argument is required.

The OpenAI-compatible base endpoint.

Defaults to http://127.0.0.1:11434/v1.

The endpoint is resolved as a secret, so you can pass a secret name to avoid hardcoding sensitive URLs.

Instructions to send as the Responses API instructions field.

The value to send as the request input after JSON serialization.

Defaults to this.

The field where Tenzir writes the result record.

Defaults to ai.prompt.

Bearer token to send in the Authorization header.

If you omit this argument, Tenzir sends no authorization header. This is useful for local Ollama endpoints.

The API key is resolved as a secret.

Sampling temperature to send with the request.

Defaults to 0.

Maximum number of output tokens to request.

HTTP request timeout.

Defaults to 30s.

Maximum number of in-flight requests.

Defaults to 1.

TLS options for the HTTP client.

Send each event to the default local Ollama endpoint:

from {message: "Summarize this security alert."}
ai::prompt model="qwen3"
select summary=ai.prompt.text

Send a smaller input record to an OpenAI endpoint:

from {
message: "User logged in from an unusual ASN.",
src_ip: 203.0.113.10,
}
ai::prompt model="gpt-4.1-mini",
endpoint="https://api.openai.com/v1",
api_key=secret("openai-api-key"),
system="Summarize the alert in one short sentence.",
data={message: message, src_ip: src_ip},
into=enrichment.ai
select summary=enrichment.ai.text,
tokens=enrichment.ai.usage.total_tokens

Last updated: