Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/guides/frameworks/supabase-edge-functions-basic.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Replace the placeholder code in your `edge-function-trigger/index.ts` file with
// Setup type definitions for built-in Supabase Runtime APIs
import "jsr:@supabase/functions-js/edge-runtime.d.ts";
// Import the Trigger.dev SDK - replace "<your-sdk-version>" with the version of the SDK you are using, e.g. "3.0.0". You can find this in your package.json file.
import { tasks } from "npm:@trigger.dev/[email protected]/v3";
import { tasks } from "npm:@trigger.dev/[email protected]";
// Import your task type from your /trigger folder
import type { helloWorldTask } from "../../../src/trigger/example.ts";
// 👆 **type-only** import
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ supabase functions new video-processing-handler
```ts functions/video-processing-handler/index.ts
// Setup type definitions for built-in Supabase Runtime APIs
import "jsr:@supabase/functions-js/edge-runtime.d.ts";
import { tasks } from "npm:@trigger.dev/sdk@latest/v3";
import { tasks } from "npm:@trigger.dev/sdk@latest";
// Import the videoProcessAndUpdate task from the trigger folder
import type { videoProcessAndUpdate } from "../../../src/trigger/videoProcessAndUpdate.ts";
// 👆 type only import
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/python/python-crawl4ai.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ After you've initialized your project with Trigger.dev, add these build settings
```ts trigger.config.ts
import { defineConfig } from "@trigger.dev/sdk";
import { pythonExtension } from "@trigger.dev/python/extension";
import type { BuildContext, BuildExtension } from "@trigger.dev/core/v3/build";
import type { BuildContext, BuildExtension } from "@trigger.dev/core/build";

