How do I convert a Bilibili BV ID to an AV number (aid)?

BV IDs and AV numbers (aid) are two encodings of the same video number, so you can convert them offline. The current algorithm XORs the aid with 23442827791579, writes it in base 58 with Bilibili's alphabet and swaps fixed positions; the old 2020 constants only work for small aids. A known pair to test with: AV170001 is BV17x411w7KC. XTikAPI reads Bilibili with 10 endpoints from $0.002 a call. A failed call is not charged, and a verified account gets $0.5 of trial balance.

Updated 2026-11-18

Which algorithm to use

The 2020-era method (XOR 177451812, add 8728348608, base 58) only covers aids up to about 2^28. Bilibili-API-collect issue #847 documents the newer version with XOR code 23442827791579, mask 2251799813685247 and a 2^51 ceiling; the Rust amagi crate and the abv libraries implement it.

When you need more than the number

Conversion gives you an ID, not the video. bilibili.videos.detail takes the bv_id and returns title, uploader and counts; bilibili.comments.list returns its comments. Some Bilibili endpoints, such as subtitles, want the aid plus the cid of a part, which the detail call also returns.

Why XTikAPI

  • One API key for Bilibili and every other supported platform, with the same JSON shape: data holds the result, meta says what was billed.
  • A failed call or a timeout is not charged; the response says charged: false.
  • X-Max-Price caps what one call may cost, and the same Idempotency-Key within 24 hours is never billed twice.
  • Prepaid balance, no subscription. Balance never expires, and unused top-up money can be refunded within 14 days.

Endpoints

More about Bilibili

Sources