Manage API Keys
Most actions performed in the Neon Console can be performed using the Neon API. Using the Neon API requires an API key. This topic describes how to generate, revoke, and use API keys.
API keys are global and belong to your Neon account. They can be used with any project that belongs to your Neon account. While there is no strict limit on the number of API keys you can create, we recommend keeping it under 10,000 per Neon account.
Create an API key
An API key (or token) is a randomly-generated 64-bit key that you must provide when calling Neon API methods. An API key remains valid until it is revoked.
To generate an API key:
- Log in to the Neon Console.
- Click your account in the top right corner of the Neon Console, and select Account settings.
- Select API keys and click Create new API Key.
- Enter a name for the API key.
- Click Create and copy the generated key.
Store your key in a safe location. You will not be able to view or copy the key again after leaving the Account settings page. You can safely store an API key in a locally installed credential manager or in a credential management service such as the AWS Key Management Service. If you lose an API key, revoke it and generate a new one.
Revoke an API key
An API key that is no longer needed can be revoked. This action cannot be reversed.
To revoke an API key:
- Click your account in the top right corner of the Neon Console and select Account settings.
- Select API keys to see a list of API keys.
- To revoke a key, click Revoke. The key is immediately revoked. Any request that uses the key now fails.
Make an API call
The following cURL
example uses the /projects
endpoint to retrieve projects that belong to your Neon account.
where:
"https://console.neon.tech/api/v2/projects"
is the resource URL, which includes the base URL for the Neon API and the/projects
endpoint.- The
"Accept: application/json"
in the header specifies the accepted response type. - The
Authorization: Bearer $NEON_API_KEY
entry in the header specifies your API key. Replace$NEON_API_KEY
with an actual 64-bit API key. A request without this header, or containing an invalid or revoked API key, fails and returns a401 Unauthorized
HTTP status code. jq
is an optional third-party tool that formats the JSON response, making it easier to read.
Response body
Refer to the Neon API reference for other supported Neon API methods.
Manage API keys with the Neon API
API key actions performed in the Neon Console can also be performed using the Neon API. The following examples demonstrate how to create, view, and revoke API keys using the Neon API.
Prerequisites
You can create and manage API keys using the Neon API, but you need an API key to start with. You can obtain an API key from the Neon Console. For instructions, see Create an API key. In the examples shown below, $NEON_API_KEY
is specified in place of an actual API key, which you must provide when making a Neon API request.
The jq
option specified in each example is an optional third-party tool that formats the JSON response, making it easier to read. For information about this utility, see jq.
Create an API key with the API
The following Neon API method creates an API key. To view the API documentation for this method, refer to the Neon API reference.
The API method appears as follows when specified in a cURL command. You must specify the key_name
attribute and a name for the API key.
The response body includes an id
for the key and a generated 64-bit key
value, which can be used to access the Neon API. API keys should stored and managed securely, as they provide access to all objects in your Neon account.
Response body
List API keys with the API
The following Neon API method lists API keys for your Neon account. To view the API documentation for this method, refer to the Neon API reference.
The API method appears as follows when specified in a cURL command. No parameters are required.
Response body
Revoke an API key with the API
The following Neon API method revokes the specified API key. The key_id
is a required parameter. To view the API documentation for this method, refer to the Neon API reference.
The API method appears as follows when specified in a cURL command:
Response body
Need help?
Join our Discord Server to ask questions or see what others are doing with Neon. Users on paid plans can open a support ticket from the console. For more details, see Getting Support.