Apache Airflow Providers Cohere
raw JSON → 1.6.5 verified Fri May 01 auth: no python
Apache Airflow provider for integrating with Cohere, enabling workflows that leverage Cohere's large language models for text generation, embedding, classification, and summarization. Current version 1.6.5, released on 2025-03-07. Active development with regular releases.
pip install apache-airflow-providers-cohere Common errors
error ModuleNotFoundError: No module named 'airflow.providers.cohere' ↓
cause The provider package is not installed.
fix
pip install apache-airflow-providers-cohere
error ImportError: cannot import name 'CohereHook' from 'airflow.providers.cohere.hooks.cohere' ↓
cause The hook class name changed or path is wrong. In older versions it was 'CohereHook' in 'cohere_hook' module.
fix
Use correct import: from airflow.providers.cohere.hooks.cohere import CohereHook
error AttributeError: 'CohereHook' object has no attribute 'get_conn' ↓
cause The hook API changed; get_conn was removed in place of a 'conn' property.
fix
Use hook.conn instead of hook.get_conn()
Warnings
breaking Upgrading from provider versions <1.0.0 to >=1.0.0 changed hook and operator import paths. Old paths (with unerlying 'cohere_hook' or 'cohere_embedding' modules) no longer work. Use the current imports shown above. ↓
fix Update imports to use 'hooks.cohere' and 'operators.embedding'.
deprecated The 'CohereGenerateOperator' is deprecated as of v1.3.0. Use 'CohereTextGenOperator' instead. ↓
fix Replace CohereGenerateOperator with CohereTextGenOperator from 'airflow.providers.cohere.operators.text_gen'.
gotcha Cohere API keys are typically stored in an Airflow connection with conn_type='cohere'. Ensure the connection ID matches the root path of Cohere's API base (https://api.cohere.com). Incorrect base can cause 401 errors. ↓
fix Create a Cohere connection in Airflow UI: Conn Id: cohere_default, Conn Type: Cohere, Login: (your API key). Host: https://api.cohere.com
Imports
- CohereHook wrong
from airflow.providers.cohere.hooks.cohere_hook import CohereHookcorrectfrom airflow.providers.cohere.hooks.cohere import CohereHook - CohereEmbeddingOperator wrong
from airflow.providers.cohere.operators.cohere_embedding import CohereEmbeddingOperatorcorrectfrom airflow.providers.cohere.operators.embedding import CohereEmbeddingOperator
Quickstart
from airflow import DAG
from airflow.providers.cohere.hooks.cohere import CohereHook
from airflow.providers.cohere.operators.embedding import CohereEmbeddingOperator
from datetime import datetime
with DAG('cohere_demo', start_date=datetime(2024,1,1), schedule=None) as dag:
embed = CohereEmbeddingOperator(
task_id='embed_text',
conn_id='cohere_default',
text='Hello, world!',
model='embed-english-v3.0',
input_type='search_document'
)