## TL;DR
Set the API key in the environment the process actually runs in: Comet reads COMET_API_KEY at import time, so export it for the training process, or set it in the project configuration, and confirm the process can see it before starting the experiment. The experiment fails at creation because Comet finds no key in its environment. Keys set in a different shell, a notebook kernel that predates the export, or a scheduler that scrubs environment variables all produce the same error.

```text
Comet experiment failed error "COMET_API_KEY environment variable is not set"
```

## Use this when
- The check or run fails with this symptom: a Comet experiment fails with COMET_API_KEY environment variable is not set.
- You are working on a Comet ML experiment started from a script, a notebook, or a scheduled training job and the failure repeats on the same data or configuration.
- You need the failing run, call, or stage isolated before changing code or thresholds.

## Not for this skill when
- A key that is set but invalid, which fails later with an authentication response rather than this message.
- The error text names a different tool, stage, or root cause. Match the verbatim error first and use that skill.

## Steps
1. Print whether the variable is present from inside the training process, without printing its value. Verify: the process environment lacks the variable, confirmed from inside
2. Set the variable in the launcher that starts training: the shell profile, the job definition, or the notebook kernel environment. Verify: the variable is part of the process environment
3. Alternatively store the key through the Comet configuration command for the user account. Verify: Comet reports a configured key
4. Restart the process or kernel so the new environment is picked up. Verify: a fresh process sees the variable
5. Start a minimal experiment. Verify: the experiment is created and appears in the Comet workspace

## Variant phrasings
### comet COMET_API_KEY environment variable is not set
The shorter phrasing focused on the named failure.
### comet experiment failed api key not set
The symptom phrasing a searcher tries next.
### comet api key environment fix
The variant naming the failing stage or tool directly.

Compatibility: Comet ML Python client, environment based configuration

## Why it happens
Comet reads its key once, at client initialisation, from the process environment. Interactive setup steps often set the key in a shell the training job never inherits, especially under schedulers, containers, and notebook kernels started before the export.

## Edge cases / pitfalls
- Never commit the key into the training script or a repository config to make the error go away; use the job secret store.
- Rotating a key in the Comet UI does not update running jobs; they keep failing until their environment is refreshed.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_3Snt9bCYg-tfFdaiLEtAZQ
