Loading...
Loading...
Vercel environment variable expert guidance. Use when working with .env files, vercel env commands, OIDC tokens, or managing environment-specific configuration.
npx skill4agent add vercel-labs/vercel-plugin env-vars.envvercel env| File | Purpose | Git-tracked? |
|---|---|---|
| Default values for all environments | Yes |
| Local overrides and secrets | No (gitignored) |
| Development-specific defaults | Yes |
| Local dev overrides | No |
| Production-specific defaults | Yes |
| Local prod overrides | No |
| Test-specific defaults | Yes |
| Local test overrides | No |
.env.env.[environment].env.local.env.[environment].local.env.env.development.env.production.local.env.localvercel env pullNEXT_PUBLIC_NEXT_PUBLIC_# Pull all env vars for the current environment into .env.local
vercel env pull .env.local
# Pull for a specific environment
vercel env pull .env.local --environment=production
vercel env pull .env.local --environment=preview
vercel env pull .env.local --environment=development
# Overwrite existing file without prompting
vercel env pull .env.local --yes
# Pull to a custom file
vercel env pull .env.production.local --environment=production# Interactive — prompts for value and environments
vercel env add MY_SECRET
# Non-interactive
echo "secret-value" | vercel env add MY_SECRET production
# Add to multiple environments
echo "secret-value" | vercel env add MY_SECRET production preview development
# Add a sensitive variable (encrypted, not shown in logs)
vercel env add MY_SECRET --sensitive# List all environment variables
vercel env ls
# Filter by environment
vercel env ls production# Remove from specific environment
vercel env rm MY_SECRET production
# Remove from all environments
vercel env rm MY_SECRET# 1) Link first so pulls target the correct Vercel project
vercel link --yes --project <name-or-id> --scope <team>
# 2) Pull env vars into .env.local
vercel env pull .env.local --yes
# 3) Verify required keys from .env.example exist in .env.local
while IFS='=' read -r key _; do
[[ -z "$key" || "$key" == \#* ]] && continue
grep -q "^${key}=" .env.local || echo "Missing in .env.local: $key"
done < .env.example.env.localvercel env run -- npm run dev.env.localvercel env addvercel env pull .env.local --yesVERCEL_OIDC_TOKENvercel env pull .env.localVERCEL_OIDC_TOKENvercel env pull .env.local --yes// The @vercel/oidc package reads VERCEL_OIDC_TOKEN automatically
import { getVercelOidcToken } from '@vercel/oidc'
// AI Gateway uses OIDC by default — no manual token handling needed
import { gateway } from 'ai'
const result = await generateText({
model: gateway('openai/gpt-5.2'),
prompt: 'Hello',
})| Symptom | Cause | Fix |
|---|---|---|
| Haven't pulled env vars | |
| Auth errors after ~12h locally | Token expired | |
| Works on Vercel, fails locally | Token not in | |
| Both set, key takes priority | Remove |
| Use Case | Where to Set |
|---|---|
| Secrets (API keys, tokens) | Vercel Dashboard ( |
| Public config (site URL, feature flags) | |
| Local-only overrides | |
| CI/CD secrets | Vercel Dashboard ( |
https://vercel.com/{team}/{project}/settings/environment-variablesvercel.appvercel devvercel env pull# Add a variable only for the "staging" branch
echo "staging-value" | vercel env add DATABASE_URL preview --git-branch=stagingvercel env pullvercel env pull .env.local# Save custom vars before pulling
grep -v '^#' .env.local | grep -v '^VERCEL_\|^POSTGRES_\|^NEXT_PUBLIC_' > .env.custom.bak
vercel env pull .env.local --yes
cat .env.custom.bak >> .env.local # Re-append custom vars.env.development.local.env.local.env.local.env.localdrizzle-kittsx# Use dotenv-cli
npm install -D dotenv-cli
npx dotenv -e .env.local -- npx drizzle-kit push
npx dotenv -e .env.local -- npx tsx scripts/seed.ts
# Or source manually
source <(grep -v '^#' .env.local | sed 's/^/export /') && node scripts/migrate.jsvercel env pull.env.exampleNEXT_PUBLIC_.env.development.localvercel env pull