A full nHentai API implementation for .NET
A User-Agent is required to use this API. The client will throw an error if none is provided. You can get your User-Agent by:
- Going to https://www.whatismybrowser.com/detect/what-is-my-user-agent/
- Or by opening Developer Tools (F12) in your browser, going to Network tab, and looking at the "User-Agent" header in any request
Example:
var client = new NHentaiClient("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36");
If nHentai implements CSRF protection, you can get the token by:
- Opening Developer Tools (F12)
- Going to Network tab
- Looking for a request header named 'x-csrf-token' or a cookie named 'csrf_token'
- Pass it to the client using the cookies dictionary
Important: The CSRF token must be obtained from the same IP address and User-Agent that will be used with the API. Using a token from a different IP or User-Agent will result in authentication failures.
var cookies = new Dictionary<string, string>
{
{"csrf_token", "your-token-here"}
};
var client = new NHentaiClient("your-user-agent", cookies);
- Browse homepage content
- Search by keywords
- Search by tags with optional popularity sorting
- Filter tags using
-
prefix (exclusion)
- Fetch book details
- Get related books
- Page images (preview, thumbnail, and original quality)
- Cover images (preview and thumbnail)
// Initialize client with User-Agent
var client = new NHentaiClient("your-user-agent-string");
// Search with filters
var result = await client.GetSearchPageListAsync("school swimsuit full color -loli", 2);
// Browse homepage
var homeResults = await client.GetHomePageListAsync(1);
var client = new NHentaiClient("your-user-agent-string");
// Get book by ID
var book = await client.GetBookAsync(123);
// Get related books
var related = await client.GetBookRecommendAsync(123);
var book = await client.GetBookAsync(123);
// Get full page image
byte[] picture = await client.GetPictureAsync(book, 1);
// Get cover image
byte[] cover = await client.GetBigCoverPictureAsync(book);
// Get thumbnails
byte[] thumbnail = await client.GetThumbPictureAsync(book, 1);
byte[] coverThumb = await client.GetBookThumbPictureAsync(book);
- Mewdeko - Discord Bot
- MartineApi - Image API Wrapper
- NekosBestApi - Anime Image API
This project is licensed under the MIT License - see the LICENSE file for details.