Client
The Client is the main class of genshin-kit.js that provides access to all Genshin Impact API routes. It handles authentication, caching, cookie management, and provides a unified interface for interacting with the HoYoLab API.
Quick Start
import { Client } from "genshin-kit.js";
const client = new Client();
client.login("YOUR_LTUID", "YOUR_LTOKEN");
// Now you can access all routes
const userData = await client.genshinUser.fetch("123456789");
const spiralAbyss = await client.sprialAbyss.fetch("123456789");
You only need to login once. After logging in, you don’t need to pass the ltoken and ltuid for each request.
Constructor Options(Optional)
Create a new client with customizable options:
import { Client, Language } from "genshin-kit.js";
const client = new Client({
language: Language.EnglishUS, // Set the language for API responses
debug: false, // Enable debug logging
cacheOptions: {
maxAge: 60, // Cache expiration time in seconds
maxSize: 100, // Maximum number of cached items
},
cookieManager: new ClientCookieManager(), // Custom cookie manager
});
Cache Sweeper(Optional)
The cache automatically removes expired entries. You can also manually control cache behavior:
// Disable caching completely
const client = new Client({
cacheOptions: {
maxSize: 0, // No caching
},
});
// Custom cache duration for different data types
const client = new Client({
cacheOptions: {
maxAge: 60, // Default 1 minute
},
});
The cache sweeper runs automatically to remove expired entries. Each route has its own cache instance.
More information about caching can be found here.
Cookie Management(Optional)
The client supports multiple authentication methods and cookie management strategies.
Multiple Cookies
Add multiple accounts to rotate between them:
const client = new Client();
// Add multiple cookie pairs
client.addCookies([
{ ltuid: "LTUID_1", ltoken: "LTOKEN_1" },
{ ltuid: "LTUID_2", ltoken: "LTOKEN_2" },
{ ltuid: "LTUID_3", ltoken: "LTOKEN_3" },
]);
More information about cookie can be found here.