NlaakALD
NlaakALD7mo ago

Unable to push deployment config to ...

Hi all. I just started having this issue about 2 hours ago. The Live Site is working with no issues, but the dev side will not update config. Says OPEN_API_KEY not defined but it is and has been for last 20 days. I though I might have broke something after not being able to figure it out, so i stashed and pulled in the live version (production) and its doing the same thing. so i created a component to test OpenAI connection
"use client";

import { useAction } from "convex/react";
import { api } from "../convex/_generated/api";

const CheckOpenAI = () => {
const checkConnectionAction = useAction(api.openai.checkConnection);

const handleCheck = async () => {
const result = await checkConnectionAction();
console.log(result);
};

return <button onClick={handleCheck}>Check OpenAI Connection</button>;
}

export default CheckOpenAI;
"use client";

import { useAction } from "convex/react";
import { api } from "../convex/_generated/api";

const CheckOpenAI = () => {
const checkConnectionAction = useAction(api.openai.checkConnection);

const handleCheck = async () => {
const result = await checkConnectionAction();
console.log(result);
};

return <button onClick={handleCheck}>Check OpenAI Connection</button>;
}

export default CheckOpenAI;
and added a function to the openai.ts file in convex folder
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
})

export const checkConnection = action({
args: {},
handler: async () => {
try {
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});

// Make a simple API call to list models
const response = await openai.models.list();

// If we get here without throwing an error, the connection is working
return { success: true, message: "Connection to OpenAI API is working" };
} catch (error) {
// If there's an error, the connection failed
return {
success: false,
message: "Failed to connect to OpenAI API",
error: error instanceof Error ? error.message : String(error)
};
}
},
});
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
})

export const checkConnection = action({
args: {},
handler: async () => {
try {
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});

// Make a simple API call to list models
const response = await openai.models.list();

// If we get here without throwing an error, the connection is working
return { success: true, message: "Connection to OpenAI API is working" };
} catch (error) {
// If there's an error, the connection failed
return {
success: false,
message: "Failed to connect to OpenAI API",
error: error instanceof Error ? error.message : String(error)
};
}
},
});
All is good except thats its not. npx convex dev is spamming
Error: Unable to push deployment config to https://dapper-corgi-203.convex.cloud
Error fetching POST https://dapper-corgi-203.convex.cloud/api/push_config 400 Bad Request: InvalidModules: Hit an error while pushing:
Loading the pushed modules encountered the following
error:
Failed to analyze openai.js: Uncaught Error: The OPENAI_API_KEY environment variable is missing or empty; either provide it, or instantiate the OpenAI client with an apiKey option, like new OpenAI({ apiKey: 'My API Key' }).
at new OpenAI (../node_modules/openai/src/index.ts:120:188)
at <anonymous> (../convex/openai.ts:7:10)
Error: Unable to push deployment config to https://dapper-corgi-203.convex.cloud
Error fetching POST https://dapper-corgi-203.convex.cloud/api/push_config 400 Bad Request: InvalidModules: Hit an error while pushing:
Loading the pushed modules encountered the following
error:
Failed to analyze openai.js: Uncaught Error: The OPENAI_API_KEY environment variable is missing or empty; either provide it, or instantiate the OpenAI client with an apiKey option, like new OpenAI({ apiKey: 'My API Key' }).
at new OpenAI (../node_modules/openai/src/index.ts:120:188)
at <anonymous> (../convex/openai.ts:7:10)
and npm run dev is giving error
Error: [Request ID: 16acc18b4019ebfc] Server Error
Could not find public function for 'openai:checkConnection'. Did you forget to run `npx convex dev` or `npx convex deploy`?
Error: [Request ID: 16acc18b4019ebfc] Server Error
Could not find public function for 'openai:checkConnection'. Did you forget to run `npx convex dev` or `npx convex deploy`?
the last error is because i cannot update config (convex). The only thing that changed was i upgraded to pro from free. Am i missing something?
1 Reply
ian
ian7mo ago
Did your dev backend change when you updated to pro? Is it a new project? You can check your dashboard's environment variables separately for dev & prod. You can get there with npx convex dashboard and you can set it there or via npx convex env set OPENAI_API_KEY ...yourvalue

Did you find this page helpful?