How Do I create Secret Environment Variables that are project specific through the API?

I am automating the creation of Vercel Projects by leveraging the API.

I can successfully create Environment Variable (either through project creation or through the environment variables endpoint) with the exception of environment variables that contain a secret. I get the following error:

Error creating project: {
error: {
code: ‘ENV_SHOULD_BE_A_SECRET’,
message: ‘Value for variable NEXT_PUBLIC_POSTHOG_KEY is forbidden. Only secret IDs are allowed.’,
key: ‘environmentVariables.value’,
envVarKey: ‘NEXT_PUBLIC_POSTHOG_KEY’,
value: ‘’
}
}

However, the secrets endpoint does not allows me to specify secrets for a specific project since the projectID property is marked as depecreated:

How should I use the Vercel API to create Environment Variable secrets that are specific for a single project?

You can use /v10/projects/{idOrName}/env with the type set as sensitive to create a sensitive environment variable. Secrets were converted to sensitive Environment Variables for Preview and Production on May 1st, 2024. You can find more info about the change in the links below.