Tutorial
Set up a NEON API Token
Last Updated: Mar 20, 2026
Authors: Claire K. Lunch
Last Updated: Mar 20, 2026
This tutorial covers how to get a NEON API token and set it as an environment variable in your coding environment. It is intended for users who want to get their tokens set up quickly and efficiently. For a longer and broader overview of NEON user accounts and token management, see the tutorial on how to use a token with neonUtilities.
The first step is create a NEON user account, if you don’t have one. Follow the instructions on the Data Portal User Accounts page. If you already have an account, go to the NEON Data Portal, sign in, and go to your My Account profile page.
Once you have an account, you can create an API token for yourself. At the bottom of the My Account page, you should see this bar:
Click the ‘GET API TOKEN’ button. After a moment, you should see this:
Click on the Copy button to copy your API token to the clipboard:
To create a persistent environment variable in R, we use a
.Renviron file. The usethis package has a
handy function to open the file for your active environment:
usethis::edit_r_environ()
The .Renviron file should now be open. Add a new line to
it:
NEON_TOKEN=PASTE YOUR TOKEN HERE
Save the file and re-start R. You can now retrieve the token anytime
you are working in this environment using the function
Sys.getenv().
token <- Sys.getenv("NEON_TOKEN")
To create a persistent environment variable in Python, the simplest
option is to use the dotenv module.
This code chunk is run in the command line of your project environment:
pip install python-dotenv
touch .env
This will create a file named .env in the project
folder. If you’re using GitHub, make sure .env is in your
.gitignore to avoid syncing tokens to GitHub.
To add variables to the .env file, move over to the
Python console.
import dotenv
import os
dotenv.set_key(dotenv_path=".env",
key_to_set="NEON_TOKEN",
value_to_set="PASTE YOUR TOKEN HERE")
Use the command dotenv.load_dotenv() to load environment
variables to the session, then use os.environ.get() to
access particular variables.
dotenv.load_dotenv()
token = os.environ.get("NEON_TOKEN")
If dotenv.load_dotenv() returns False, the
variables did not load. If that happens, try
dotenv.load_dotenv(dotenv.find_dotenv(usecwd=True)).
You are now ready to use your token in your code!