Skip to content

Add a Common AI connection type for Hugging Face Inference Endpoints #77833

Backlog

Description

@kaxil

Description

Add a pydanticai_huggingface connection type so a Common AI task can point at a dedicated Hugging Face Inference Endpoint by name.

Common AI (apache-airflow-providers-common-ai) already reaches Hugging Face Inference Providers: a pydanticai connection with the huggingface: model prefix and the access token in Password. A dedicated Inference Endpoint is harder. The user copies the endpoint URL into the connection by hand and has to keep it in sync with the endpoint. The token is also entered twice, once on the huggingface connection and once on the pydanticai one.

pydantic-ai's HuggingFaceProvider already accepts either provider_name (routing through Inference Providers) or base_url (a dedicated endpoint), so this is connection plumbing and no new model integration.

Scope

  • A pydanticai_huggingface connection type shipped by the Hugging Face provider behind a [common.ai] extra, following PydanticAISnowflakeHook (pydanticai_snowflake) in the Snowflake provider.
  • Extra fields for endpoint_name and namespace, resolved to the endpoint URL with the hook methods from Manage Hugging Face Inference Endpoints from Dags #77830, or for provider_name.
  • A decision on credential reuse: either one connection serves both HuggingFaceHook and Common AI, or the new type points at a huggingface connection ID. The PR states which one it chose and why.

This depends on #77830 for the endpoint hook methods.

Done when

  • @task.llm(llm_conn_id=...) reaches a dedicated endpoint when endpoint_name is set, and Inference Providers when provider_name is set.
  • Common AI's model_providers.rst table has a Hugging Face row for the new connection type, and the Hugging Face provider docs have a connection page for it.
  • The end-to-end scenarios below have all been run against a real endpoint, and the PR description carries the evidence.

End-to-end verification

The whole feature is a URL lookup against a live service plus credential handling, which a mocked HfApi cannot prove. Keep the PR in draft until the evidence listed further down is in its description.

Setup:

  • A live Airflow from breeze start-airflow, with both providers installed from the PR branch. Create the connection in the UI and trigger the Dags there.
  • A real Hugging Face token and a small CPU Inference Endpoint in the test namespace (airflow-hf by default) serving a small text-generation model. Redact the token from anything pasted into the PR.
  • Pause or delete the endpoint after the last scenario. It is billed while it runs.

Scenarios:

  1. Connection form. The new type appears in the connection-type list with endpoint_name, namespace and provider_name fields, and saving it works.
  2. Dedicated endpoint. With endpoint_name set, a @task.llm task gets a real completion. Show that the request went to the endpoint's own URL and not to Inference Providers.
  3. Inference Providers. With provider_name set instead, the same task gets a completion through that provider.
  4. Invalid combinations. Both fields set, and neither set, each fail with an error that names the two fields. Record whether the failure happens when the connection is saved or when the task runs.
  5. Unknown endpoint. An endpoint_name that does not exist fails the task with the name and namespace in the message.
  6. Endpoint not running. Run the task against a paused endpoint and against one in scaledToZero. The PR describes what happens in each case, and the how-to page says the same.
  7. Endpoint recreated. Delete the endpoint, create it again under the same name, and rerun the task without touching the connection. It looks up the endpoint's current URL and succeeds, which is the case that breaks today when the URL is pasted into the connection.
  8. Token entered once. With the credential-reuse option the PR chose, the token is stored in one place and both HuggingFaceHook and the Common AI task work.
  9. Together with Manage Hugging Face Inference Endpoints from Dags #77830. One Dag resumes the endpoint, calls it through the new connection, and pauses it in a teardown.
  10. Token stays out of logs. The token appears neither in the task log nor in the rendered template fields.

What the PR needs

The code follows AGENTS.md and gets reviewed against code-review.instructions.md, so read both first. The points provider PRs trip on most:

  • The hook subclasses Common AI's public PydanticAIHook, as the Snowflake one does. Nothing is imported from core internals or from another provider's private modules.
  • Imports sit at the top of the file. There is no assert outside tests and no new raise AirflowException; use ValueError, TypeError or a dedicated exception class.
  • Unset fields are tested with is None. An empty string from the connection form is treated as unset on purpose, with a test for it.
  • Functions and methods are named with an action verb (get_, build_, resolve_). Comments appear only where they record a constraint the code cannot show.
  • Tests are pytest, with spec/autospec on every mock, parametrization for the field combinations, and no issue numbers in names or docstrings. Each test fails when the change it covers is reverted. At least one test builds the real HuggingFaceProvider, so pydantic-ai validates the arguments it receives.
  • provider.yaml lists the new connection type, the [common.ai] extra goes in pyproject.toml, generated files are regenerated with prek and never edited by hand, and the docs change in the same PR. Providers take no newsfragment.
  • The diff contains only files this issue needs.

The PR description has:

  • What changed and why, in words that match the diff, including the credential-reuse decision.
  • For each scenario above: the task-log lines or the error message it produced.
  • Screenshots: the connection form with the new fields (scenario 1), the Grid view of scenario 9, and the task log of scenario 2.
  • The endpoint's status read from the API after the last run, showing it is not left running.
  • Any scenario that was not run, by number, with the reason. A mocked version passing is no substitute.
  • The generative-AI disclosure from the PR template, filled in, and closes: #<this issue>.

cc @ParagEkbote

Use case/motivation

Teams that serve an open model on a dedicated Inference Endpoint want to use it from @task.llm and @task.agent the same way they use a hosted model: by naming a connection. With this connection type the Dag refers to the endpoint by name, the URL is looked up at run time, and the Hugging Face token lives in one place.

It also completes the flow from #77830. A Dag can resume an endpoint, run Common AI tasks against it through this connection, and pause it in a teardown, without an endpoint URL appearing anywhere in the Dag or the connection.

Related issues

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions