mastra-ai/mastra · error · Error
Upstash URL and token are required
Error message
Upstash URL and token are required
What it means
The Upstash logger transport pushes logs to an Upstash Redis REST API, which requires both the REST URL and token. The constructor throws 'Upstash URL and token are required' if either opts.upstashUrl or opts.upstashToken is missing or empty.
Source
Thrown at packages/loggers/src/upstash/index.ts:26
maxListLength: number;
batchSize: number;
flushInterval: number;
logBuffer: any[];
lastFlush: number;
flushIntervalId: NodeJS.Timeout;
constructor(opts: {
listName?: string;
maxListLength?: number;
batchSize?: number;
upstashUrl: string;
flushInterval?: number;
upstashToken: string;
}) {
super({ objectMode: true });
if (!opts.upstashUrl || !opts.upstashToken) {
throw new Error('Upstash URL and token are required');
}
this.upstashUrl = opts.upstashUrl;
this.upstashToken = opts.upstashToken;
this.listName = opts.listName || 'application-logs';
this.maxListLength = opts.maxListLength || 10000;
this.batchSize = opts.batchSize || 100;
this.flushInterval = opts.flushInterval || 10000;
this.logBuffer = [];
this.lastFlush = Date.now();
// Start flush interval
this.flushIntervalId = setInterval(() => {
this._flush().catch(err => {
console.error('Error flushing logs to Upstash:', err);
});
}, this.flushInterval);View on GitHub (pinned to 75dd419e61)
Solutions
- Set both upstashUrl (e.g. https://<db>.upstash.io) and upstashToken from your Upstash console REST credentials.
- Add a startup env check that fails fast with a clear message before constructing the transport.
- Confirm you copied the REST API token (not the database password) from the Upstash console.
Example fix
// before
const logger = new UpstashTransport({ upstashUrl: process.env.UPSTASH_URL, upstashToken: process.env.UPSTASH_TOKEN }); // throws if unset
// after
if (!process.env.UPSTASH_URL || !process.env.UPSTASH_TOKEN) throw new Error('Set UPSTASH_URL and UPSTASH_TOKEN');
const logger = new UpstashTransport({ upstashUrl: process.env.UPSTASH_URL!, upstashToken: process.env.UPSTASH_TOKEN! }); Defensive patterns
Strategy: validation
Validate before calling
function assertUpstashCreds(opts) {
if (!opts.upstashUrl || !opts.upstashToken) {
throw new Error('Set UPSTASH_URL and UPSTASH_TOKEN before creating the Upstash transport');
}
} Type guard
function hasUpstashCreds(opts) {
return typeof opts.upstashUrl === 'string' && opts.upstashUrl.length > 0 &&
typeof opts.upstashToken === 'string' && opts.upstashToken.length > 0;
} Try / catch
try {
const logger = new UpstashTransport({ upstashUrl, upstashToken });
} catch (e) {
if (e.message === 'Upstash URL and token are required') {
console.error('Upstash REST credentials missing — check UPSTASH_URL / UPSTASH_TOKEN');
}
throw e;
} Prevention
- Fail fast at startup if UPSTASH_URL/UPSTASH_TOKEN env vars are missing.
- Copy credentials from the Upstash console's REST API section (not the DB password).
- Keep credentials in secret management, not committed config files.
When it happens
Trigger: new UpstashTransport({ upstashUrl: process.env.UPSTASH_URL, upstashToken: process.env.UPSTASH_TOKEN }) where either env var is unset or empty.
Common situations: Upstash REST credentials not provisioned in the deployment environment; using the wrong credential type (DB password instead of REST token); typo'd env var names; empty strings from default config templates.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- HTTP URL is required
- Failed to execute Upstash command: ${response.statusText}
- Google RBAC roleMapping is required.
- Cookie password must be at least 32 characters. Set OKTA_COO
- heartbeatMs must be a finite number no greater than ${MAX_TI
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/68f96e9d625d7071.
Report an issue: GitHub.