# Instagram User ID Lookup API

> Convert an Instagram username to its numeric user id with one API call. Returns the id plus the full public profile (name, bio, counts, picture) as JSON, for 1 credit.

**Turn an Instagram username into its numeric user id** with one call. You get the id together with the full public profile (name, bio, counts, picture). Ids never change when an account renames itself, so store the id and use it in later calls, for example with [profile by id](/docs/instagram-profile-api).

```
GET https://api.klupt.io/v1/users/by-username/{username}
```

**Cost:** 1 credit per successful call (0.5 if served from cache). Failed calls are free.

## Parameters

| Parameter | In | Description |
|---|---|---|
| `username` | path | Instagram username, with or without `@`. Letters, digits, `.` and `_`, up to 30 characters. Always read as a username, even if it is all digits. |
| `fresh` | query | `true` skips the cache and fetches live (full price). |

## Response

```json
{
  "data": {
    "id": "25025320",
    "username": "instagram",
    "full_name": "Instagram",
    "is_private": false,
    "is_verified": true,
    "profile_pic_url": "https://scontent.cdninstagram.com/…/profile.jpg",
    "biography": "Bringing you closer to the people and things you love.",
    "external_url": "https://about.instagram.com",
    "category": "Product/service",
    "is_business": true,
    "profile_pic_url_hd": "https://scontent.cdninstagram.com/…",
    "counts": { "followers": 690000000, "following": 180, "posts": 7900 }
  },
  "meta": { "request_id": "req_8Hn2…", "cached": false, "cache_age_seconds": 0, "credits_charged": 1, "credits_remaining": 26949 }
}
```

`id` is a string because Instagram ids can be larger than 2^53.

## Examples

```bash
curl "https://api.klupt.io/v1/users/by-username/instagram" -H "X-Api-Key: $KLUPT_API_KEY"
```

```python
import os, requests
r = requests.get("https://api.klupt.io/v1/users/by-username/instagram",
                 headers={"X-Api-Key": os.environ["KLUPT_API_KEY"]}, timeout=30)
user_id = r.json()["data"]["id"]
```

```javascript
const r = await fetch("https://api.klupt.io/v1/users/by-username/instagram", {
  headers: { "X-Api-Key": process.env.KLUPT_API_KEY },
});
const { data } = await r.json();
console.log(data.id);
```

## Errors

| Status | Code | When |
|---|---|---|
| 404 | `user_not_found` | No account with that username (free) |
| 400 | `invalid_request` | The username has characters Instagram does not allow |

See all [error codes](/docs/errors).

## FAQ

### How do I find an Instagram user id from a username?
Call `GET /v1/users/by-username/{username}` with your API key. The `data.id` field is the numeric Instagram user id.

### Does the user id change when someone changes their username?
No. The numeric id stays the same for the life of the account, which is why it is the best key to store.
