danny-avila/LibreChat · error · Error
Missing DALLE_API_KEY environment variable.
Error message
Missing DALLE_API_KEY environment variable.
What it means
Thrown lazily by DALLE3.getApiKey() the first time an image request actually needs a key. It checks `process.env.DALLE3_API_KEY ?? process.env.DALLE_API_KEY`; if both are empty and `this.override` is false it throws. Note the message names only DALLE_API_KEY even though DALLE3_API_KEY is the preferred variable — a minor message/behavior mismatch to be aware of.
Source
Thrown at api/app/clients/tools/structured/DALLE3.js:126
// 5. Diversify depictions of ALL images with people to always include always DESCENT and GENDER for EACH person using direct terms. Adjust only human descriptions.
// - EXPLICITLY specify these attributes, not abstractly reference them. The attributes should be specified in a minimal way and should directly describe their physical form.
// - Your choices should be grounded in reality. For example, all of a given OCCUPATION should not be the same gender or race. Additionally, focus on creating diverse, inclusive, and exploratory scenes via the properties you choose during rewrites. Make choices that may be insightful or unique sometimes.
// - Use "various" or "diverse" ONLY IF the description refers to groups of more than 3 people. Do not change the number of people requested in the original description.
// - Don't alter memes, fictional character origins, or unseen people. Maintain the original prompt's intent and prioritize quality.
// The prompt must intricately describe every part of the image in concrete, objective detail. THINK about what the end goal of the description is, and extrapolate that to what would make satisfying images.
// All descriptions sent to dalle should be a paragraph of text that is extremely descriptive and detailed. Each should be more than 3 sentences long.
// - The "vivid" style is HIGHLY preferred, but "natural" is also supported.`;
this.schema = dalle3JsonSchema;
}
static get jsonSchema() {
return dalle3JsonSchema;
}
getApiKey() {
const apiKey = process.env.DALLE3_API_KEY ?? process.env.DALLE_API_KEY ?? '';
if (!apiKey && !this.override) {
throw new Error('Missing DALLE_API_KEY environment variable.');
}
return apiKey;
}
replaceUnwantedChars(inputString) {
return inputString
.replace(/\r\n|\r|\n/g, ' ')
.replace(/"/g, '')
.trim();
}
wrapInMarkdown(imageUrl) {
return ``;
}
returnValue(value) {
if (this.isAgent === true && typeof value === 'string') {
return [value, {}];View on GitHub (pinned to 5ff282f900)
Solutions
- Add `DALLE3_API_KEY=<key>` (or the legacy `DALLE_API_KEY=<key>`) to your .env and restart the API process.
- Verify the var is visible to the process: `node -e "console.log(Boolean(process.env.DALLE3_API_KEY))"` run with the same env loading the server uses.
- If loading the tool only for catalog/manifest purposes, instantiate it with `override: true` so getApiKey() returns an empty string instead of throwing.
- Check there is no leading/trailing space or quotes around the value in the .env file (dotenv will include them literally).
Example fix
// before — tool invoked, throws inside getApiKey()
const t = new DALLE3({});
await t._call({ prompt: 'a cat' });
// after — key supplied via env, or override for manifest loading
// .env: DALLE3_API_KEY=sk-...
const t = new DALLE3({ override: true }); // catalog-only, no calls Defensive patterns
Strategy: validation
Validate before calling
function resolveDalleKey() {
const key = process.env.DALLE3_API_KEY ?? process.env.DALLE_API_KEY;
if (!key) {
throw new Error('Set DALLE3_API_KEY (or legacy DALLE_API_KEY) before invoking the DALLE3 tool.');
}
return key;
} Type guard
function hasDalleKey() {
return Boolean(process.env.DALLE3_API_KEY ?? process.env.DALLE_API_KEY);
} Try / catch
try {
await dalleTool.invoke({ prompt });
} catch (e) {
if (/Missing DALLE_API_KEY/.test(e.message)) {
return 'Image generation is not configured.';
}
throw e;
} Prevention
- Run a startup env check that lists all tool keys and fails or warns when one is missing.
- Treat DALLE3_API_KEY as the canonical name; keep DALLE_API_KEY only for backward compat.
- In tests, construct the tool with override:true or inject the key via the constructor.
When it happens
Trigger: Invoking the DALLE3 tool's _call() (image generation) on an instance whose constructor did not set an apiKey and where neither DALLE3_API_KEY nor DALLE_API_KEY is present in process.env, while override is false.
Common situations: Enabling the DALL·E 3 tool for an agent without adding the key to .env; renaming DALLE3_API_KEY to DALLE_API_KEY (or vice-versa) during a config migration; the value is present in the shell but not exported, so the Node process never sees it; using a managed secret store that failed to inject the var.
Related errors
- Missing FLUX_API_KEY environment variable.
- Missing IMAGE_GEN_OAI_API_KEY environment variable.
- Missing AZURE_AI_SEARCH_SERVICE_ENDPOINT, AZURE_AI_SEARCH_IN
- Gemini Image Generation requires one of: user-provided API k
- Missing ${this.envVarApiKey} or ${this.envVarSearchEngineId}
AI-assisted analysis of danny-avila/LibreChat@5ff282f900 (2026-08-12).
Data as JSON: /api/errors/049aa306a082a4ed.
Report an issue: GitHub.