# Convex Environment Variables Reference

# Environment Variables

## System variables (always available in Convex functions)

```ts
process.env.CONVEX_CLOUD_URL; // https://your-deployment.convex.cloud
process.env.CONVEX_SITE_URL; // https://your-deployment.convex.site
```

*   `CONVEX_CLOUD_URL` — for Convex clients (queries, mutations, subscriptions)
    
*   `CONVEX_SITE_URL` — for HTTP actions
    

## Setting custom env variables

```bash
# Dev
npx convex env set MY_API_KEY some-secret-value

# Production
npx convex env set MY_API_KEY prod-secret-value --prod
```

Or set them in the Convex dashboard under Deployment Settings.

## Accessing in Convex functions

```ts
const apiKey = process.env.MY_API_KEY; // string or undefined
```

## Client-side env variables (Vite)

Convex URLs are not automatically available in your React code. Set them in your `.env` file.

```bash
# .env
VITE_CONVEX_URL=https://your-deployment.convex.cloud
```

If you need the `.site` URL on the client you can derive it:

```tsx
const CONVEX_SITE_URL = import.meta.env.VITE_CONVEX_URL.replace(
  ".cloud",
  ".site",
);
```

Or add a separate env variable:

```bash
# .env
VITE_CONVEX_SITE_URL=https://your-deployment.convex.site
```
