Back to APIs

Translate text with high-quality machine translation tools.

Using the DeepL API with Trigger.dev

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

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

Example code using DeepL

Below is a working code example of how you can use DeepL 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, eventTrigger } from "@trigger.dev/sdk";
2
import { z } from "zod";
3
import * as deepl from "deepl-node";
4
5
// API documentation: https://www.deepl.com/docs-api/api-access
6
// This code uses the deepl-node library.
7
// You can find more examples and usage details at: https://github.com/DeepLcom/deepl-node
8
const translator = new deepl.Translator(process.env.DEEPL_AUTH_KEY!);
9
10
client.defineJob({
11
id: "deepl-translate",
12
name: "DeepL Translate",
13
version: "1.0.0",
14
trigger: eventTrigger({
15
name: "deepl.translate",
16
schema: z.object({
17
text: z.string(),
18
targetLang: z.string(), // Languages: https://www.deepl.com/docs-api/translate-text
19
}),
20
}),
21
22
run: async (payload, io, ctx) => {
23
// Wrap any SDK call in io.runTask so it's resumable and displays in logs
24
await io.runTask(
25
"Translate text",
26
async () => {
27
const targetLang = payload.targetLang as deepl.TargetLanguageCode;
28
const result = await translator.translateText(
29
payload.text,
30
null,
31
targetLang
32
);
33
return result;
34
},
35
36
// Add metadata to improve how the task displays in the logs
37
{ name: "DeepL Translate Text", icon: "deepl" }
38
);
39
},
40
});