Cloudflare Docs
AI Gateway
Edit this page
Give us feedback
Set theme to dark (⇧+D)

HuggingFace

https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_slug}/huggingface

When making requests to HuggingFace Inference API, replace https://api-inference.huggingface.co/models/ in the URL you’re currently using with https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_slug}/huggingface. Note that the model you’re trying to access should come right after, for example https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_slug}/huggingface/bigcode/starcoder.

Request
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_slug}/huggingface/bigcode/starcoder \
--header 'Authorization: Bearer {hf_api_token}' \
--header 'Content-Type: application/json' \
--data '{
"inputs": "console.log"
}'

If you are using the HuggingFace.js library, you can set your inference endpoint like this:

index.js
import { HfInferenceEndpoint } from '@huggingface/inference'
const hf = new HfInferenceEndpoint(
"https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_slug}/huggingface/gpt2",
env.HF_API_TOKEN
);