openai_chat_completion
Generates responses to messages in a chat conversation, using the OpenAI API and external tools.
Introduced in version 4.32.0.
-
Common
-
Advanced
processor:
label: ""
openai_chat_completion:
server_address: https://api.openai.com/v1
api_key: "" # No default (required)
model: "" # No default (required)
prompt: "" # No default (optional)
system_prompt: "" # No default (optional)
history: "" # No default (optional)
image: "" # No default (optional)
max_tokens: 0 # No default (optional)
temperature: 0 # No default (optional)
user: "" # No default (optional)
response_format: text
json_schema:
name: "" # No default (required)
schema: "" # No default (required)
tools: [] # No default (required)
processor:
label: ""
openai_chat_completion:
server_address: https://api.openai.com/v1
api_key: "" # No default (required)
model: "" # No default (required)
prompt: "" # No default (optional)
system_prompt: "" # No default (optional)
history: "" # No default (optional)
image: "" # No default (optional)
max_tokens: 0 # No default (optional)
temperature: 0 # No default (optional)
user: "" # No default (optional)
response_format: text
json_schema:
name: "" # No default (required)
description: "" # No default (optional)
schema: "" # No default (required)
schema_registry:
url: "" # No default (required)
name_prefix: schema_registry_id_
subject: "" # No default (required)
refresh_interval: "" # No default (optional)
tls:
skip_cert_verify: false
enable_renegotiation: false
root_cas: ""
root_cas_file: ""
client_certs: []
oauth:
enabled: false
consumer_key: ""
consumer_secret: ""
access_token: ""
access_token_secret: ""
basic_auth:
enabled: false
username: ""
password: ""
jwt:
enabled: false
private_key_file: ""
signing_method: ""
claims: {}
headers: {}
top_p: 0 # No default (optional)
frequency_penalty: 0 # No default (optional)
presence_penalty: 0 # No default (optional)
seed: 0 # No default (optional)
stop: [] # No default (optional)
tools: [] # No default (required)
This processor sends user prompts to the OpenAI API, and the specified large language model (LLM) generates responses using all available context, including supplementary data provided by external tools. By default, the processor submits the entire payload of each message as a string, unless you use the prompt configuration field to customize it.
To learn more about chat completion, see the OpenAI API documentation, and Examples.
Fields
api_key
The API secret key for OpenAI API.
|
This field contains sensitive information that usually shouldn’t be added to a configuration directly. For more information, see Secrets. |
Type: string
frequency_penalty
Specify a number between -2.0 and 2.0. Positive values penalize new tokens based on the frequency of their appearance in the text so far. This decreases the model’s likelihood to repeat the same line verbatim.
Requires version 4.34.0 or later.
Type: float
history
Include messages from a prior conversation. You must use a Bloblang query to create an array of objects in the form of [{"role": "user", "content": "<text>"}, {"role":"assistant", "content":"<text>"}] where:
-
roleis the sender of the original messages, eithersystem,user, orassistant. -
contentis the text of the original messages.
Requires version 4.51.0 or later.
Type: string
image
An optional image to submit along with the prompt. The result of the Bloblang mapping must be a byte array.
Requires version 4.38.0 or later.
Type: string
# Examples:
image: 'root = this.image.decode("base64") # decode base64 encoded image'
json_schema
The JSON schema used by the model when generating responses in json_schema format. To learn more about supported JSON schema features, see the OpenAI documentation.
Requires version 4.35.0 or later.
Type: object
json_schema.description
An optional description, which helps the model understand the schema’s purpose.
Type: string
max_tokens
The maximum number of tokens to generate for chat completion.
Requires version 4.34.0 or later.
Type: int
model
The name of the OpenAI model to use.
Type: string
# Examples:
model: gpt-4o
# ---
model: gpt-4o-mini
# ---
model: gpt-4
# ---
model: gpt4-turbo
presence_penalty
Specify a number between -2.0 and 2.0. Positive values penalize new tokens if they have appeared in the text so far. This increases the model’s likelihood to talk about new topics.
Requires version 4.34.0 or later.
Type: float
prompt
The user prompt you want to generate a response for. By default, the processor submits the entire payload of each message as a string.
This field supports interpolation functions.
Type: string
response_format
Specify the output format of the configured model.
If you choose the json_schema option, you must also configure a json_schema or schema_registry.
Requires version 4.35.0 or later.
Type: string
Default: text
Options: text, json, json_schema
schema_registry
The schema registry to dynamically load schemas for model responses in json_schema format. Schemas must be in JSON format. To learn more about supported JSON schema features, see the OpenAI documentation.
Requires version 4.35.0 or later.
Type: object
schema_registry.basic_auth
Configure basic authentication for requests from this component.
Type: object
schema_registry.basic_auth.enabled
Whether to use basic authentication in requests.
Type: bool
Default: false
schema_registry.basic_auth.password
The password to use for authentication. Used together with username for basic authentication.
|
This field contains sensitive information that usually shouldn’t be added to a configuration directly. For more information, see Secrets. |
Type: string
Default: ""
schema_registry.basic_auth.username
The username of the account credentials to authenticate as. Used together with password for basic authentication.
Type: string
Default: ""
schema_registry.jwt
Beta
Configure JSON Web Token (JWT) authentication. This feature is in beta and may change in future releases. JWTs provide secure, stateless authentication between services.
Type: object
schema_registry.jwt.claims
A map of claims to include in the JWT. Claims pass the identity of the authenticated entity to the service provider.
Type: object
Default: {}
schema_registry.jwt.enabled
Whether to use JWT authentication in requests.
Type: bool
Default: false
schema_registry.jwt.headers
Additional key-value pairs to include in the JWT header (optional). These headers provide extra metadata for JWT processing.
Type: object
Default: {}
schema_registry.jwt.private_key_file
Path to a file containing the PEM-encoded private key using PKCS#1 or PKCS#8 format. The private key must be compatible with the algorithm specified in the signing_method field.
Type: string
Default: ""
schema_registry.jwt.signing_method
The cryptographic algorithm used to sign the JWT. Supported algorithms are RS256, RS384, RS512, and EdDSA. This algorithm must be compatible with the private key specified in the private_key_file field.
Type: string
Default: ""
schema_registry.name_prefix
A prefix to add to the schema registry name. To form the complete schema registry name, the schema ID is appended as a suffix.
Type: string
Default: schema_registry_id_
schema_registry.oauth
Configure OAuth version 1.0 authentication for secure API access.
Type: object
schema_registry.oauth.access_token
The value used to gain access to the protected resources on behalf of the user.
Type: string
Default: ""
schema_registry.oauth.access_token_secret
The secret that establishes ownership of the access_token in OAuth 1.0 authentication.
|
This field contains sensitive information that usually shouldn’t be added to a configuration directly. For more information, see Secrets. |
Type: string
Default: ""
schema_registry.oauth.consumer_key
The value used to identify this component or client to the service provider.
Type: string
Default: ""
schema_registry.oauth.consumer_secret
The secret that establishes ownership of the consumer key in OAuth 1.0 authentication.
|
This field contains sensitive information that usually shouldn’t be added to a configuration directly. For more information, see Secrets. |
Type: string
Default: ""
schema_registry.oauth.enabled
Whether to enable OAuth version 1.0 authentication for requests.
Type: bool
Default: false
schema_registry.refresh_interval
How frequently to poll the schema registry for the latest schema. If not specified, the schema does not refresh.
Type: string
schema_registry.subject
The subject name used to fetch the schema from the schema registry.
Type: string
schema_registry.tls
Configure Transport Layer Security (TLS) settings to secure network connections. This includes options for standard TLS as well as mutual TLS (mTLS) authentication where both client and server authenticate each other using certificates. Key configuration options include client_certs for mTLS authentication, root_cas/root_cas_file for custom certificate authorities, and skip_cert_verify for development environments.
Type: object
schema_registry.tls.client_certs[]
A list of client certificates for mutual TLS (mTLS) authentication. Configure this field to enable mTLS, authenticating the client to the server with these certificates.
Certificate pairing rules: For each certificate item, provide either:
-
Inline PEM data using both
certandkeyor -
File paths using both
cert_fileandkey_file.
Mixing inline and file-based values within the same item is not supported.
Type: array<object>
Default: []
# Examples:
client_certs:
- cert: foo
key: bar
# ---
client_certs:
- cert_file: ./example.pem
key_file: ./example.key
schema_registry.tls.client_certs[].cert
The plaintext certificate to use for TLS authentication. Must be paired with the corresponding private key in the key field when using inline PEM data for mTLS client certificates.
Type: string
Default: ""
schema_registry.tls.client_certs[].cert_file
The path to a file containing the certificate to use for TLS authentication. Must be paired with the corresponding private key file in the key_file field when using file-based configuration for mTLS client certificates.
Type: string
Default: ""
schema_registry.tls.client_certs[].key
Private key for mTLS client certificate as inline PEM data. Must correspond to the client certificate specified in the cert field. Use this field together with cert when providing certificate data inline rather than through files.
|
This field contains sensitive information that usually shouldn’t be added to a configuration directly. For more information, see Secrets. |
Type: string
Default: ""
schema_registry.tls.client_certs[].key_file
Path to private key file for mTLS client certificate in PEM format. Must correspond to the client certificate specified in the cert_file field. Use this field together with cert_file when loading certificate data from files.
Type: string
Default: ""
schema_registry.tls.client_certs[].password
The password to use for the private key (specified in the key or key_file fields), if it is password-protected. The PKCS#1 and PKCS#8 formats are supported. Supports environment variable interpolation for secure password management.
The pbeWithMD5AndDES-CBC algorithm is obsolete and not supported for the PKCS#8 format. This algorithm does not authenticate the ciphertext, making it vulnerable to padding oracle attacks that can let an attacker recover the plaintext.
|
This field contains sensitive information that usually shouldn’t be added to a configuration directly. For more information, see Secrets. |
Type: string
Default: ""
# Examples:
password: foo
# ---
password: ${KEY_PASSWORD}
schema_registry.tls.enable_renegotiation
Whether to allow the remote server to repeatedly request renegotiation. Enable this option if you’re seeing the error message local error: tls: no renegotiation.
Type: bool
Default: false
schema_registry.tls.root_cas
Specify a root certificate authority to use (optional). This is a string that represents a certificate chain from the parent-trusted root certificate, through possible intermediate signing certificates, to the host certificate. Use either this field for inline certificate data or root_cas_file for file-based certificate loading.
|
This field contains sensitive information that usually shouldn’t be added to a configuration directly. For more information, see Secrets. |
Type: string
Default: ""
# Examples:
root_cas: |-
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
schema_registry.tls.root_cas_file
Specify the path to a root certificate authority file (optional). This is a file, often with a .pem extension, which contains a certificate chain from the parent-trusted root certificate, through possible intermediate signing certificates, to the host certificate. Use either this field for file-based certificate loading or root_cas for inline certificate data.
Type: string
Default: ""
# Examples:
root_cas_file: ./root_cas.pem
schema_registry.tls.skip_cert_verify
Whether to skip server-side certificate verification. Set to true only for testing environments as this reduces security by disabling certificate validation. When using self-signed certificates or in development, this may be necessary, but should never be used in production. Consider using root_cas or root_cas_file to specify trusted certificates instead of disabling verification entirely.
Type: bool
Default: false
seed
When set to a specific number, the model makes a best effort to generate consistent responses for requests that use the same prompt, seed, and parameters. Determinism is not guaranteed.
Requires version 4.34.0 or later.
Type: int
server_address
The OpenAI API endpoint to which the processor sends requests. Update the default value to use a different OpenAI-compatible service.
Type: string
Default: https://api.openai.com/v1
stop[]
Specify up to four stop sequences to use. When the model encounters a stop pattern, it stops generating text and returns the final response.
Requires version 4.34.0 or later.
Type: array<string>
system_prompt
The system prompt to submit along with the user prompt.
This field supports interpolation functions.
Type: string
temperature
Choose a sampling temperature between 0 and 2:
-
Higher values, such as
0.8make the output more random. -
Lower values, such as
0.2make the output more focused and deterministic.
Redpanda recommends adding a value for this field or top_p, but not both.
Requires version 4.34.0 or later.
Type: float
tools[]
External tools the model can invoke, such as functions, APIs, or web browsing. You can build subpipelines of processors that include definitions of these tools, and the specified model can choose when to invoke them to help answer a prompt.
If you don’t want to use external tools, enter an empty array tools: [].
|
Requires version 4.50.0 or later.
Type: array<object>
tools[].description
A description of this tool. The LLM uses it to decide whether to invoke the tool.
Type: string
tools[].parameters
The parameters the LLM needs to provide to invoke this tool.
Type: object
Default: []
tools[].parameters.properties
The parameters the LLM can provide when it invokes this tool, keyed by parameter name.
Type: object
tools[].parameters.properties.enum[]
The values this parameter is limited to. Leave empty to accept any value.
Type: array<string>
Default: []
tools[].parameters.required[]
The names of the parameters the LLM must provide when it invokes this tool.
Type: array<string>
Default: []
tools[].processors[]
The processors to run when the LLM invokes this tool. They receive a message whose payload is the tool call arguments as a JSON object, and their output is returned to the LLM as the tool result.
Type: array<processor>
top_p
An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. For example, a top_p of 0.1 means only the tokens comprising the top 10% probability mass are sampled.
Redpanda recommends adding a value for this field or temperature, but not both.
Requires version 4.34.0 or later.
Type: float
user
A unique identifier that represents the end-user generating the prompt. This value can help OpenAI monitor and detect platform abuse.
This field supports interpolation functions.
Requires version 4.34.0 or later.
Type: string
Examples
Use GPT-4o analyze an image
This example fetches image URLs from stdin and has GPT-4o describe the image.
input:
stdin:
scanner:
lines: {}
pipeline:
processors:
- http:
verb: GET
url: "${!content().string()}"
- openai_chat_completion:
model: gpt-4o
api_key: TODO
prompt: "Describe the following image"
image: "root = content()"
output:
stdout:
codec: lines
Provide historical chat history
This pipeline provides a historical chat history to GPT-4o using a cache.
input:
stdin:
scanner:
lines: {}
pipeline:
processors:
- mapping: |
root.prompt = content().string()
- branch:
processors:
- cache:
resource: mem
operator: get
key: history
- catch:
- mapping: 'root = []'
result_map: 'root.history = this'
- branch:
processors:
- openai_chat_completion:
model: gpt-4o
api_key: TODO
prompt: "${!this.prompt}"
history: 'root = this.history'
result_map: 'root.response = content().string()'
- mutation: |
root.history = this.history.concat([
{"role": "user", "content": this.prompt},
{"role": "assistant", "content": this.response},
])
- cache:
resource: mem
operator: set
key: history
value: '${!this.history}'
- mapping: |
root = this.response
output:
stdout:
codec: lines
cache_resources:
- label: mem
memory: {}
Use GPT-4o to call a tool
This example asks GPT-4o to respond with the weather by invoking an HTTP processor to get the forecast.
input:
generate:
count: 1
mapping: |
root = "What is the weather like in Chicago?"
pipeline:
processors:
- openai_chat_completion:
model: gpt-4o
api_key: "${OPENAI_API_KEY}"
prompt: "${!content().string()}"
tools:
- name: GetWeather
description: "Retrieve the weather for a specific city"
parameters:
required: ["city"]
properties:
city:
type: string
description: the city to look up the weather for
processors:
- http:
verb: GET
url: 'https://wttr.in/${!this.city}?T'
headers:
User-Agent: curl/8.11.1 # Returns a text string from the weather website
output:
stdout: {}