8000 GitHub - huggingface/hf-azure: Hugging Face CLI extension to deploy open-models from the Hub, with optimized recipes, on Microsoft Foundry. · GitHub
[go: up one dir, main page]

Skip to content
huggingfacePublic

About

Hugging Face CLI extension to deploy open-models from the Hub, with optimized recipes, on Microsoft Foundry.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

Deploy open models from the Hugging Face Hub on Microsoft Foundry with hf-azure

hf-azure is an hf CLI extension to deploy open models from the Hugging Face Hub on Microsoft Foundry and use them from your code or coding agents.

Installation

hf extensions install huggingface/hf-azure

Or install it from PyPI with uv tool install hf-azure and run hf-azure instead of hf azure.

$ hf azure --help
usage: hf azure microsoft-foundry [-h]
                                  {models,deploy,deployments,accounts,capacity,quota,pi,opencode,hermes,codex}
                                  ...

Deploy open models from the Hugging Face collection on Microsoft Foundry

positional arguments:
  {models,deploy,deployments,accounts,capacity,quota,pi,opencode,hermes,codex}
    models              Browse the Hugging Face collection on Microsoft
                        Foundry
    deploy              Deploy a model
    deployments         Manage the deployments
    accounts            Manage the Microsoft Foundry resources
    capacity            Show the available accelerators
    quota               Show the managed compute quota
    pi                  Launch pi with a Microsoft Foundry deployment
    opencode            Launch opencode with a Microsoft Foundry deployment
    hermes              Launch hermes with a Microsoft Foundry deployment
    codex               Launch codex with a Microsoft Foundry deployment

options:
  -h, --help            show this help message and exit

The microsoft-foundry prefix is optional for now, e.g. `hf azure deploy` is
`hf azure microsoft-foundry deploy`.

Authentication

Run az login and set AZURE_SUBSCRIPTION_ID and FOUNDRY_ACCOUNT_NAME, or create a new Microsoft Foundry resource if you don't have one yet.

hf azure microsoft-foundry accounts create my-foundry --resource-group my-foundry-rg --location eastus

Deploy a model

Pick a model from the Hugging Face collection on Microsoft Foundry, compare its deployment templates, and deploy it.

hf azure microsoft-foundry models list --search "gemma 4"
hf azure microsoft-foundry models google/gemma-4-26B-A4B-it deployment-templates
hf azure microsoft-foundry deploy google/gemma-4-26B-A4B-it --name my-gemma-4

Deploying takes around 20 minutes, and you can stop billing with hf azure microsoft-foundry deployments delete my-gemma-4 once you're done.

Use the endpoint

Export the endpoint and key, and use the deployment name as the model with any OpenAI-compatible client.

export OPENAI_BASE_URL=$(hf azure microsoft-foundry accounts info -o json | jq -r .openai_base_url)
export OPENAI_API_KEY=$(hf azure microsoft-foundry accounts keys -o json | jq -r .key1)
from openai import OpenAI

client = OpenAI()
completion = client.chat.completions.create(
    model="my-gemma-4",
    messages=[{"role": "user", "content": "What's the capital of France?"}],
    max_completion_tokens=1024,
)
print(completion.choices[0].message.content)

Coding agents

Launch Pi, OpenCode, Hermes Agent, or Codex on a deployment with the endpoint and key already configured, passing any extra arguments to the agent after --.

hf azure microsoft-foundry <harness> my-gemma-4
Pi manual setup

Add this provider to ~/.pi/agent/models.json and select foundry/my-gemma-4.

{
  "providers": {
    "foundry": {
      "baseUrl": "https://my-foundry.services.ai.azure.com/openai/v1",
      "api": "openai-completions",
      "apiKey": "$OPENAI_API_KEY",
      "compat": {"maxTokensField": "max_completion_tokens"},
      "models": [
        {"id": "my-gemma-4", "name": "Gemma 4 26B A4B", "input": ["text"], "contextWindow": 262144, "maxTokens": 4096}
      ]
    }
  }
}
OpenCode manual setup

Add this provider to opencode.json and select foundry/my-gemma-4.

{
  "providers": {
    "foundry": {
      "package": "@opencode/ai/providers/openai-compatible",
      "env": ["OPENAI_API_KEY"],
      "settings": {"baseURL": "{env:OPENAI_BASE_URL}"},
      "models": {
        "my-gemma-4": {
          "name": "Gemma 4 26B A4B",
          "capabilities": {"tools": true, "input": ["text"], "output": ["text"]},
          "limit": {"context": 262144, "output": 4096}
        }
      }
    }
  }
}
Hermes Agent manual setup

Add this provider to ~/.hermes/config.yaml and run hermes --provider foundry --model my-gemma-4.

providers:
  foundry:
    name: Microsoft Foundry
    base_url: https://my-foundry.services.ai.azure.com/openai/v1
    key_env: OPENAI_API_KEY
    models:
      my-gemma-4:
        context_length: 262144
Codex manual setup

Save this as ~/.codex/foundry.config.toml and run codex --profile foundry, without model_reasoning_effort in ~/.codex/config.toml.

model = "my-gemma-4"
model_provider = "foundry"
model_context_window = 262144

[model_providers.foundry]
name = "Microsoft Foundry"
base_url = "https://my-foundry.services.ai.azure.com/openai/v1"
env_key = "OPENAI_API_KEY"
wire_api = "responses"

Agent skill

Give your agent the hf-azure skill to find, deploy, and manage models.

npx skills add huggingface/hf-azure --skill hf-azure

Telemetry

The CLI sends anonymous usage events with public catalog metadata only, such as the models, templates, and regions used, and you can disable it with HF_HUB_DISABLE_TELEMETRY=1.

About

Hugging Face CLI extension to deploy open-models from the Hub, with optimized recipes, on Microsoft Foundry.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages

0