# Classify and label new Gmail messages with OpenAI GPT-4o-mini

> Quick overview This workflow triggers on new Gmail messages, sends key email details to OpenAI for classification, parses the JSON result, and applies a matching Gmail label to each email based on the predicted category. How it works 1. Triggers every minute when a new email arrives in Gmail. 2. Sets the OpenAI model, a classification prompt, and a mapping of categories to Gmail label IDs. 3. Calls the OpenAI Chat Completions API with the email subject, sender, and a truncated body to classify the message. 4. Parses the JSON response to extract category, urgency, and a short summary, defaulting to “noise” if parsing fails. 5. Adds the corresponding Gmail label to the original email message based on the returned category. Setup 1. Connect your Gmail account credentials for both the Gmail trigger and the Gmail label action. 2. Add an OpenAI API key using HTTP Header Auth for the OpenAI Chat Completions request. 3. Create the target labels in Gmail, copy their label IDs, and replace the p

- **Domain**: `n8n-workflow-19459.n8n.io`
- **Provider**: n8n.io (https://n8n.io)
- **Kind**: workflow
- **Live-responds (last probe)**: None
- **Signed card**: False
- **Streaming**: False
- **Quality score**: 40%

## URLs
- Agent card: https://n8n.io/workflows/19459
- Page (HTML): https://agenstry.com/agents/n8n-workflow-19459.n8n.io
- Documentation: https://n8n.io/workflows/19459
