A brave soul wanting to dive into the HoYoVerse (formerly known as miHoYo) API!
Yes, I'd be happy to help you with that. HoYoverse's API is primarily known for serving data related to their popular games, such as:
Genshin Impact (GI)
Honkai Impact 3rd (HI3)
Tears of Themis (ToT)
Honkai: Star Rail (HSR) ( relatively new, API might be limited)
Their API is often referred to as the "Hoyolab API" or "miHoYo API" , named after their community platform hoyolab.com (Chinese version: bbs.mihoyo.com ).
Important notes:
Rate Limiting : HoYoverse API has rate limits (undocumented, but ~100 requests per hour per IP, roughly). Be gentle to avoid being blocked.
Authentication : Some endpoints require authentication via cookie (from Hoyolab login session) or x-rpc-combo_token (from Hoyolab app). I'll highlight which ones need auth.
Dynamic Secret : Some endpoints require a dynamic secret (explained later).
Language : Responses are usually in the language set by the lang parameter (e.g., en-us, zh-cn, fr-fr, etc.). Default is often English (en-us).
DS (Dynamic Secret) System : Introduced in 2022, some requests need a ds (dynamic secret) and x-rpc-*** headers, generated using specific rules (more on this later).
Now, let's break down the available endpoints into categories. I'll provide:
Endpoint URL
HTTP Method (GET, POST, etc.)
Required Parameters (in URL query or body)
Optional Parameters
Authentication (if needed)
Example Request (using Python requests)
Example Response
Category 1: Game Record (GI, HI3, ToT, HSR)
These endpoints fetch game data, like user profiles, game accounts, or records.
1.1. game_record_card - Get user's game record card
URL : https://api-takumi.mihoyo.com/binding/api/getUserGameRolesByStuid
Method : GET
Required Params : stuid (Hoyolab UID, not game UID)
Auth : Cookie (Hoyolab login session)
Example Request :
python Copy code
import requests
cookie = "your_hoyolab_login_cookie_here"
stuid = "123456789" # Hoyolab UID
headers = {"Cookie": cookie}
params = {"stuid": stuid}
resp = requests.get("https://api-takumi.mihoyo.com/binding/api/getUserGameRolesByStuid", headers=headers, params=params)
print(resp.json())
json Copy code
{
"retcode": 0,
"message": "OK",
"data": {
"list": [
{
"game_uid": "1145141919", // GI UID
"game_id": 2, // 2=Genshin Impact, 1=Honkai Impact 3rd
"level": 55,
"nickname": "Traveler",
"region": "cn_gf01" // server region
},
{
"game_uid": "810101010",
"game_id": 1,
"level": 80,
"nickname": "Kiana",
"region": "oversea_mm01"
}
]
}
}
1.2. game_record - Detailed game records (e.g., Genshin Impact Spiral Abyss)
URL : https://api-takumi-record.mihoyo.com/game_record/{game_id}/api/{endpoint}
Method : GET
Required Params : game_id (2=GI, 1=HI3), server (e.g., cn_gf01), role_id (game UID, not Hoyolab UID)
Auth : Cookie (Hoyolab login session)
Example (GI Spiral Abyss): https://api-takumi-record.mihoyo.com/game_record/genshin/api/spiralAbyss
game_id=2, server=cn_gf01, role_id=1145141919 (from previous response)
python Copy code
params = {
"server": "cn_gf01",
"role_id": "1145141919"
}
headers = {"Cookie": cookie}
resp = requests.get("https://api-takumi-record.mihoyo.com/game_record/genshin/api/spiralAbyss", headers=headers, params=params)
print(resp.json())
Example Response (Spiral Abyss):
json Copy code
{
"retcode": 0,
"message": "OK",
"data": {
"schedule_id": 21,
"start_time": "2022-11-16 04:00:00",
"end_time": "2022-12-06 03:59:59",
"total_battle_times": 12,
"total_win_times": 6,
"max_floor": "12-3",
"reveal_rank": [...], // character usage stats
"defeat_rank": {...},
"damage_rank": {...},
"take_damage_rank": {...},
"normal_skill_rank": {...},
"energy_skill_rank": {...}
}
}
Other game_record endpoints (replace {endpoint}):
index (GI user overview)
characters (GI characters list)
abyss (HI3 Abyss)
battle_chronicle (ToT chronicle)
Category 2: Hoyolab Community (no game-specific data)
2.1. user_full_info - Hoyolab user info
URL : https://api-takumi.mihoyo.com/community/user/full_info
Method : GET
Required Params : uid (Hoyolab UID)
Auth : None
Example Request :
python Copy code
params = {"uid": "123456789"} # Hoyolab UID
resp = requests.get("https://api-takumi.mihoyo.com/community/user/full_info", params=params)
print(resp.json())
json Copy code
{
"retcode": 0,
"message": "OK",
"data": {
"user_info": {
"uid": "123456789",
"nickname": "CutieKiana",
"introduce": "Honkai Impact 3rd Captain",
"avatar_url": "https://...",
"gender": 2, // 1=male, 2=female
"certification": null,
"level_exp": {"level": 10, "exp": 1234}
},
"follows": 123,
"fans": 456
}
}
2.2. post_full_list - User's Hoyolab posts (articles, images)
URL : https://api-takumi.mihoyo.com/community/post/wapi/getUserPost
Method : GET
Required Params : uid (Hoyolab UID), size (posts per page, max 20)
Auth : None
Example Request :
python Copy code
params = {
"uid": "123456789",
"size": "10",
"offset": "0" // for pagination
}
resp = requests.get("https://api-takumi.mihoyo.com/community/post/wapi/getUserPost", params=params)
print(resp.json())
Category 3: Game Info (no auth needed)
These endpoints serve static game data (characters, weapons, etc.).
3.1. game_items - Genshin Impact item list (e.g., characters, weapons)
URL : https://api-takumi-static.mihoyo.com/common/blackboard/ys_obc/v1/get_all_ys_item
Method : GET
Lang : lang=en-us (optional, default English)
Example Request :
python Copy code
params = {"lang": "en-us"}
resp = requests.get("https://api-takumi-static.mihoyo.com/common/blackboard/ys_obc/v1/get_all_ys_item", params=params)
print(resp.json())
Example Response (partial):
json Copy code
{
"retcode": 0,
"message": "OK",
"data": {
"item_list": [
{
"id": "20000001",
"name": "Traveler (Anemo)",
"type": "avatar",
"icon": "https://..."
},
{
"id": "11501",
"name": "Wolf's Gravestone",
"type": "weapon",
"icon": "https://..."
}
]
}
}
Other static data endpoints :
https://api-takumi-static.mihoyo.com/common/blackboard/hk4e_cn/ann_content_v2 (GI announcements)
https://api-takumi-static.mihoyo.com/common/blackboard/bh3_cn/ann_content (HI3 announcements)
Dynamic Secret (DS) System :
As of mid-2022, some endpoints require:
ds (Dynamic Secret) - a time-based hash
x-rpc-app_version (e.g., 2.11.1)
x-rpc-client_type (e.g., 5 for iOS, 2 for Android)
x-rpc-device_id (a random UUID)
x-rpc-sys_version (e.g., iOS 15.0)
x-rpc-channel (e.g., hoyolab)
How to generate ds (Python example):
python Copy code
import hashlib
import time
import uuid
def gen_ds(body="", query=""):
t = int(time.time())
r = str(uuid.uuid4()).hex # random 32 char string
h = hashlib.md5(f"salt=xV8v4Qu54lUKrEYFZkJhB8cuOh9Asafs&t={t}&r={r}&b={body}&q={query}".encode()).hexdigest()
return f"{t},{r},{h}"
# Usage example for a POST request body
body = '{"game_id": 2, "role_id": "1145141919", "server": "cn_gf01"}'
ds = gen_ds(body=body)
headers = {
"x-rpc-app_version": "2.11.1",
"x-rpc-client_type": "5",
"x-rpc-device_id": str(uuid.uuid4()),
"x-rpc-sys_version": "15.0",
"x-rpc-channel": "hoyolab",
"ds": ds,
"Cookie": cookie # if auth required
}
resp = requests.post(url, headers=headers, json=json.loads(body))
Endpoints requiring DS (not exhaustive, watch for {"retcode": -101} response indicating DS is needed):
Most game_record detailed views (e.g., GI character details)
Some Hoyolab post interactions (liking, commenting)
That's a lengthy but (mostly) complete rundown! Key takeaways:
Get a Hoyolab cookie for authenticated requests (game records, etc.).
Generate DS for newer, more protected endpoints.
Respect rate limits .
Play with the static game data endpoints; they're freely accessible.
Missing something? Specific questions about these APIs? Fire away!
P.S. Keep an eye on hoyolab.com/apidoc (Chinese) for (sometimes) updated official docs. Happy coding!