Back to APIs

Hugging Face

huggingface.co

Integrate advanced NLP models for text analysis and generation.

Using the Hugging Face API with Trigger.dev

You can use Trigger.dev with any existing Node SDK or even just using fetch. Using io.runTask makes your Hugging Face background job resumable and appear in our dashboard.

Use io.runTask() and the official SDK or fetch.

Use our HTTP endpoint to subscribe to webhooks

Example code using Hugging Face

Below are some working code examples of how you can use Hugging Face with Trigger.dev. These samples are open source and maintained by the community, you can copy and paste them into your own projects.

1
import { TriggerClient } from "@trigger.dev/sdk";
2
import { createHash } from "crypto";
3
4
// Go to Hugging Face Dashboard > Click on Profile > Settings
5
// Go to Webhooks > Add a new webhook
6
// Select yourself as the target
7
// Add the webhook URL
8
// Add the secret as "Test" (for example)
9
// Create a model from the dashboard to trigger the webhook
10
const huggingFace = client.defineHttpEndpoint({
11
id: "hugging-face",
12
source: "huggingface.co",
13
icon: "huggingface",
14
verify: async (request) => {
15
if (
16
request.headers.get("x-webhook-secret") ===
17
process.env.HUGGING_FACE_WEBHOOK_SECRET
18
)
19
return { success: true };
20
return { success: false, reason: "Webhook Secret Match Failed" };
21
},
22
});
23
24
client.defineJob({
25
id: "http-hugging-face",
26
name: "HTTP Hugging Face",
27
version: "1.0.0",
28
enabled: true,
29
trigger: huggingFace.onRequest(),
30
run: async (request, io, ctx) => {
31
const body = await request.json();
32
await io.logger.info(`Body`, body);
33
},
34
});