Skip to content

feat: Allow creating separate SDK client instances with their own credentials #3452

@madebyfabian

Description

@madebyfabian

Is your feature request related to a problem? Please describe.

Right now, if you want to call SDK methods across two different Trigger.dev projects, you have to swap credentials globally using configure() and swap them back after.

configure({ accessToken: process.env.TRIGGER_SECRET_KEY_B })
const res = await runs.list({ /* ... */ })
// Has to be reset, otherwise, all SDK methods following this code will use key B.
configure({ accessToken: process.env.TRIGGER_SECRET_KEY })

This works, but it's fragile. If you forget to reset, every subsequent SDK call silently runs against the wrong project. This can be an issue especially if you have concurrent calls, like on a long-running server or a Vercel Fluid instance.

See Discord discussion: https://discord.com/channels/1066956501299777596/1496733903522627594

Describe the solution you'd like to see

Something like this:

const triggerA = new TriggerClient({ accessToken: process.env.TRIGGER_SECRET_KEY_A })
const triggerB = new TriggerClient({ accessToken: process.env.TRIGGER_SECRET_KEY_B })
 
const runsA = await triggerA.runs.list({ /* ... */ })
const runsB = await triggerB.runs.list({ /* ... */ })

Each client is fully self-contained, without shared state.

The existing behaviour (initialising from env variables automatically, with the
import { runs } from '@trigger/sdk') would stay exactly as it is right now, so no breaking changes.

Describe alternate solutions

Either using the two configure method above or the internal auth.withAuth method, but this does the same.

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions