Hugging Face
Access 105 Hugging Face models through Mastra's model router. Authentication is handled automatically using the HF_TOKEN environment variable.
Learn more in the Hugging Face documentation.
.env
HF_TOKEN=your-api-token
src/mastra/agents/my-agent.ts
import { Agent } from "@mastra/core/agent";
const agent = new Agent({
id: "my-agent",
name: "My Agent",
instructions: "You are a helpful assistant",
model: "huggingface/Amazon-FMR/Ergo"
});
// Generate a response
const response = await agent.generate("Hello!");
// Stream a response
const stream = await agent.stream("Tell me a story");
for await (const chunk of stream) {
console.log(chunk);
}
note
Mastra uses the OpenAI-compatible /chat/completions endpoint. Some provider-specific features may not be available. Check the Hugging Face documentation for details.
ModelsDirect link to Models
| Model | Context | Tools | Reasoning | Image | Audio | Video | Input $/1M | Output $/1M |
|---|---|---|---|---|---|---|---|---|
huggingface/Amazon-FMR/Ergo | 1.0M | $0.90 | $3 | |||||
huggingface/anthracite-org/magnum-v4-72b | 33K | $3 | $5 | |||||
huggingface/ByteDance-Seed/UI-TARS-1.5-7B | 128K | $0.10 | $0.20 | |||||
huggingface/CohereLabs/command-a-plus-05-2026-bf16 | 192K | $0.30 | $2 | |||||
huggingface/deepseek-ai/DeepSeek-R1-0528 | 164K | $0.50 | $2 | |||||
huggingface/deepseek-ai/DeepSeek-V3 | 164K | $0.32 | $0.89 | |||||
huggingface/deepseek-ai/DeepSeek-V3-0324 | 131K | $1 | $3 | |||||
huggingface/deepseek-ai/DeepSeek-V3.1 | 164K | $0.25 | $0.95 | |||||
huggingface/deepseek-ai/DeepSeek-V3.2 | 164K | $0.26 | $0.38 | |||||
huggingface/deepseek-ai/DeepSeek-V4-Flash | 1.0M | $0.09 | $0.18 | |||||
huggingface/deepseek-ai/DeepSeek-V4-Flash-0731 | 1.0M | $0.07 | $0.14 | |||||
huggingface/deepseek-ai/DeepSeek-V4-Flash-Vision-Exp | 1.0M | $0.22 | $0.65 | |||||
huggingface/deepseek-ai/DeepSeek-V4-Pro | 1.0M | $0.80 | $2 | |||||
huggingface/deepseek-ai/DeepSeek-V4-Pro-0813 | 1.0M | $1 | $3 | |||||
huggingface/deepseek-ai/DeepSeek-V4.1-Flash | 1.0M | $0.05 | $0.48 | |||||
huggingface/deepseek-ai/DeepSeek-V4.1-Flash-1017 | 1.0M | $0.02 | $0.20 | |||||
huggingface/dphn/Dolphin-Mistral-24B-Venice-Edition | 128K | $0.20 | $0.90 | |||||
huggingface/google/gemma-2-27b-it | 8K | $0.65 | $0.65 | |||||
huggingface/google/gemma-3-12b-it | 131K | $0.05 | $0.15 | |||||
huggingface/google/gemma-3-27b-it | 131K | $0.08 | $0.16 | |||||
huggingface/google/gemma-3-4b-it | 131K | $0.04 | $0.05 | |||||
huggingface/google/gemma-4-26B-A4B-it | 262K | $0.06 | $0.27 | |||||
huggingface/google/gemma-4-31B-it | 262K | $0.34 | $0.10 | |||||
huggingface/Gryphe/MythoMax-L2-13b | 8K | $0.08 | $0.11 | |||||
huggingface/ibm-granite/granite-4.2-8b | 131K | $0.06 | $0.15 | |||||
huggingface/inclusionAI/Ling-3.0-flash | 131K | $0.06 | $0.18 | |||||
huggingface/inclusionAI/Ling-3.0-flash-VL | 131K | $0.06 | $0.18 | |||||
huggingface/inclusionAI/LingSante-3.1-air-VL | 131K | $0.06 | $0.18 | |||||
huggingface/LiquidAI/LFM2.5-24B-A2B | 128K | $0.05 | $0.70 | |||||
huggingface/meta-llama/Llama-3.1-70B-Instruct | 131K | $0.72 | $0.72 | |||||
huggingface/meta-llama/Llama-3.1-8B-Instruct | 131K | $0.02 | $0.04 | |||||
huggingface/meta-llama/Llama-3.2-3B-Instruct | 131K | $0.05 | $0.33 | |||||
huggingface/meta-llama/Llama-3.3-70B-Instruct | 131K | $0.10 | $0.32 | |||||
huggingface/meta-llama/Llama-4-Maverick-17B-128E-Instruct | 524K | $0.35 | $1 | |||||
huggingface/meta-llama/Llama-4-Scout-17B-16E-Instruct | 328K | $0.10 | $0.30 | |||||
huggingface/meta-llama/Llama-Guard-4-12B | 164K | $0.18 | $0.18 | |||||
huggingface/meta-models/Muse-Glimmer-30B | 131K | $0.25 | $1 | |||||
huggingface/meta-models/Muse-Spark-Open-816B-A42B | 1.0M | $1 | $4 | |||||
huggingface/microsoft/phi-4 | 16K | $0.07 | $0.14 | |||||
huggingface/MiniMaxAI/MiniMax-M2.5 | 66K | $0.30 | $1 | |||||
huggingface/MiniMaxAI/MiniMax-M2.7 | 197K | $0.60 | $2 | |||||
huggingface/MiniMaxAI/MiniMax-M3 | 1.0M | $0.23 | $0.96 | |||||
huggingface/MiniMaxAI/MiniMax-M3.1-Flash | 1.0M | $0.11 | $0.44 | |||||
huggingface/mistralai/Mistral-Large-4-1T-A52B | 1.0M | $0.70 | $2 | |||||
huggingface/moondream/moondream3.1-9B-A2B | 32K | $0.30 | $3 | |||||
huggingface/moonshotai/Kimi-K2.5 | 262K | $0.60 | $3 | |||||
huggingface/moonshotai/Kimi-K2.6 | 262K | $0.57 | $2 | |||||
huggingface/moonshotai/Kimi-K2.7-Code | 262K | $0.60 | $3 | |||||
huggingface/moonshotai/Kimi-K3 | 1.0M | $0.28 | $10 | |||||
huggingface/moonshotai/Kimi-K3.1-Pro | 1.0M | $1 | $6 | |||||
huggingface/NousResearch/Hermes-4-405B | 131K | $1 | $3 | |||||
huggingface/nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16 | 262K | $0.06 | $0.24 | |||||
huggingface/nvidia/NVIDIA-Nemotron-3-Super-120B-A12B-FP8 | 262K | $0.07 | $0.40 | |||||
huggingface/nvidia/NVIDIA-Nemotron-3-Ultra-550B-A55B-BF16 | 262K | $0.50 | $2 | |||||
huggingface/nvidia/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-BF16 | 1.0M | $0.05 | $0.16 | |||||
huggingface/nvidia/NVIDIA-Nemotron-3.5-Super-VL-120B-A12B-BF16 | 1.0M | $0.10 | $0.40 | |||||
huggingface/openai/gpt-oss-120b | 131K | $0.03 | $0.15 | |||||
huggingface/openai/gpt-oss-20b | 131K | $0.02 | $0.09 | |||||
huggingface/openai/gpt-oss-safeguard-20b | 131K | $0.07 | $0.20 | |||||
huggingface/Qwen/Qwen2.5-72B-Instruct | 33K | $0.36 | $0.40 | |||||
huggingface/Qwen/Qwen2.5-Coder-32B-Instruct | 33K | $0.66 | $1 | |||||
huggingface/Qwen/Qwen2.5-VL-72B-Instruct | 128K | $0.80 | $1 | |||||
huggingface/Qwen/Qwen3-14B | 41K | $0.17 | $0.34 | |||||
huggingface/Qwen/Qwen3-235B-A22B-Instruct-2507 | 262K | $0.09 | $0.55 | |||||
huggingface/Qwen/Qwen3-30B-A3B | 41K | $0.12 | $0.50 | |||||
huggingface/Qwen/Qwen3-30B-A3B-Instruct-2507 | 262K | $0.10 | $0.30 | |||||
huggingface/Qwen/Qwen3-32B | 41K | $0.08 | $0.28 | |||||
huggingface/Qwen/Qwen3-Coder-30B-A3B-Instruct | 262K | $0.15 | $0.60 | |||||
huggingface/Qwen/Qwen3-Coder-480B-A35B-Instruct | 256K | $0.35 | $2 | |||||
huggingface/Qwen/Qwen3-Coder-Next | 262K | $0.12 | $0.80 | |||||
huggingface/Qwen/Qwen3-Embedding-4B | 33K | $0.01 | โ | |||||
huggingface/Qwen/Qwen3-Embedding-8B | 33K | $0.01 | โ | |||||
huggingface/Qwen/Qwen3-Next-80B-A3B-Instruct | 262K | $0.09 | $1 | |||||
huggingface/Qwen/Qwen3-VL-235B-A22B-Instruct | 262K | $0.20 | $0.88 | |||||
huggingface/Qwen/Qwen3-VL-30B-A3B-Instruct | 262K | $0.15 | $0.60 | |||||
huggingface/Qwen/Qwen3-VL-8B-Instruct | 262K | $0.25 | $0.75 | |||||
huggingface/Qwen/Qwen3.5-27B | 262K | $0.26 | $3 | |||||
huggingface/Qwen/Qwen3.5-35B-A3B | 262K | $0.14 | $1 | |||||
huggingface/Qwen/Qwen3.5-397B-A17B | 262K | $0.45 | $3 | |||||
huggingface/Qwen/Qwen3.5-9B | 262K | $0.08 | $0.12 | |||||
huggingface/Qwen/Qwen3.6-27B | 262K | $0.32 | $3 | |||||
huggingface/Qwen/Qwen3.6-35B-A3B | 262K | $0.10 | $0.89 | |||||
huggingface/Qwen/Qwen3.8-2.4T-A95B | 1.0M | $2 | $6 | |||||
huggingface/Qwen/Qwen3.8-27B | 1.0M | $0.04 | $1 | |||||
huggingface/RadixArk/DaisyRose-27B | 262K | $0.15 | $2 | |||||
huggingface/reflection/Beam-1.0-501B-A23B | 1.0M | $0.25 | $1 | |||||
huggingface/RekaAI/reka-edge-2603 | 16K | $0.10 | $0.10 | |||||
huggingface/Sao10K/L3-8B-Lunaris-v1 | 8K | $0.04 | $0.05 | |||||
huggingface/tencent/Hy4 | 1.0M | $0.83 | $3 | |||||
huggingface/tencent/Hy4-flash | 1.0M | $0.05 | $0.20 | |||||
huggingface/thinkingmachines/Inkling | 1.0M | $1 | $4 | |||||
huggingface/thinkingmachines/Inkling-2-Mini | 1.0M | $0.06 | $0.24 | |||||
huggingface/thinkingmachines/Inkling-2-Small | 1.0M | $0.15 | $0.50 | |||||
huggingface/thinkingmachines/Inkling-Small | 524K | $0.45 | $1 | |||||
huggingface/tngtech/DeepSeek-TNG-R1T2-Chimera | 131K | $1 | $3 | |||||
huggingface/Undi95/ReMM-SLERP-L2-13B | 6K | $0.30 | $0.50 | |||||
huggingface/XiaomiMiMo/MiMo-V2.6-Flash-RL | 1.0M | $0.14 | $0.28 | |||||
huggingface/XiaomiMiMo/MiMo-V2.6-Pro-RL | 1.0M | $0.39 | $0.78 | |||||
huggingface/zai-org/GLM-4.6 | 203K | $0.43 | $2 | |||||
huggingface/zai-org/GLM-4.7 | 203K | $0.40 | $2 | |||||
huggingface/zai-org/GLM-4.7-Flash | 131K | $0.06 | $0.40 | |||||
huggingface/zai-org/GLM-5 | 203K | $1 | $3 | |||||
huggingface/zai-org/GLM-5.2 | 1.0M | $0.56 | $2 | |||||
huggingface/zai-org/GLM-5.3 | 1.0M | $0.07 | $1 | |||||
huggingface/zai-org/GLM-5.3-Flash | 1.0M | $0.04 | $0.08 |
Model availability, capabilities, context windows, and pricing are sourced from models.dev and may change.
Advanced configurationDirect link to Advanced configuration
Custom headersDirect link to Custom headers
src/mastra/agents/my-agent.ts
import { Agent } from "@mastra/core/agent";
const agent = new Agent({
id: "custom-agent",
name: "custom-agent",
model: {
url: "https://router.huggingface.co/v1",
id: "huggingface/Amazon-FMR/Ergo",
apiKey: process.env.HF_TOKEN,
headers: {
"X-Custom-Header": "value"
}
}
});
Dynamic model selectionDirect link to Dynamic model selection
src/mastra/agents/my-agent.ts
import { Agent } from "@mastra/core/agent";
const agent = new Agent({
id: "dynamic-agent",
name: "Dynamic Agent",
model: ({ requestContext }) => {
const useAdvanced = requestContext.task === "complex";
return useAdvanced
? "huggingface/zai-org/GLM-5.3-Flash"
: "huggingface/Amazon-FMR/Ergo";
}
});