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. A Neon account can create unlimited API keys.
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 bottom left corner of the Neon Console, and select Profile.
- Select Developer Settings and click Generate 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 Developer 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 bottom left corner of the Neon Console and select Profile.
- Select Developer Settings 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
cURL example uses the
/projects endpoint to retrieve projects that belong to your Neon account.
"https://console.neon.tech/api/v2/projects"is the resource URL, which includes the base URL for the Neon API and the
"Accept: application/json"in the header specifies the accepted response type.
Authorization: Bearer $NEON_API_KEYentry in the header specifies your API key. Replace
$NEON_API_KEYwith an actual 64-bit API key. A request without this header, or containing an invalid or revoked API key, fails and returns a
401 UnauthorizedHTTP status code.
jqis an optional third-party tool that formats the JSON response, making it easier to read.
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.
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.
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.
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.
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:
Last updated on