For AI

Answers

How do Bilibili BV and AV numbers relate, and which one should I store?

Short answer

They are two spellings of the same video: the BV id is a reversible encoding of the numeric aid (the AV number), so you can convert either way locally for free. Store the BV id as your key, because links, share URLs and okdata Bilibili video detail ($0.002 a call) all use it, and keep the aid from ext.aid as a second column for older datasets.

Every Bilibili video has a numeric archive id, the aid, which used to appear in links as av170001. On 23 March 2020 Bilibili switched its links to BV ids such as BV17x411w7KC. The BV id is not a new key: it is the aid run through a fixed, reversible encoding. One video, one aid, one BV id, and you can turn either into the other with a few lines of code and no network call.

What each one looks like

AV number (aid) BV id (bvid)
Shape A positive integer, written av + digits in old links BV1 + 9 characters, 12 in total
Characters 0-9 A 58-character alphabet without 0, I, O and l
Where you see it Old links, comment-area mentions, many older datasets Every current link, share link and app screen
In okdata responses ext.aid (with view=full) id of every Bilibili post

Not to be confused with cid, which numbers each part of a multi-part video (ext.cid on video detail), or the ep/ss numbers of anime and drama episodes.

How the conversion works

The current algorithm handles aids up to 2^51. To encode, set bit 51 on the aid, XOR it with 23442827791579, write the result in base 58 with the alphabet FcwAPNKTMug3GV5Lj7EJnHpWsx4tb8haYeviqBz6rkCy12mUSDQX9RdoZf, prefix BV1, then swap the characters at positions 3 and 9, and 4 and 7 (counting from 0). Decoding runs the same steps backwards and masks with 2^51 - 1.

Worked example for av170001: 2^51 OR 170001 is 2251799813855249; XOR 23442827791579 gives 2275242641642698; in base 58 that is 7141xw7KC, so BV17141xw7KC; after the two swaps, BV17x411w7KC. We ran the same code on 20 videos from the Bilibili popular board, aids of 15 digits included, and every pair matched.

Which one to store

Key your tables on the BV id. It is what users paste, what share links carry, and what Bilibili video detail and Bilibili video comments accept as id. Keep the aid in a BIGINT column next to it when you need to join older data. Never treat BV ids as case-insensitive: BV17x411w7KC and bv17X411W7kc are different strings.

What you have What to do Cost
An AV number Convert to BV locally, then look it up $0.002
A BV id, want the aid Convert locally free
Search results id is the BV id, ext.aid the aid $0.002 a page
1,000 old aids to refresh Convert, then 1,000 lookups $2.00

Example

XOR, MASK, TOP, BASE = 23442827791579, (1 << 51) - 1, 1 << 51, 58
ABC = "FcwAPNKTMug3GV5Lj7EJnHpWsx4tb8haYeviqBz6rkCy12mUSDQX9RdoZf"

def av_to_bv(aid: int) -> str:
    n, out = (TOP | aid) ^ XOR, []
    while n:
        n, r = divmod(n, BASE)
        out.append(ABC[r])
    s = list("BV1" + "".join(reversed(out)))
    s[3], s[9], s[4], s[7] = s[9], s[3], s[7], s[4]
    return "".join(s)

def bv_to_av(bvid: str) -> int:
    s = list(bvid)
    s[3], s[9], s[4], s[7] = s[9], s[3], s[7], s[4]
    n = 0
    for ch in s[3:]:
        n = n * BASE + ABC.index(ch)
    return (n & MASK) ^ XOR

assert av_to_bv(170001) == "BV17x411w7KC" and bv_to_av("BV17x411w7KC") == 170001

To check one against Bilibili itself, ask video detail for the aid it holds:

curl -G "https://api.okdata.online/v1/bilibili/videos/get" \
  -H "Authorization: Bearer $OKDATA_API_KEY" \
  --data-urlencode 'id=BV17x411w7KC' \
  --data-urlencode 'view=full' \
  --data-urlencode 'fields=id,title,ext.aid,ext.cid'

Limits

  • The endpoint takes a BV id or a bilibili.com/video/BV... link. An av link is refused as invalid_params, which is not charged; convert it first.
  • The algorithm is Bilibili's, not a standard. If Bilibili changes it again, ids minted after the change may not decode, so keep the BV id the platform gave you rather than only the aid.
  • bilibili-API-collect, long the usual reference for this algorithm, was taken down in January 2026 after a lawyer's letter from Bilibili. Small libraries such as abv still publish the code.

For the stats behind a BV id, see getting views, coins and danmaku for a BV id.

Sources

  1. 哔哩哔哩 (Chinese Wikipedia): BV ids replaced AV numbers on 23 March 2020zh.wikipedia.org · read
  2. Colerar/abv: AV and BV convert functions for Bilibili videosgithub.com · read
  3. yt-dlp Bilibili extractor: video URLs with an av or BV prefixgithub.com · read
  4. bilibili-API-collect: repository closed in January 2026github.com · read

Where people asked this (read 2026-11-12)

Updated

Connect once, then just ask.

Every new key comes with $0.10 to try it. One sentence connects your agent.

Start free
Connect your AI

Paste this into your agent

Read https://okdata.online/agents.md and set up okdata for me; my key is in the OKDATA_API_KEY environment variable.

Claude Code, Cursor, Codex and other agents that can open a link set themselves up from it.

MCP serverhttps://api.okdata.online/mcp