# Invalid API Key error

**URL:** <https://forum.ipums.org/t/invalid-api-key-error/6451>\
**Category:** IPUMS API\
**Created:** [April 3, 2025, 6:07pm UTC](https://forum.ipums.org/t/invalid-api-key-error/6451 "2025-04-03T18:07:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![S\_D](https://avatars.discourse-cdn.com/v4/letter/s/aca169/32.png) [@S\_D](https://forum.ipums.org/u/S_D)\
**Post date:** [April 3, 2025, 6:07pm UTC](https://forum.ipums.org/t/invalid-api-key-error/6451/1 "2025-04-03T18:07:25Z")

</div>

Hi,

I’m a first-time user of IPUMS API and I keep getting an “Invalid API key” error while making a request.  
I double-checked the key I’m using and also revoked an existing one and created a new one but the issue persists.

---

<div class="post-metadata">

**Author:** ![fran](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.ipums.org/fran/32/363_2.png) [@fran](https://forum.ipums.org/u/fran)\
**Post date:** [April 7, 2025, 2:11pm UTC](https://forum.ipums.org/t/invalid-api-key-error/6451/2 "2025-04-07T14:11:21Z")

</div>

Please share your code so that we can help you debug, thanks!

---

<div class="post-metadata">

**Author:** ![Ivan\_Strahof](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.ipums.org/ivan_strahof/32/626_2.png) [@Ivan\_Strahof](https://forum.ipums.org/u/Ivan_Strahof)\
**Post date:** [April 10, 2025, 4:42pm UTC](https://forum.ipums.org/t/invalid-api-key-error/6451/3 "2025-04-10T16:42:25Z")

</div>

I’m glad that we were able to connect and troubleshoot the issue with your code. I’m sharing the resources that I mentioned in our conversation to help those using Python to submit their API calls better navigate this issue.

We provide a language-specific library in the form of [ipumspy](https://ipumspy.readthedocs.io/en/latest/index.html) that allows Python users to simplify their API calls. Our [Getting Started guide to ipumspy](https://ipumspy.readthedocs.io/en/latest/getting_started.html) begins by explaining how to initialize an API client using your API key before discussing how to create an extract definition. While discussing how to get an API key, the guide notes that we recommend storing your key in an environment variable in order to prevent it from being shared. The example code on the page therefore assumes that the API key is stored in an environment variable called IPUMS\_API\_KEY. If you have done so, then the IPUMS\_API\_KEY in:

> IPUMS\_API\_KEY = os.environ.get(“IPUMS\_API\_KEY”)

will be the string “IPUMS\_API\_KEY” that is saved as an environmental variable, not to be replaced with your actual key. If you decide not to hard-code your key, then this line can be replaced with:

> IPUMS\_API\_KEY = “REPLACE-WITH-YOUR-KEY”

We encourage ipumspy users who have reviewed our documentation and who are still having trouble to share their code so that we can help better troubleshoot their issue.

---

<div class="post-metadata">

**Author:** ![Martha\_Gimbel](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.ipums.org/martha_gimbel/32/1110_2.png) [@Martha\_Gimbel](https://forum.ipums.org/u/Martha_Gimbel)\
**Post date:** [April 22, 2025, 6:46pm UTC](https://forum.ipums.org/t/invalid-api-key-error/6451/4 "2025-04-22T18:46:54Z")

</div>

Hi! Can I ask what the solution was here? I’m having the same issue.

---

<div class="post-metadata">

**Author:** ![Ivan\_Strahof](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.ipums.org/ivan_strahof/32/626_2.png) [@Ivan\_Strahof](https://forum.ipums.org/u/Ivan_Strahof)\
**Post date:** [April 23, 2025, 9:03pm UTC](https://forum.ipums.org/t/invalid-api-key-error/6451/5 "2025-04-23T21:03:51Z")

</div>

Once you’ve [obtained your API key](https://account.ipums.org/api_keys), you should store it in an environment variable. See [these instructions](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#saving-environment-variables) for saving environment variables in conda environments for different operating systems. The sample code provided on our [Getting Started with ipumspy page](https://ipumspy.readthedocs.io/en/latest/getting_started.html) assumes that the API key is stored in an environment variable called _IPUMS\_API\_KEY_. Running the sample code without doing this will result in an error. You can alternatively directly input your API key by replacing

> IPUMS\_API\_KEY = os.environ.get(“IPUMS\_API\_KEY”)

with

> IPUMS\_API\_KEY = “REPLACE\_WITH\_YOUR\_ACTUAL\_KEY”
