#Getting `Invalid or Missing API key` when calling `envvars.upload`.
1 messages · Page 1 of 1 (latest)
Hi @small arch. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
The error Invalid or Missing API key when calling envvars.upload is likely due to incorrect configuration of the SDK. According to the Trigger.dev documentation, the correct property for the secret key in the configure function is secretKey, not accessToken. The accessToken property is not recognized by the SDK for authentication, which would result in the error you're seeing.
Here's how you should configure the SDK for preview branches:
import { configure, envvars } from "@trigger.dev/sdk";
configure({
secretKey: triggerSecretKey, // should be 'secretKey', not 'accessToken'
previewBranch: branchName,
});
await envvars.upload(triggerProjectId, "preview", {
variables,
override: true,
});
Make sure:
- You use
secretKeyin the configuration. - The environment (
slugin your code) should be"preview"for preview branches. - The
triggerSecretKeyshould start withtr_preview_.
Reference: API keys, Preview branch targeting
If you correct the property name and ensure the environment is set to "preview", the error should be resolved.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@small arch Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@hasty plume
(property) secretKey?: string | undefined
@deprecated — Use accessToken instead.
secretKey is deprecated
Let me check the knowledge base for you again. One moment! :books:
Thank you for pointing out the deprecation notice. However, based on the provided knowledge sources, the official Trigger.dev documentation consistently uses secretKey (not accessToken) in all SDK configuration examples, including for preview branches and management API usage. There is no mention in the documentation that secretKey is deprecated or that accessToken should be used instead.
For example, the documentation states:
import { configure, envvars } from "@trigger.dev/sdk";
configure({
secretKey: process.env["TRIGGER_ACCESS_TOKEN"], // starts with tr_pat_
previewBranch: "feature-xyz",
});
await envvars.update("proj_1234", "preview", "DATABASE_URL", {
value: "your_preview_database_url",
});
And for general authentication:
import { configure } from "@trigger.dev/sdk";
configure({ accessToken: "tr_dev_1234" });
However, the documentation sometimes uses accessToken in the configure function, but only in the context of setting a personal access token (PAT), not for environment-specific secret keys. The distinction is:
- Use secretKey for environment-specific keys (e.g., tr_dev_, tr_prod_, tr_preview_).
- Use accessToken for personal access tokens (tr_pat_).
If you are using a preview branch secret key (tr_preview_), the documentation only shows usage with secretKey, not accessToken. If you are seeing a deprecation warning in your IDE or editor, it may be ahead of the documentation, but the official docs do not mention this change.
Summary:
According to the current official documentation, you should use secretKey for preview branch secret keys. If you are using a personal access token (PAT), use accessToken. If you are still getting the error, double-check that your key matches the expected prefix and that you are using the correct environment ("preview") and branch name.
If you have further issues, it may be worth checking for SDK updates or consulting the Trigger.dev team, as the documentation does not mention secretKey being deprecated at this time.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@small arch Kapa.ai is still learning and improving, please let me know how I did by reacting below.
I noticed that the branch didn't exist when I was calling envvars.upload
@hasty plume how can I upload the variables for preview environment? Without having to set an specific branch?
Let me check the knowledge base for you again. One moment! :books:
To upload environment variables for the preview environment (so they apply to all preview branches, not just a specific branch), you should use the environment value "preview" and do not set the previewBranch option in your SDK configuration.
Here’s how you can do it:
import { configure, envvars } from "@trigger.dev/sdk";
configure({
secretKey: process.env["TRIGGER_SECRET_KEY"], // Use your preview environment secret key (starts with tr_preview_)
// Do NOT set previewBranch here
});
await envvars.upload("proj_1234", "preview", {
variables: {
MY_ENV_VAR: "value",
ANOTHER_VAR: "anotherValue",
},
override: true,
});
This will set the variables for the entire preview environment, and they will be applied to all preview branches unless a branch-specific variable overrides them. Only set the previewBranch option if you want to target a specific branch; omitting it targets the whole preview environment Environment variables for preview Preview branch targeting.
Note:
- Make sure your secret key is for the preview environment (starts with tr_preview_).
- The environment parameter in envvars.upload should be "preview".
- Do not set previewBranch in the configure call.
This approach ensures the variables are available to all preview branches by default.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@small arch Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@hasty plume still getting AuthenticationError [TriggerApiError]: Invalid or Missing API key when trying to upload without the branchname but using preview as the slug
AuthenticationError [TriggerApiError]: Invalid or Missing API key
at Function.generate <redacted> {
status: 401,
headers: {
connection: 'keep-alive',
'content-type': 'application/json; charset=utf-8',
date: 'Wed, 15 Oct 2025 13:58:35 GMT',
'strict-transport-security': 'max-age=3153600000',
'transfer-encoding': 'chunked',
'x-ratelimit-limit': '1500',
'x-ratelimit-remaining': '1499',
'x-ratelimit-reset': '1760536725861',
'x-robots-tag': 'noindex, nofollow'
},
error: 'Invalid or Missing API key',
code: undefined,
param: undefined,
type: undefined
}
Let me check the knowledge base for you again. One moment! :books:
Based on the official Trigger.dev documentation, to upload environment variables for the preview environment (so they apply to all preview branches), you should:
- Use the environment value
"preview"in yourenvvars.uploadcall. - Use your preview environment secret key (starts with
tr_preview_) as thesecretKeyin the SDK configuration. - Do not set the
previewBranchoption in the SDK configuration.
Your code should look like this:
import { configure, envvars } from "@trigger.dev/sdk";
configure({
secretKey: process.env["TRIGGER_SECRET_KEY"], // should be your tr_preview_... key
// Do NOT set previewBranch
});
await envvars.upload("proj_1234", "preview", {
variables: {
MY_ENV_VAR: "value",
},
override: true,
});
If you are still getting Invalid or Missing API key, please check the following based on the documentation:
- Key Format: Ensure your secret key starts with
tr_preview_and is valid for the preview environment. - Key Location: Make sure the key is being correctly loaded from your environment (e.g.,
process.env["TRIGGER_SECRET_KEY"]). - Project Ref: Double-check that your project reference (
"proj_1234") is correct. - No previewBranch: Do not set the
previewBranchoption in the SDK configuration when targeting the whole preview environment (Preview branch targeting).
If all of the above are correct and you still receive the error, the knowledge sources do not provide further troubleshooting steps for this specific error. It may indicate an issue with the key itself or a possible limitation in the current Trigger.dev implementation that is not documented. In that case, contacting Trigger.dev support or checking for updates in their documentation would be the next step.