# Bilibili profile picture API

> Get any Bilibili profile picture from one image URL: avatarsapi.com/bilibili/<handle>. No Bilibili API key, no scraping code.

Put a Bilibili Handle in the URL and the response is the profile picture as image bytes, ready for an `<img src>`. avatarapi fetches it from Bilibili, checks it is a real image, and caches it at the edge.

```html
<img src="https://avatarsapi.com/bilibili/2" alt="">
```

## What goes in the URL

`https://avatarsapi.com/bilibili/<handle>`

The numeric user id (mid) from `space.bilibili.com/<mid>`.

Accounts with no picture are a Miss, not Bilibili's shared placeholder.

Percent-encode the Handle if it contains a `/`, a space, or other reserved characters.

## Options

- `?size=16..1000` sets the square size in pixels (default 400): `https://avatarsapi.com/bilibili/2?size=64`
- `?json` returns the resolved image URL instead of the bytes:

```json
{ "version": 1, "data": { "url": "https://…", "source": "bilibili", "kind": "username" } }
```

Starter Projects can also set `?ttl=1h..28d` for the cache lifetime (default 7 days).

## When there is no picture

If the account does not exist or has no profile picture, the response is a 404 with a JSON body whose `code` is `ENOTFOUND`. That makes `onerror` a reliable fallback:

```html
<img
  src="https://avatarsapi.com/bilibili/2"
  onerror="this.onerror=null; this.src='/default-avatar.svg'"
  alt="">
```

`EUPSTREAM` (502) means Bilibili itself failed or changed; it is usually transient. All codes are in the [error table](https://avatarsapi.com/docs#errors).

## Related

- [Bluesky profile picture API](/platforms/bluesky)
- [Buy Me a Coffee profile picture API](/platforms/buymeacoffee)
- [Cash App profile picture API](/platforms/cashapp)
- [CodePen profile picture API](/platforms/codepen)
- [All 67 platforms](/platforms/)
