---
"@context": https://schema.org
"@type": TechArticle
"@id": https://www.twilio.com/docs/sendgrid/ui/account-and-settings/api-keys#article
headline: API Keys
description: Create, manage, store, and test Twilio SendGrid API keys to authenticate access to Twilio SendGrid services and set permission scopes for each key.
url: https://www.twilio.com/docs/sendgrid/ui/account-and-settings/api-keys
inLanguage: en
dateModified: 2026-08-14T19:01:57.000Z
author:
  "@type": Organization
  name: Twilio Developer Education Team
publisher:
  "@type": Organization
  name: Twilio
---

# API Keys

> \[!WARNING]
>
> * Twilio supports a key longer than 69 characters. No exceptions can be made for third-party infrastructure.
> * Twilio limits accounts to 100 API keys.
> * You can't give an API key greater permissions than your own.
> * The Twilio SendGrid Console displays the API key only once at creation.
> * Treat your API key like a password and store it somewhere safe.
> * Twilio can't retrieve or restore an unknown or deleted API key.

To authenticate access to Twilio SendGrid services, use *Application Programming Interface* (API) keys.

They are the preferred alternative to using a username and password because you can revoke an API key at any time without having to change your username and password. We suggest that you use API keys for connecting to all of SendGrid's services.

## Manage API keys

Go to **Settings** > [**API Keys**][tsc-apikeys]. The **API Keys** page displays your current API keys with the following parameters:

| Parameter  | Purpose                                                                        |
| ---------- | ------------------------------------------------------------------------------ |
| Name       | The name you defined for your API key.                                         |
| API Key ID | The way you would reference your API key for management through the API.       |
| Action     | Actions you can perform on your API keys, such as editing or deleting the key. |

### Create an API key

To use the Mail API, you need an API key.

1. Go to **Settings** > [**API Keys**][tsc-apikeys]. The **API Keys** page appears.
2. Click **Create API Key**. The **Create API Key** appears.
3. Type a human-readable name for your API key in the **API Key Name** box.
4. Choose the permissions for your API Key:

   | API key permission                  | Access details for account                                                                                       |
   | ----------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
   | **Full Access**                     | Grants all API endpoints **full access** to your account.                                                        |
   | **Custom Access**                   | Choose both which API endpoints and which access levels each have to your account.                               |
   | **Billing Access**                  | Grants all billing API endpoints **full access** to your account.                                                |
   | **Email Address Validation Access** | Grants **read access** to the reporting console and **full access** to validation API endpoints on your account. |

   #### View all access details for custom access

   * API Keys
   * Alerts
   * Category Management
   * Deliverability Insights
   * Design Library
   * Email Activity
   * Email Testing
   * IP Management
   * Inbound Parse
   * Mail Send
     * Mail Send
     * Scheduled Sends
   * Mail Settings
     * Address Allow List
     * BCC
     * Bounce Purge
     * Event Notification
     * Footer
     * Forward Bounce
     * Forward Spam
     * Legacy Email Template
     * Mail Settings
     * Plain Content
     * Spam Checker
   * Marketing
     * Automation
     * Marketing
   * Marketing Campaigns
   * Partners
   * Recipients Data Erasure
   * SSO Settings
   * Security
   * Sender Authentication
   * Stats
     * Browser Stats
     * Category Stats
     * Email Clients and Devices
     * Geographical
     * Global Stats
     * Mailbox Provider Stats
     * Parse Webhook
     * Stats Overview
     * Subuser Stats
   * Subusers
   * Suppressions
     * Suppressions
     * Unsubscribe Groups
   * Teammates
     * SSO Teammates
     * Teammates
   * Template Engine
   * Tracking
     * Click Tracking
     * Google Analytics
     * Open Tracking
     * Subscription Tracking
     * Tracking Settings
   * User Account
     * Account Profile
     * Enforced TLS
     * Timezone
     * User Profile
