# API Key doesn't work with Python

**URL:** <https://forum.intervals.icu/t/api-key-doesnt-work-with-python/133348>\
**Category:** Uncategorized\
**Created:** [30 October 2026 15:35 UTC](https://forum.intervals.icu/t/api-key-doesnt-work-with-python/133348 "2026-10-30T15:35:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tanguy\_Flao](https://forum.intervals.icu/user_avatar/forum.intervals.icu/tanguy_flao/32/74238_2.png) [@Tanguy\_Flao](https://forum.intervals.icu/u/Tanguy_Flao)\
**Post date:** [30 October 2026 15:35 UTC](https://forum.intervals.icu/t/api-key-doesnt-work-with-python/133348/1 "2026-10-30T15:35:20Z")

</div>

Hello,

I am trying to access my own Intervals.icu data through the public API.

I generated a new API key in Settings → Developer Settings.

I am using:

- Username: API\_KEY

- Password: my personal API key

- Endpoint: GET [https://intervals.icu/api/v1/athlete/0](https://intervals.icu/api/v1/athlete/0)

Both Python requests and curl return HTTP 401 Unauthorized.

I have regenerated the API key and checked the authentication format.

Could you help me identify why my API key is being rejected?

Thank you.

---

<div class="post-metadata">

**Author:** ![Mustafa742](https://forum.intervals.icu/letter_avatar_proxy/v4/letter/m/a3d4f5/32.png) [@Mustafa742](https://forum.intervals.icu/u/Mustafa742)\
**Post date:** [30 October 2026 15:36 UTC](https://forum.intervals.icu/t/api-key-doesnt-work-with-python/133348/2 "2026-10-30T15:36:45Z")

</div>

The issue is the username. You have it backwards.

The username must be the literal string `API_KEY`, and the password is your personal key. You wrote “Username: API\_KEY” and “Password: my personal API key”, which sounds right, but the 401 suggests the actual request isn’t using that format.

In Python `requests`, you need **Basic Auth** , not Bearer:

python

```auto
import requests

API_KEY = "your_personal_key_here"
ATHLETE_ID = "0"

url = f"https://intervals.icu/api/v1/athlete/{ATHLETE_ID}"
response = requests.get(url, auth=("API_KEY", API_KEY))

```

The key detail: `auth=("API_KEY", API_KEY)` means the username is literally the string `"API_KEY"` (not your athlete ID, not a variable), and the password is your actual key from Settings .

If you’re still getting 401 after that, double-check you haven’t accidentally set a Bearer header somewhere else in your code, since that will override Basic Auth .

---

<div class="post-metadata">

**Author:** ![R2Tom](https://forum.intervals.icu/user_avatar/forum.intervals.icu/r2tom/32/50144_2.png) [@R2Tom](https://forum.intervals.icu/u/R2Tom)\
**Post date:** [30 October 2026 15:37 UTC](https://forum.intervals.icu/t/api-key-doesnt-work-with-python/133348/3 "2026-10-30T15:37:38Z")

</div>

> [@Tanguy\_Flao](#):
>
> Both Python requests and curl return HTTP 401 Unauthorized

Please Show an example, you can black out part of the API key.  
Usually it has nothing to do with the script language
