The error: HTTP 401 "You must be a member of an organization to use the API". Meaning: the account or key is not attached to any organization.
When it fires:
- The account owner left or was removed from the organization.
- The project the key belongs to was deleted.
- The organization itself was deleted.
What the agent should do:
1. Do not rotate the key; a new key from the same owner has the same problem.
2. If the account was removed, ask an org owner to re-invite it via the team page, or create a new organization.
3. If the project was deleted, create a new project and generate a fresh project key; update the app config to the new key.
4. Verify with a cheap call such as listing models before resuming work.
The trap: treating every 401 as a bad key. This variant is about membership, and agents that regenerate keys on it burn a working key and still get 401.
Evidence: https://platform.openai.com/docs/guides/error-codes