You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用HuggingFace Inference Endpoints调用模型遇404,免费端点正常

问题解决:HuggingFace付费推理端点404错误

你的核心问题是付费端点的URL拼接错误,付费Inference Endpoints的访问不需要在URL后追加模型ID——每个端点是单独绑定一个模型的,直接使用端点提供的基础URL即可。

修正后的代码:

mode = 'paid'                                              # works if 'free'
model_id = "sentence-transformers/all-MiniLM-L6-v2"
headers = {"Authorization": f"Bearer {HUGGINGFACE_TOKEN}"}

if mode == 'free':
    # 免费端点正常使用
    api_url = f"https://api-inference.huggingface.co/pipeline/feature-extraction/{model_id}"
else:
    # 付费端点直接使用基础URL,不要追加model_id
    api_url = "https://xxxxxxxxxxxxxxxxx.us-east-1.aws.endpoints.huggingface.cloud/"

def get_embeddings(texts):
    response = requests.post(api_url, headers=headers, json={"inputs": texts, "options":{"wait_for_model":True}})

额外检查点:

  • 确认你的HUGGINGFACE_TOKEN拥有该付费端点的访问权限(可在端点设置的"Access Control"中检查)
  • 确保端点的推理任务配置和你调用的feature-extraction类型匹配(Web界面测试正常的话,这一点大概率没问题)

内容的提问来源于stack exchange,提问作者AlwaysLearning

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 22:13:10