export default defineConfig({
project: "<project ref>",
Expand Down
25 changes: 14 additions & 11 deletions docs/how-to-reduce-your-spend.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ description: "Tips and best practices to reduce your costs on Trigger.dev"
## Check out your usage page regularly

Monitor your usage dashboard to understand your spending patterns. You can see:

- Your most expensive tasks
- Your total duration by task
- Number of runs by task
Expand All @@ -18,6 +19,7 @@ You can view your usage page by clicking the "Organization" menu in the top left
## Create billing alerts

Configure billing alerts in your dashboard to get notified when you approach spending thresholds. This helps you:

- Catch unexpected cost increases early
- Identify runaway tasks before they become expensive

Expand All @@ -43,7 +45,7 @@ export const lightTask = task({

// Only use larger machines when necessary
export const heavyTask = task({
id: "heavy-task",
id: "heavy-task",
machine: "medium-1x", // 1 vCPU, 2 GB RAM
run: async (payload) => {
// CPU/memory intensive operations
Expand All @@ -64,11 +66,14 @@ export const expensiveApiCall = task({
id: "expensive-api-call",
run: async (payload: { userId: string }) => {
// This expensive operation will only run once per user
await wait.for({ seconds: 30 }, {
idempotencyKey: `user-processing-${payload.userId}`,
idempotencyKeyTTL: "1h"
});

await wait.for(
{ seconds: 30 },
{
idempotencyKey: `user-processing-${payload.userId}`,
idempotencyKeyTTL: "1h",
}
);

const result = await processUserData(payload.userId);
return result;
},
Expand Down Expand Up @@ -105,7 +110,7 @@ export const processItems = task({
id: "process-items",
run: async (payload: { items: string[] }) => {
// Process all items in parallel
const promises = payload.items.map(item => processItem(item));
const promises = payload.items.map((item) => processItem(item));
// This works very well for API calls
await Promise.all(promises);
},
Expand Down Expand Up @@ -133,7 +138,7 @@ export const apiTask = task({
This is very useful for intermittent errors, but if there's a permanent error you don't want to retry because you will just keep failing and waste compute. Use [AbortTaskRunError](/errors-retrying#using-aborttaskrunerror) to prevent a retry:

```ts
import { task, AbortTaskRunError } from "@trigger.dev/sdk/v3";
import { task, AbortTaskRunError } from "@trigger.dev/sdk";

export const someTask = task({
id: "some-task",
Expand All @@ -145,13 +150,11 @@ export const someTask = task({
throw new AbortTaskRunError(result.error);
}

return result
return result;
},
});
```



## Use appropriate maxDuration settings

Set realistic maxDurations to prevent runs from executing for too long:
Expand Down
24 changes: 12 additions & 12 deletions docs/realtime/auth.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ You can create a Public Access Token using the `auth.createPublicToken` function

```tsx
// Somewhere in your backend code
import { auth } from "@trigger.dev/sdk/v3";
import { auth } from "@trigger.dev/sdk";

const publicToken = await auth.createPublicToken(); // 👈 this public access token has no permissions, so is pretty useless!
```
Expand All @@ -33,7 +33,7 @@ const publicToken = await auth.createPublicToken(); // 👈 this public access t
By default a Public Access Token has no permissions. You must specify the scopes you need when creating a Public Access Token:

```ts
import { auth } from "@trigger.dev/sdk/v3";
import { auth } from "@trigger.dev/sdk";

const publicToken = await auth.createPublicToken({
scopes: {
Expand All @@ -47,7 +47,7 @@ const publicToken = await auth.createPublicToken({
This will allow the token to read all runs, which is probably not what you want. You can specify only certain runs by passing an array of run IDs:

```ts
import { auth } from "@trigger.dev/sdk/v3";
import { auth } from "@trigger.dev/sdk";

const publicToken = await auth.createPublicToken({
scopes: {
Expand All @@ -61,7 +61,7 @@ const publicToken = await auth.createPublicToken({
You can scope the token to only read certain tasks:

```ts
import { auth } from "@trigger.dev/sdk/v3";
import { auth } from "@trigger.dev/sdk";

const publicToken = await auth.createPublicToken({
scopes: {
Expand All @@ -75,7 +75,7 @@ const publicToken = await auth.createPublicToken({
Or tags:

```ts
import { auth } from "@trigger.dev/sdk/v3";
import { auth } from "@trigger.dev/sdk";

const publicToken = await auth.createPublicToken({
scopes: {
Expand All @@ -89,7 +89,7 @@ const publicToken = await auth.createPublicToken({
Or a specific batch of runs:

```ts
import { auth } from "@trigger.dev/sdk/v3";
import { auth } from "@trigger.dev/sdk";

const publicToken = await auth.createPublicToken({
scopes: {
Expand All @@ -103,7 +103,7 @@ const publicToken = await auth.createPublicToken({
You can also combine scopes. For example, to read runs with specific tags and for specific tasks:

```ts
import { auth } from "@trigger.dev/sdk/v3";
import { auth } from "@trigger.dev/sdk";

const publicToken = await auth.createPublicToken({
scopes: {
Expand All @@ -120,7 +120,7 @@ const publicToken = await auth.createPublicToken({
By default, Public Access Token's expire after 15 minutes. You can specify a different expiration time when creating a Public Access Token:

```ts
import { auth } from "@trigger.dev/sdk/v3";
import { auth } from "@trigger.dev/sdk";

const publicToken = await auth.createPublicToken({
expirationTime: "1hr",
Expand Down Expand Up @@ -156,7 +156,7 @@ For triggering tasks from your frontend, you need special "trigger" tokens. Thes
### Creating Trigger Tokens

```ts
import { auth } from "@trigger.dev/sdk/v3";
import { auth } from "@trigger.dev/sdk";

// Somewhere in your backend code
const triggerToken = await auth.createTriggerPublicToken("my-task");
Expand All @@ -167,7 +167,7 @@ const triggerToken = await auth.createTriggerPublicToken("my-task");
You can pass multiple tasks to create a token that can trigger multiple tasks:

```ts
import { auth } from "@trigger.dev/sdk/v3";
import { auth } from "@trigger.dev/sdk";

// Somewhere in your backend code
const triggerToken = await auth.createTriggerPublicToken(["my-task-1", "my-task-2"]);
Expand All @@ -178,7 +178,7 @@ const triggerToken = await auth.createTriggerPublicToken(["my-task-1", "my-task-
You can also create tokens that can be used multiple times:

```ts
import { auth } from "@trigger.dev/sdk/v3";
import { auth } from "@trigger.dev/sdk";

// Somewhere in your backend code
const triggerToken = await auth.createTriggerPublicToken("my-task", {
Expand All @@ -191,7 +191,7 @@ const triggerToken = await auth.createTriggerPublicToken("my-task", {
These tokens also expire, with the default expiration time being 15 minutes. You can specify a custom expiration time:

```ts
import { auth } from "@trigger.dev/sdk/v3";
import { auth } from "@trigger.dev/sdk";

// Somewhere in your backend code
const triggerToken = await auth.createTriggerPublicToken("my-task", {
Expand Down
2 changes: 1 addition & 1 deletion docs/realtime/backend/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ See our [authentication guide](/realtime/auth) for detailed information on creat
Subscribe to a run:

```ts
import { runs, tasks } from "@trigger.dev/sdk/v3";
import { runs, tasks } from "@trigger.dev/sdk";

// Trigger a task
const handle = await tasks.trigger("my-task", { some: "data" });
Expand Down
14 changes: 7 additions & 7 deletions docs/realtime/backend/streams.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Streams use the metadata system to send data chunks in real-time. You register a
Here's how to stream data from OpenAI in your task:

```ts
import { task, metadata } from "@trigger.dev/sdk/v3";
import { task, metadata } from "@trigger.dev/sdk";
import OpenAI from "openai";

const openai = new OpenAI({
Expand Down Expand Up @@ -64,7 +64,7 @@ export const myTask = task({
You can subscribe to the stream using the `runs.subscribeToRun` method with `.withStreams()`:

```ts
import { runs } from "@trigger.dev/sdk/v3";
import { runs } from "@trigger.dev/sdk";
import type { myTask, STREAMS } from "./trigger/my-task";

// Somewhere in your backend
Expand All @@ -91,7 +91,7 @@ async function subscribeToStream(runId: string) {
You can register and subscribe to multiple streams in the same task:

```ts
import { task, metadata } from "@trigger.dev/sdk/v3";
import { task, metadata } from "@trigger.dev/sdk";
import OpenAI from "openai";

const openai = new OpenAI({
Expand Down Expand Up @@ -138,7 +138,7 @@ export const myTask = task({
Then subscribe to both streams:

```ts
import { runs } from "@trigger.dev/sdk/v3";
import { runs } from "@trigger.dev/sdk";
import type { myTask, STREAMS } from "./trigger/my-task";

// Somewhere in your backend
Expand Down Expand Up @@ -170,7 +170,7 @@ The [AI SDK](https://sdk.vercel.ai/docs/introduction) provides a higher-level AP

```ts
import { openai } from "@ai-sdk/openai";
import { logger, metadata, runs, schemaTask } from "@trigger.dev/sdk/v3";
import { logger, metadata, runs, schemaTask } from "@trigger.dev/sdk";
import { streamText } from "ai";
import { z } from "zod";

Expand Down Expand Up @@ -215,7 +215,7 @@ When using tools with the AI SDK, you can access tool calls and results using th

```ts
import { openai } from "@ai-sdk/openai";
import { logger, metadata, runs, schemaTask } from "@trigger.dev/sdk/v3";
import { logger, metadata, runs, schemaTask } from "@trigger.dev/sdk";
import { streamText, tool, type TextStreamPart } from "ai";
import { z } from "zod";

Expand Down Expand Up @@ -283,7 +283,7 @@ You can define a Trigger.dev task that can be used as a tool, and will automatic

```ts
import { openai } from "@ai-sdk/openai";
import { logger, metadata, runs, schemaTask, toolTask } from "@trigger.dev/sdk/v3";
import { logger, metadata, runs, schemaTask, toolTask } from "@trigger.dev/sdk";
import { streamText, tool, type TextStreamPart } from "ai";
import { z } from "zod";

Expand Down
16 changes: 8 additions & 8 deletions docs/realtime/backend/subscribe.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ These functions allow you to subscribe to run updates from your backend code. Ea
Subscribes to all changes to a specific run.

```ts Example
import { runs } from "@trigger.dev/sdk/v3";
import { runs } from "@trigger.dev/sdk";

for await (const run of runs.subscribeToRun("run_1234")) {
console.log(run);
Expand All @@ -29,7 +29,7 @@ This function subscribes to all changes to a run. It returns an async iterator t
Subscribes to all changes to runs with a specific tag.

```ts Example
import { runs } from "@trigger.dev/sdk/v3";
import { runs } from "@trigger.dev/sdk";

for await (const run of runs.subscribeToRunsWithTag("user:1234")) {
console.log(run);
Expand All @@ -47,7 +47,7 @@ This function subscribes to all changes to runs with a specific tag. It returns
Subscribes to all changes for runs in a batch.

```ts Example
import { runs } from "@trigger.dev/sdk/v3";
import { runs } from "@trigger.dev/sdk";

for await (const run of runs.subscribeToBatch("batch_1234")) {
console.log(run);
Expand All @@ -65,7 +65,7 @@ This function subscribes to all changes for runs in a batch. It returns an async
You can infer the types of the run's payload and output by passing the type of the task to the subscribe functions:

```ts
import { runs, tasks } from "@trigger.dev/sdk/v3";
import { runs, tasks } from "@trigger.dev/sdk";
import type { myTask } from "./trigger/my-task";

async function myBackend() {
Expand All @@ -85,7 +85,7 @@ async function myBackend() {
When using `subscribeToRunsWithTag`, you can pass a union of task types:

```ts
import { runs } from "@trigger.dev/sdk/v3";
import { runs } from "@trigger.dev/sdk";
import type { myTask, myOtherTask } from "./trigger/my-task";

for await (const run of runs.subscribeToRunsWithTag<typeof myTask | typeof myOtherTask>("my-tag")) {
Expand Down Expand Up @@ -130,7 +130,7 @@ This example task updates the progress of a task as it processes items.

```ts
// Your task code
import { task, metadata } from "@trigger.dev/sdk/v3";
import { task, metadata } from "@trigger.dev/sdk";

export const progressTask = task({
id: "progress-task",
Expand Down Expand Up @@ -165,7 +165,7 @@ We can now subscribe to the runs and receive real-time metadata updates.

```ts
// Somewhere in your backend code
import { runs } from "@trigger.dev/sdk/v3";
import { runs } from "@trigger.dev/sdk";
import type { progressTask } from "./trigger/progress-task";

async function monitorProgress(runId: string) {
Expand Down Expand Up @@ -199,7 +199,7 @@ For more information on how to write tasks that use the metadata API, as well as
You can get type safety for your metadata by defining types:

```ts
import { runs } from "@trigger.dev/sdk/v3";
import { runs } from "@trigger.dev/sdk";
import type { progressTask } from "./trigger/progress-task";

interface ProgressMetadata {
Expand Down
6 changes: 3 additions & 3 deletions docs/realtime/how-it-works.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The run object returned by Realtime subscriptions is optimized for streaming upd
After you trigger a task, you can subscribe to the run using the `runs.subscribeToRun` function. This function returns an async iterator that you can use to get updates on the run status.

```ts
import { runs, tasks } from "@trigger.dev/sdk/v3";
import { runs, tasks } from "@trigger.dev/sdk";

// Somewhere in your backend code
async function myBackend() {
Expand All @@ -43,7 +43,7 @@ Every time the run changes, the async iterator will yield the updated run. You c
Alternatively, you can subscribe to changes to any run that includes a specific tag (or tags) using the `runs.subscribeToRunsWithTag` function.

```ts
import { runs } from "@trigger.dev/sdk/v3";
import { runs } from "@trigger.dev/sdk";

// Somewhere in your backend code
for await (const run of runs.subscribeToRunsWithTag("user:1234")) {
Expand All @@ -55,7 +55,7 @@ for await (const run of runs.subscribeToRunsWithTag("user:1234")) {
If you've used `batchTrigger` to trigger multiple runs, you can also subscribe to changes to all the runs triggered in the batch using the `runs.subscribeToBatch` function.

```ts
import { runs } from "@trigger.dev/sdk/v3";
import { runs } from "@trigger.dev/sdk";

// Somewhere in your backend code
for await (const run of runs.subscribeToBatch("batch-id")) {
Expand Down
Loading