# Use an API key

Send a key with each call, and the CLI, your code and the API act as you.

## Before you start

You need an API key. See [Create an API key](/docs/authentication/api-keys.md).

## Use an API key

**Code**

1. Add [your key](/docs/authentication/api-keys.md) to your project's `.env`:

```bash title=".env"
VERYFRONT_API_KEY=vf_…
```

2. Check who the CLI is. You should now see `✓ Authenticated with an API key`:

```bash
npx veryfront whoami
```

**REST**

1. Set `VERYFRONT_API_KEY` to [your key](/docs/authentication/api-keys.md): `export VERYFRONT_API_KEY=vf_…`
2. Call the API with it. You should now see `200`:

```bash
curl -s -o /dev/null -w "%{http_code}\n" "https://api.veryfront.com/projects?limit=1" \
  -H "Authorization: Bearer $VERYFRONT_API_KEY"
```

`X-API-Key: $VERYFRONT_API_KEY` works in place of the `Authorization` header.

### Troubleshooting

**If the API says "Missing or invalid Authorization header"**, the call sent no key. Check that `VERYFRONT_API_KEY` is set in this shell.

**If the API says "Invalid or expired API key"**, the key is not one Veryfront knows. Check it for a typo, or create a new one.

See the [Authentication reference](/docs/reference/authentication.md).

## With MCP

1. Call `veryfront__get_current_user`. The MCP connection is the key you sent. It worked when the answer holds your user's profile.

## Next steps

* [Revoke an API key](/docs/authentication/revoke-access.md)
* [Connect a coding agent](/docs/mcp/connect.md)
