# How to Call SendGrid API from Frontend Without Exposing API Key

> SendGrid API keys must never be exposed client-side. RealComposer acts as an edge gateway that validates the incoming message, injects your SendGrid Bearer token server-side, and prevents unauthorized outbound email spam.

- Canonical page: https://realcomposer.com/recipes/sendgrid-frontend-proxy
- Client platform: React / Webflow
- Upstream services: SendGrid
- Category: Security & Secret Vault
- JSON version: https://realcomposer.com/recipes/sendgrid-frontend-proxy.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=sendgrid-frontend-proxy&via=agent

## Problem: SendGrid Key Leaks Turn Sites into Spam Relays

Exposed SendGrid keys are immediately seized by spam bots to blast phishing emails, causing domain blacklisting.

- Domain reputation destruction on Spamhaus
- Instant SendGrid account termination
- High overage billing

## Solution steps

1. **Vault Your SendGrid Key**: Store SENDGRID_API_KEY in RealComposer Secret Vault.

2. **Send from Contact Form**: Post form submissions to RealComposer edge route.

## Pipeline config

Import this config into a RealComposer pipeline. `{{secrets.NAME}}` values are read from the encrypted Secret Vault at request time, so the client never sees them.

```json
{
  "name": "SendGrid Edge Proxy",
  "method": "POST",
  "cacheTtlSeconds": 0,
  "steps": [
    {
      "stepKey": "sendgrid",
      "upstreamUrlTemplate": "https://api.sendgrid.com/v3/mail/send",
      "httpMethod": "POST",
      "headersTemplate": {
        "Authorization": "Bearer {{secrets.SENDGRID_API_KEY}}"
      },
      "timeoutMs": 4000
    }
  ],
  "outputMapping": {
    "version": 1,
    "fields": [
      {
        "targetPath": "status",
        "sourceStep": "sendgrid",
        "sourcePath": "statusCode"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X POST "https://realcomposer.com/v1/acme/send-email"
```

## Payload before and after

Raw upstream response:

```json
{
  "statusCode": 202,
  "headers": {}
}
```

Slimmed RealComposer response:

```json
{
  "status": 202
}
```

## FAQ

### Does RealComposer rate limit requests?

Yes, per-client token rate limits protect against automated spam abuse.
