Airflow Summit 2026 is coming August 31 - September 2 in Austin, TX. Register now to secure your spot!

airflow.providers.openai.operators.openai

Classes

OpenAIEmbeddingOperator

Operator that accepts input text to generate OpenAI embeddings using the specified model.

OpenAIResponseOperator

Operator that generates a model response using the OpenAI Responses API.

OpenAITriggerBatchOperator

Operator that triggers an OpenAI Batch API endpoint and waits for the batch to complete.

Module Contents

class airflow.providers.openai.operators.openai.OpenAIEmbeddingOperator(conn_id, input_text, model='text-embedding-3-small', embedding_kwargs=None, **kwargs)[source]

Bases: airflow.providers.common.compat.sdk.BaseOperator

Operator that accepts input text to generate OpenAI embeddings using the specified model.

Parameters:
  • conn_id (str) – The OpenAI connection ID to use.

  • input_text (str | list[str] | list[int] | list[list[int]]) – The text to generate OpenAI embeddings for. This can be a string, a list of strings, a list of integers, or a list of lists of integers.

  • model (str) – The OpenAI model to be used for generating the embeddings.

  • embedding_kwargs (dict | None) – Additional keyword arguments to pass to the OpenAI create_embeddings method.

See also

For more information on how to use this operator, take a look at the guide: OpenAIEmbeddingOperator For possible options for embedding_kwargs, see: https://platform.openai.com/docs/api-reference/embeddings/create

template_fields: collections.abc.Sequence[str] = ('input_text',)[source]
conn_id[source]
input_text[source]
model = 'text-embedding-3-small'[source]
embedding_kwargs[source]
property hook: airflow.providers.openai.hooks.openai.OpenAIHook[source]

Return an instance of the OpenAIHook.

execute(context)[source]

Derive when creating an operator.

The main method to execute the task. Context is the same dictionary used as when rendering jinja templates.

Refer to get_template_context for more context.

class airflow.providers.openai.operators.openai.OpenAIResponseOperator(conn_id, input_text, model='gpt-4o-mini', response_kwargs=None, **kwargs)[source]

Bases: airflow.providers.common.compat.sdk.BaseOperator

Operator that generates a model response using the OpenAI Responses API.

The operator is synchronous and returns the response’s aggregated output text. For previous_response_id chaining, background=True responses, or access to the full structured response, use OpenAIHook directly.

Parameters:
  • conn_id (str) – The OpenAI connection ID to use.

  • input_text (str | list[Any]) – The input prompt for the model. This can be a string or a structured list of input items.

  • model (str) – The OpenAI model to use.

  • response_kwargs (dict | None) – Additional keyword arguments to pass to the OpenAI create_response method (for example instructions, tools, conversation or previous_response_id).

See also

For more information on how to use this operator, take a look at the guide: OpenAIResponseOperator For possible options, see: https://platform.openai.com/docs/api-reference/responses/create

template_fields: collections.abc.Sequence[str] = ('input_text',)[source]
conn_id[source]
input_text[source]
model = 'gpt-4o-mini'[source]
response_kwargs[source]
property hook: airflow.providers.openai.hooks.openai.OpenAIHook[source]

Return an instance of the OpenAIHook.

execute(context)[source]

Derive when creating an operator.

The main method to execute the task. Context is the same dictionary used as when rendering jinja templates.

Refer to get_template_context for more context.

class airflow.providers.openai.operators.openai.OpenAITriggerBatchOperator(file_id, endpoint, conn_id=OpenAIHook.default_conn_name, deferrable=conf.getboolean('operators', 'default_deferrable', fallback=False), wait_seconds=3, timeout=24 * 60 * 60, wait_for_completion=True, **kwargs)[source]

Bases: airflow.providers.common.compat.sdk.BaseOperator

Operator that triggers an OpenAI Batch API endpoint and waits for the batch to complete.

Parameters:
  • file_id (str) – Required. The ID of the batch file to trigger.

  • endpoint (Literal['/v1/chat/completions', '/v1/embeddings', '/v1/completions']) – Required. The OpenAI Batch API endpoint to trigger.

  • conn_id (str) – Optional. The OpenAI connection ID to use. Defaults to ‘openai_default’.

  • deferrable (bool) – Optional. Run operator in the deferrable mode.

  • wait_seconds (float) – Optional. Number of seconds between checks. Only used when deferrable is False. Defaults to 3 seconds.

  • timeout (float) – Optional. The amount of time, in seconds, to wait for the request to complete. Only used when deferrable is False. Defaults to 24 hour, which is the SLA for OpenAI Batch API.

  • wait_for_completion (bool) – Optional. Whether to wait for the batch to complete. If set to False, the operator will return immediately after triggering the batch. Defaults to True.

See also

For more information on how to use this operator, please take a look at the guide: OpenAITriggerBatchOperator

template_fields: collections.abc.Sequence[str] = ('file_id',)[source]
conn_id = 'openai_default'[source]
file_id[source]
endpoint[source]
deferrable[source]
wait_seconds = 3[source]
timeout = 86400[source]
wait_for_completion = True[source]
batch_id: str | None = None[source]
property hook: airflow.providers.openai.hooks.openai.OpenAIHook[source]

Return an instance of the OpenAIHook.

execute(context)[source]

Derive when creating an operator.

The main method to execute the task. Context is the same dictionary used as when rendering jinja templates.

Refer to get_template_context for more context.

execute_complete(context, event=None)[source]

Invoke this callback when the trigger fires; return immediately.

Relies on trigger to throw an exception, otherwise it assumes execution was successful.

on_kill()[source]

Cancel the batch if task is cancelled.

Was this entry helpful?