Skip to main content

hf-msft-foundry

hf-msft-foundry is an open-source extension for the hf CLI to easily manage and deploy open-models from the Hugging Face Hub on Microsoft Foundry with optimized recipes for managed compute on NVIDIA A100, NVIDIA H100, NVIDIA H200, or AMD MI300X.

Installation

hf extensions install alvarobartt/hf-msft-foundry

Install the standalone hf-msft-foundry command with pip install hf-msft-foundry or uv tool install hf-msft-foundry. PyPI

Authentication

Authenticate with az login, a service principal, or a managed identity, then use AZURE_SUBSCRIPTION_ID and FOUNDRY_ACCOUNT_NAME to override the default subscription or select a Microsoft Foundry resource, or pass --subscription-id and --account for a single command.

To create a Microsoft Foundry resource, run the following command.

hf msft-foundry accounts create my-foundry --resource-group my-foundry-rg --location eastus

Deploy a model

Model Size Default deployment template
zai-org/GLM-5.3-Flash 321B 4 x AMD Instinct MI300X at 512K context
nvidia/NVIDIA-Nemotron-3-Super-120B-A12B-FP8 120B (12B active) 2 x NVIDIA H100 at 256K context
google/gemma-4-26B-A4B-it 26B (4B active) 1 x NVIDIA A100 at 256K context

Browse the catalog to see the GPUs, context lengths, and hourly prices for a model's recipes, then use quota and capacity to check GPU availability before deploying.

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

The CLI uses the default recipe and waits until the deployment is ready, which typically takes around 20 minutes. Use --deployment-template 256k-nvidia-h100 to select another recipe or --no-wait to return immediately, and keep the generated deployment name from the command output if you omit --name.

Use the endpoint

Export the key and the base URL ending in /openai/v1, then use the deployment name as the model ID when calling /chat/completions or, for supported models and templates, /responses.

export OPENAI_BASE_URL=$(hf msft-foundry accounts info -o json | jq -r .openai_base_url)
export OPENAI_API_KEY=$(hf msft-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)

Send images as base64 data URIs because deployments cannot fetch remote URLs.

Coding agents

Choose a model that supports tool calling if the agent needs to read or edit files, then launch Pi 1.x or OpenCode 2.x from your project directory once the deployment reaches Succeeded. The harness executable must be on PATH, and your Azure identity needs permission to list the Microsoft Foundry account keys. Install Pi or install OpenCode.

hf msft-foundry pi my-gemma-4
hf msft-foundry opencode my-gemma-4

Both launchers configure the endpoint and credentials automatically, and you can omit the deployment name when FOUNDRY_DEPLOYMENT is set or the account has one ready deployment. Pi stores sessions in a profile per account and deployment, while OpenCode starts a standalone server and uses its usual session storage.

Pass harness arguments after --, using --continue to resume the latest session or --session to select a specific one.

hf msft-foundry pi my-gemma-4 -- -p "Remember the codename Cedar."
hf msft-foundry pi my-gemma-4 -- --continue -p "What was the codename?"
hf msft-foundry opencode my-gemma-4 -- run "Remember the codename Cedar."
hf msft-foundry opencode my-gemma-4 -- run --continue "What was the codename?"
Manual provider setup

The examples use the endpoint and key with the 256K Gemma 4 template and a 4,096 token output limit, so adjust the context limit to match your deployment template.

For OpenCode, merge this provider into your project's 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}
        }
      }
    }
  }
}

For Pi, merge this provider into ~/.pi/agent/models.json, set baseUrl to the value of OPENAI_BASE_URL, 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}
      ]
    }
  }
}

Agent skill

Install the hf-msft-foundry skill from your project directory to give your agent the steps for finding models, choosing a recipe, and managing deployments. Read the skill.

npx skills add alvarobartt/hf-msft-foundry --skill hf-msft-foundry

Commands

Command Description
models [list|<model> [info|deployment-templates]] [--search] [--version] List models, show one, or list its deployment templates
deploy <model> [--deployment-template] [--name] [--instances] [--version] [--no-wait] Deploy a model
deployments {list,status,wait,scale,delete} Manage the deployments
accounts {list,info,keys,create} Manage the Microsoft Foundry resources
capacity / quota Show the available accelerators and the managed compute quota
pi [<deployment>] / opencode [<deployment>] Launch a coding agent against a ready chat deployment

For machine-readable results and errors, pass -o json to hf msft-foundry.

When you finish using the deployment, run hf msft-foundry deployments delete my-gemma-4 --wait to stop billing.

Metadata

Release files for hf-msft-foundry 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hf-msft-foundry 0.2.0
File Size Uploaded Provenance Actions
hf_msft_foundry-0.2.0.tar.gz 17.0 kB Without provenance Details for hf_msft_foundry-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hf-msft-foundry 0.2.0
File Interpreter ABI Platform Actions
hf_msft_foundry-0.2.0-py3-none-any.whl Python 3 none any Details for hf_msft_foundry-0.2.0-py3-none-any.whl

Total release size: 38.2 kB

Release files / hf_msft_foundry-0.2.0.tar.gz

Download URL hf_msft_foundry-0.2.0.tar.gz
Size 17.0 kB
Tags Source
SHA-256 checksum
How to use checksums
5a693e4fb49c7a73869a853a8f5ab750701ff4bd4a3b12ab38198d7eb62f3ebb
BLAKE2b-256 checksum
How to use checksums
2c96a1d2145ec850cff54ce2bfe5fcd4341f2c89201ff6e24b491595eb4fabf3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / hf_msft_foundry-0.2.0-py3-none-any.whl

Download URL hf_msft_foundry-0.2.0-py3-none-any.whl
Size 21.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
30f79592d3bf467f49b8c8165a5662d5e2f505f89a8ff3f0d5c8412670db3caa
BLAKE2b-256 checksum
How to use checksums
482d21246d7ba37a0e413a9799acc0968b0c7129f3f9bc30b86c30c88a90aff8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for hf-msft-foundry 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page