SendGrid supports API keys delivered via Bearer token or Basic authentication, depending on the SendGrid functionality you are using. In addition to Bearer API key authentication, SendGrid recommends two-factor authentication (2FA) to improve security.
Authenticate to the SendGrid API by creating an API Key in the Settings section of the SendGrid UI.
SendGrid requires using API keys because they are a secure way to talk to the SendGrid API that is separate from your username and password. If your API key gets compromised, it's easy to delete and create a new API key and update your environment variables with the new key. API key permissions can be set to provide access to different functions of your account, without providing access to your account as a whole.
To use an API key, pass an Authorization header with a value of
Bearer <Your-API-Key-Here>, where you replace
<Your-API-Key-Here> with the API Key that you created in the UI.
GET https://api.sendgrid.com/v3/resource HTTP/1.1 Authorization: Bearer <Your-API-Key-Here>
curl -X "GET" "https://api.sendgrid.com/v3/templates" -H "Authorization: Bearer <Your-API-Key-Here>" -H "Content-Type: application/json"
SendGrid supports Basic Authentication using an API key as your password value for some services. When using Basic Authentication, your username will always be "apikey," and your password will be your API key.
To ensure the security of your account, Twilio SendGrid has ended support for basic authentication with username and password as of Q4 2020.
Using basic authentication with your account password is not as secure as using an API key. If your credentials are compromised—for example, if you accidentally commit them to version control—it is more difficult to regain the security of your account when those credentials are your username and password rather than an API key. For this reason, Twilio SendGrid no longer supports authentication via username and password.
Enabling two-factor authentication (2FA) will allow Twilio SendGrid to deliver confirmation codes via SMS to your mobile phone. You will not be able to log in when cellular service is not available. SMS 2FA is powered by Authy. Selecting this option does not require an Authy account, but if you have one, you will be able to use either the Authy App or SMS messages.
To ensure the security of your account, SendGrid requires enabling two-factor authentication (2FA) for all users. For more information about setting up 2FA, see Two-factor authentication.
It is not possible to use basic authentication for users, subusers, or teammates that enable 2FA.