> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.beatapi.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.beatapi.io/_mcp/server.

# Bilibili returns HTTP 412 or WBI signature error: how to fix it

> Understand the difference between Bilibili HTTP 412 IP blocks and WBI signing (-352 / -403) errors, when a quick local header fix works, and when switching to BeatAPI ($0.003/request) saves time.

Bilibili returns two distinct anti-bot errors that have different causes:

* **HTTP `412 Precondition Failed`:** Your IP range, missing `User-Agent` or `Referer`, or missing `buvid3` cookie triggered Bilibili's edge firewall.
* **Business code `-352` or `-403` (WBI signing error):** Your `w_rid` and `wts` signature is missing or expired (the daily `img_key` / `sub_key` mixin rotated), or the endpoint requires a logged-in `SESSDATA` cookie.

For a small local script on a home IP, fixing headers and refreshing WBI keys can resolve both errors. For cloud servers (AWS, Aliyun, Cloudflare, GitHub Actions), scheduled jobs, and AI agents, BeatAPI handles Bilibili signing and IP reputation server-side across 87 Bilibili actions starting at `$0.003` per request (checked 2026-11-23; failed gateway calls cost `$0`).

## Quick diagnosis: local fix vs. BeatAPI

| Symptom                                   | Likely cause                                                   | Local fix to try first                                                                                                  | When to switch to BeatAPI                                           |
| ----------------------------------------- | -------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- |
| `HTTP 412` on first request               | Datacenter IP or default `python-requests` User-Agent          | Add a real browser `User-Agent`, `Referer: https://www.bilibili.com/`, and fetch `buvid3` from `/x/frontend/finger/spi` | Still hits `412` from a cloud VPS or CI runner                      |
| `code: -352` or `-403` on search/comments | Missing or expired WBI (`w_rid` + `wts`) or missing `SESSDATA` | Re-fetch `img_url` and `sub_url` from `/x/web-interface/nav` and recompute MD5 `w_rid`                                  | You do not want personal `SESSDATA` cookies on a server             |
| Works locally, breaks in production       | Cloud IP range is rate-limited by Bilibili                     | Requires residential proxies                                                                                            | Switch immediately (`$0.003` per call costs less than a proxy pool) |

## Call Bilibili actions through BeatAPI

BeatAPI serves Bilibili search, video details, and comments over `POST https://api.beatapi.io/v1/social-data/call` and remote MCP (`https://beatapi.io/mcp`) without `buvid3`, WBI signing, or `SESSDATA`:

**`Search videos ($0.003)`**

```bash title="Search videos ($0.003)"
curl -sS https://api.beatapi.io/v1/social-data/call \
  -H "Authorization: Bearer $BEATAPI_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"action":"bilibili.web.fetch_general_search","params":{"keyword":"Rust 教程","order":"click","page":1,"page_size":20}}'
```

**`Video detail ($0.003)`**

```bash title="Video detail ($0.003)"
curl -sS https://api.beatapi.io/v1/social-data/call \
  -H "Authorization: Bearer $BEATAPI_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"action":"bilibili.web.fetch_one_video","params":{"bv_id":"BV1xx411c7mD"}}'
```

**`Video comments ($0.003)`**

```bash title="Video comments ($0.003)"
curl -sS https://api.beatapi.io/v1/social-data/call \
  -H "Authorization: Bearer $BEATAPI_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"action":"bilibili.app.fetch_video_comments","params":{"bv_id":"BV1xx411c7mD","mode":3,"next_offset":1}}'
```

Check live inputs and pricing for `$0` via `POST /v1/capabilities/inspect` or [BeatAPI pricing](https://beatapi.io/pricing).

## Related

* [Bilibili error -352, -3 & HTTP 412 recovery](/faq/bilibili-research-recovery)
* [Bilibili Python search and comments guide](/guides/bilibili-python-research)
* [Bilibili FAQ](/faq/bilibili)
* [MediaCrawler alternative](/faq/mediacrawler-alternative)