5. Click **Create & View**. The **API Key Created** page displays your created API Key.
6. To copy the API key, click on it.
   * Store this key somewhere not in the public view.
   * Never include your API Key in your code or commit it to a public location or repository like GitHub.

To make billing-related API calls, Twilio requires [a separate API key](#create-an-api-key).
By providing greater control over who has access to the responsibilities associated with your account, this segmentation improves security.

### Store your API key in an environment variable

To further improve account security, store your API key in a local environment variable. This limits access to the API to individuals with the API key stored on their local environment. Supported programming languages can read environment variables for the API key values.

This section stores your key in a local environment variable named `SENDGRID_API_KEY`.

To store your Twilio SendGrid API key, open your command line and run the following command, replacing `YOUR_API_KEY` with the API key you created and saved in the [previous section](#create-an-api-key):

## macOS Terminal

```bash
export SENDGRID_API_KEY=YOUR_API_KEY
```

## Windows command line

```bash
setx SENDGRID_API_KEY=YOUR_API_KEY
```

## PowerShell

```bash
[System.Environment]::SetEnvironmentVariable("SENDGRID_API_KEY", "YOUR_API_KEY", "User")
```

To access the variable in your app, follow the convention from your programming language.

## Python

```python {title="Read the API key in Python"}
api_key = os.environ.get('SENDGRID_API_KEY')
```

## Node.js

```javascript {title="Read the API key in Node.js"}
const apiKey = process.env.SENDGRID_API_KEY;
```

## PHP

```php {title="Read the API key in PHP"}
$apiKey = getenv('SENDGRID_API_KEY');
```

## C# or .NET

```csharp {title="Read the API key in C#"}
var apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
```

## Java

```java {title="Read the API key in Java"}
apiKey = System.getenv("SENDGRID_API_KEY");
```

## Ruby

```ruby {title="Read the API key in Ruby"}
api_key = ENV['SENDGRID_API_KEY']
```

## Go

```go {title="Read the API key in Go"}
apiKey := os.Getenv("SENDGRID_API_KEY")
```

## Edit your API key

To change the human-readable name or the permission levels of an API key, follow this procedure:

1. Go to **Settings** > [**API Keys**][tsc-apikeys]. The **API Keys** page appears.
2. Click the action menu, then **Edit API Key** for the key you want to edit. The **Edit API Key** panel displays.
3. From this panel, you can change the name or permission levels of your key.
4. When finished making changes, click **Update**. The **API Key** page displays.

## Delete your API key

To change the human-readable name or the permission levels of an API key, follow this procedure:

1. Go to **Settings** > [**API Keys**][tsc-apikeys]. The **API Keys** page appears.
2. Click the action menu, then **Delete API Key** for the key you want to delete. The **Delete API Key?** modal displays.
3. Click **Confirm**. The **API Key** page displays without the deleted API key.

Twilio SendGrid rejects any subsequent API calls made using this deleted API key.

## Replace your API key

To replace your API key, follow this procedure:

1. [Delete your API key](#delete-your-api-key).
2. [Create an API key](#create-an-api-key).
3. Replace the old API key with the new one in your code.

## Test your API key

To test your created API key, use cURL:

```bash {title="Test an API key against the Mail Send endpoint"}
curl -i --request POST \
        --url https://api.sendgrid.com/v3/mail/send \
        --header 'Authorization: Bearer YOUR_API_KEY_HERE' \
        --header 'Content-Type: application/json' \
        --data '{
                  "personalizations": [
                    {
                      "to": [
                        {
                          "email": "recipient@example.com"
                        }
                      ]
                    }
                  ],
                  "from": {
                    "email": "sendeexampexample@example.com"
                  },
                  "subject": "Hello, World!",
                  "content": [
                    {
                      "type": "text/plain",
                      "value": "Howdy!"
                    }
                  ]
                }'
```

Look for a **202 Accepted** in the HTTP response headers.

[tsc-apikeys]: https://app.sendgrid.com/settings/api_keys
