
OpenAI ChatCompletion
CertifiedSend prompts to OpenAI Chat Completions
OpenAI ChatCompletion
Send prompts to OpenAI Chat Completions
Calls the OpenAI Chat Completions API docs with a prompt or message list, optional tool calls, and optional JSON Schema structured output. Requires either prompt or messages; defaults to OpenAI sampling limits and records token usage metrics.
type: io.kestra.plugin.openai.ChatCompletionExamples
Based on a prompt input, generate a completion response and pass it to a downstream task.
id: openai_chat
namespace: company.team
inputs:
- id: prompt
type: STRING
defaults: What is data orchestration?
tasks:
- id: completion
type: io.kestra.plugin.openai.ChatCompletion
apiKey: "{{ secret('OPENAI_API_KEY') }}"
model: gpt-4o
prompt: "{{ inputs.prompt }}"
- id: log_output
type: io.kestra.plugin.core.log.Log
message: "{{ outputs.completion.choices[0].message.content }}"
Send a prompt to OpenAI's ChatCompletion API.
id: openai_chat
namespace: company.team
tasks:
- id: prompt
type: io.kestra.plugin.openai.ChatCompletion
apiKey: "{{ secret('OPENAI_API_KEY') }}"
model: gpt-4o
prompt: Explain in one sentence why data engineers build data pipelines
- id: use_output
type: io.kestra.plugin.core.log.Log
message: "{{ outputs.prompt.choices | jq('.[].message.content') | first }}"
Based on a prompt input, ask OpenAI to call a function that determines whether you need to respond to a customer's review immediately or wait until later, and then comes up with a suggested response.
id: openai_chat
namespace: company.team
inputs:
- id: prompt
type: STRING
defaults: I love your product and would purchase it again!
tasks:
- id: prioritize_response
type: io.kestra.plugin.openai.ChatCompletion
apiKey: "{{ secret('OPENAI_API_KEY') }}"
model: gpt-4o
messages:
- role: user
content: "{{ inputs.prompt }}"
functions:
- name: respond_to_review
description: Given the customer product review provided as input, determines how urgently a reply is required and then provides suggested response text.
parameters:
- name: response_urgency
type: string
description: How urgently this customer review needs a reply. Bad reviews
must be addressed immediately before anyone sees them. Good reviews can
wait until later.
required: true
enumValues:
- reply_immediately
- reply_later
- name: response_text
type: string
description: The text to post online in response to this review.
required: true
- id: response_urgency
type: io.kestra.plugin.core.debug.Return
format: "{{ outputs.prioritize_response | jq('.choices[0].message.tool_calls[0].function.arguments | fromjson | .response_urgency') | first }}"
- id: response_text
type: io.kestra.plugin.core.debug.Return
format: "{{ outputs.prioritize_response | jq('.choices[0].message.tool_calls[0].function.arguments | fromjson | .response_text') | first }}"
Properties
apiKey *Requiredstring
OpenAI API key
model *Requiredstring
Model ID
Required OpenAI model identifier (e.g., gpt-4o); see the model docs.
clientTimeout Non-dynamicinteger
10The maximum number of seconds to wait for a response
frequencyPenalty numberstring
Frequency penalty (-2 to 2)
Default 0; positive values reduce reuse of frequent tokens.
functionCall string
autoTool choice directive
Use 'auto' (default), 'none', or a specific function name present in functions; other names raise an error.
functions array
Functions exposed as tools
Define tool-callable functions with names, descriptions, and parameters; ignored if none provided.
io.kestra.plugin.openai.ChatCompletion-PluginChatFunction
Function description
Function name
Function parameters
io.kestra.plugin.openai.ChatCompletion-PluginChatFunctionParameter
Function parameter description
Provide enough detail for the model to populate this argument correctly.
Function parameter name
Function parameter type
OpenAPI data type: string, number, integer, boolean, array, or object
Allowed enum values
Optional; constrains the model to this fixed set for classification-like prompts.
Parameter required flag
Defaults to false; when true the model must provide this parameter.
jsonResponseSchema string
JSON response schema
Stringified JSON Schema enabling response_format = json_schema; uses name kestra_schema with strict true.
logitBias object
Token logit bias
Map token IDs to bias values; empty when unset.
maxTokens integerstring
Max completion tokens
Leave null to rely on model defaults; counts only completion tokens.
messages array
Messages to send to the model
Required when prompt is absent; each entry keeps its role and content.
io.kestra.plugin.openai.ChatCompletion-ChatMessage
n integerstring
1Number of choices
Default 1; controls size of choices list.
pluginDefaultsRef Non-dynamicstring
Reference (ref) of the pluginDefaults to apply to this task.
presencePenalty numberstring
Presence penalty (-2 to 2)
Default 0; positive values discourage repeating earlier topics.
prompt string
Prompt text to send
Sent as a user message when messages are omitted; required if messages is not set.
promptCaching booleanstring
Enable prompt caching
When true, enables OpenAI prompt caching to reduce latency and cost for repeated prefixes. See the prompt caching docs.
stop array
Stop sequences
Up to 4 strings; default is none.
temperature numberstring
1.0Sampling temperature (0–2)
Default 1.0; higher values increase randomness.
topP numberstring
Nucleus sampling top_p
Lower values limit token candidates. Omit to let OpenAI apply its server-side default. Must be omitted for reasoning models (e.g., gpt-5.2+, gpt-5.4) which reject top_p.
user string
A unique identifier representing your end-user
Outputs
choices array
Completion choices
All choices returned by the API in order.
com.openai.models.chat.completions.ChatCompletion-Choice
com.openai.core.JsonField
com.openai.core.JsonField
com.openai.core.JsonField
id string
Chat completion ID
model string
Model used
object string
Returned object type
Expected value is chat.completion.
usage
Token usage summary
Prompt, completion, and total token counts when provided by the API.