I set up .env file and gatsby-config.js as below.
// .env.development GATSBY_API_URL=https://example.com/api
you may add your env key to the allow list in gatsby-config.js
{ resolve: `gatsby-plugin-env-variables`, options: { allowList: [ "XXXXXXXXX", ] } }